其他分享
首页 > 其他分享> > 目标检测 Two Stage Detection(RCNN 系列)

目标检测 Two Stage Detection(RCNN 系列)

作者:互联网

在这里插入图片描述

目标检测 Two Stage Detection(RCNN 系列)

RCNN

总流程梳理:

NMS:

import numpy as np
import matplotlib.pyplot as plt
# 自己定义的二维数组
boxes = np.array([[100, 100, 210, 210, 0.72],
                  [250, 250, 420, 420, 0.8],
                  [220, 220, 320, 330, 0.92],
                  [100, 100, 210, 210, 0.72],
                  [230, 240, 325, 330, 0.81],
                  [220, 230, 315, 340, 0.9]])
def my_nms(arr,thresh=0.6):
    x1 = arr[:,0]
    y1 = arr[:,1]
    x2 = arr[:,2]
    y2 = arr[:,3]
    score = arr[:,4]
    # 计算各个框框的面积
    area = (x2-x1+1)*(y2-y1+1)
    # 定义一个放置最大分数的序号的列表
    score_rank_list = []
    # 按分数高低把序号列表排列出来
    score_rank = score.argsort()[::-1]
    while score_rank.size >0:
        # 把最大的分数对应序号添加到score_rank_list 中
        i = score_rank[0]
        score_rank_list.append(i)

        # 计算每一个方框和它的重复overlap area
        x11 = np.maximum(x1[i],x1[score_rank[1:]])
        x22 = np.minimum(x2[i],x2[score_rank[1:]])
        y11 = np.maximum(y1[i],y1[score_rank[1:]])
        y22 = np.minimum(y2[i],y2[score_rank[1:]])

        high = np.maximum(0,y22-y11+1)
        wide = np.maximum(0,x22-x11+1)
        overlap_area = high*wide
        # 计算重叠的面积
        ious = overlap_area/(area[i]+area[score_rank[1:]]-overlap_area)
        # 把大于thresh 的ious给去掉,然后取得生成符合条件的元组的序号
        # left_ious是一个列表,通过里面的列表的值如[2,3,4]才可以选出score_rank里面连续的值
        left_ious = np.where(ious<=thresh)[0]
        # 对score_rank进行切片,获得符合条件的序号最小值,把符合条件的score全部删除
        # +1是为了把最高的那个给排除了
        score_rank = score_rank[left_ious+1]
    # return千万不要放在循环里面
    return score_rank_list


def box_show(arr,type = 'c'):
    x1 = arr[:, 0]
    y1 = arr[:, 1]
    x2 = arr[:, 2]
    y2 = arr[:, 3]

    plt.plot([x1, x2], [y1, y1], type)
    plt.plot([x1, x1], [y1, y2], type)
    plt.plot([x1, x2], [y2, y2], type)
    plt.plot([x2, x2], [y1, y2], type)
    plt.title(" nms")


plt.figure(1)
ax1 = plt.subplot(1, 2, 1)
ax2 = plt.subplot(1, 2, 2)

plt.sca(ax1)
box_show(boxes, 'k')  # before nms

keep = my_nms(boxes, thresh=0.01)
plt.sca(ax2)
box_show(boxes[keep], 'r')  # after nm
plt.show()

Fast RCNN

总体流程:

ROI projection:

ROI Pooling:

ROI Align:

Precise ROI Pooling:

1617770830909)(目标检测 Two Stage Detection(RCNN 系列).assets/image-20210407091721261.png)]

Faster RCNN:

RPN:

1617770830910)(目标检测 Two Stage Detection(RCNN 系列).assets/image-20210407093005546.png)]

损失函数:

Smooth L1 Loss:

残差拟合:

训练过程:

标签:ROI,log,Two,rank,Detection,score,RCNN,RPN
来源: https://blog.csdn.net/Sakura_day/article/details/115482930