2021-08-20 论文:目标检测

one-stage

1、RetinaNet 1708.

Kaiming He, Focal Loss for Dense Object Detection.

1)focal loss

2021-08-20 论文:目标检测_第1张图片
为解决1-stage训练时正负例不平衡现象,对CE损失函数添加权重因子:
balanced cross entropy:从样本分布角度添加
focal loss:从样本分类难易程度出发添加(使loss聚焦于难分样本)

2021-08-20 论文:目标检测_第2张图片

two-stage

1、Faster R-CNN 1506.

Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks.
1506.01497
[paper]

  • r p n _ l o s s rpn\_loss rpn_loss

2021-08-20 论文:目标检测_第3张图片
其中,
    i i i:某个minibatch中,第 i i i个anchor
    p i p_i pi:二分类的预测值                 p i ∗ p_i^* pi:gt { 1 I o U ( g t , a n c h o r ) > 0.7 0 I o U ( g t , a n c h o r ) < 0.3 \begin{cases}1 &IoU(gt,anchor)>0.7 \\ 0 &IoU(gt,anchor)<0.3\end{cases} {10IoU(gt,anchor)>0.7IoU(gt,anchor)<0.3
    t i t_i ti:回归位置的预测值                 t i ∗ t_i^* ti:gt,计算如下:

2021-08-20 论文:目标检测_第4张图片

  • RPN 架构:

[zhihu]

2021-08-20 论文:目标检测_第5张图片
AnchorTargetCreator:生成正负anchor,计算 r p n _ l o s s rpn\_loss rpn_loss.
ProposalCreator:生成RoIs(region of interests)作为训练样本传给RoIHead.

  1. 选取得分大前12000个anchor,用回归参数修正位置,得到RoIs.
  2. 再利用NMS,得到2000个RoIs.
    (输出形如2000×4的tensor,这部分不进行反向传播)
  • RoIHead:

2021-08-20 论文:目标检测_第6张图片RoI Pooling:将不同尺寸的特征图区域(128sample_rois)pooling成固定的尺寸 7 ∗ 7 7*7 77.
FC 21:用来分类,预测RoIs属于哪个类别(20个类 + + + 背景)
FC 84:用来回归(21个类 × × × 4个位置参数)

  • r o i _ l o s s roi\_loss roi_loss
  1. Train:
    ProposalTargetCreator :选择128个正、负sample_rois用以训练.计算roi_loss.
  2. Test:
    所有rois算概率,用回归参数调整,然后再NMS.
    (实验发现,RPN生成RoI越多,mAP越高)

Problem:在Test阶段,NMS是按类别分别进行NMS吗?
(是的)

  1. RPN时,已对anchor做了一遍NMSRoIHead_Test时,再做一遍
    RPN时,已对anchor位置做了回归调整;RoIHead_Test时,再做一遍
  • L o s s Loss Loss

L o s s = L o s s r p n ( c l s 2 , r e g ) + L o s s r o i ( c l s 21 , r e g ) Loss=Loss_{rpn}(cls_2,reg)+Loss_{roi}(cls_{21},reg) Loss=Lossrpn(cls2,reg)+Lossroi(cls21,reg)





  • NMS 算法实现

输入:(boxes,nms_threshold) >> boxes
目的:去掉 模型检测出的 多余框

步骤:
(1)将boxes按得分降序;
(2.1)若boxes非空,取首项为best,并记录best;否则结束
(2.2)计算best与剩余boxes的IOUs,找出IOUs中所有小于阈值的索引为inds;
(2.3)boxes = boxes[inds+1],重复(2.1);

import numpy as np

def nms(dets, thresh):
    """Pure Python NMS baseline."""
    x1 = dets[:, 0]
    y1 = dets[:, 1]
    x2 = dets[:, 2]
    y2 = dets[:, 3]
    scores = dets[:, 4]
    areas = (x2 - x1 + 1) * (y2 - y1 + 1)
    order = scores.argsort()[::-1] # 得分降序,取最高
    
    keep = []
    while order.size > 0:
        i = order[0]
        keep.append(i)
        xx1 = np.maximum(x1[i], x1[order[1:]]) #并集Union
        yy1 = np.maximum(y1[i], y1[order[1:]])
        xx2 = np.minimum(x2[i], x2[order[1:]])
        yy2 = np.minimum(y2[i], y2[order[1:]])
        w = np.maximum(0.0, xx2 - xx1 + 1)
        h = np.maximum(0.0, yy2 - yy1 + 1)
        inter = w * h
        ovr = inter / (areas[i] + areas[order[1:]] - inter) #IOU
        inds = np.where(ovr <= thresh)[0] # 只保留iou低的索引列表!!!若空则order空
        order = order[inds + 1]
    return keep

######
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.61],
        [220,230,315,340,0.9]])
nms(boxes,0.5)

loss

1)SmoothL1Loss

在这里插入图片描述
L2Loss和L1Loss的结合

  1. 当预测值和 gt 差别较小时(绝对值差小于1),梯度不至于太大(比L1 Loss更圆滑)。
  2. 当差别大时,梯度值小(较稳定,不易梯度爆炸)。

2021-08-20 论文:目标检测_第7张图片

你可能感兴趣的:(论文,深度学习)