Faster-R-CNN学习笔记

Faster-R-CNN

(未完成)

网络架构

Faster-R-CNN学习笔记

首先预处理的图像先经过一组基础的卷积层生成feature map。

Anchor Generation Layer

这一层通过在每一个feature map的每个格子上生成不同尺度和纵横比的9个anchors,生成固定数量的anchors。大部分的bounding boxes不会包含前景目标,但有一些会。RPN的目的就是学会辨别这些boxes中好的box。

Faster-R-CNN学习笔记

RPN

经过rpn_net和relu层得到feature maps。然后分为两条路。上面一条通过softmax分类anchors获得foreground和background(检测目标是foreground),下面一条用于计算对于anchors的bounding box regression偏移量,以获得精确的proposal。前景anchor是指它与GT box的IOU大于某threshold。背景anchor是指它与GT box的IOU小于某个threshold。

RPN Loss

下面来看RPN Loss是如何计算的。

RPNLoss=Classification Loss+Bounding Box Regression LossRPNLoss = Classification\ Loss + Bounding\ Box\ Regression\ Loss

Classification Loss:

cross_entropy(predicted_class, actual_class)

Bounding Box Regression Loss:

Lloc=ux,y,w,hsmoothL1(ui(predicted)ui(target))L_{loc} = \sum_{u\in x,y,w,h}smooth_{L1}(u_i(predicted)-u_i(target))

smoothL1(x)={σ2x22x<1σ2x0.5σ2otherwise(σ=3)smooth_{L1}(x) = \begin{cases}\frac{\sigma^2x^2}{2} & ||x|| < {1\over\sigma^2} \\ ||x||-{0.5\over\sigma^2} & {otherwise} \end{cases} (\sigma = 3)

输入:

  • RPN网络的输出(预测的前景/背景类别标签,回归系数)
  • anchor boxes
  • GT boxes

输出:

  • 好的前景/背景boxes和相应的分类标签
  • 目标回归系数

参数:

  • TRAIN.RPN_POSITIVE_OVERLAP:如果一个anchor box高于这个Threshold则为高的前景box,默认设为0.7
  • TRAIN.RPN_NEGATIVE_OVERLAP:如果和GT最大重叠的anchorIOU低于这个threshold则为背景。高于RPN_NEGATIVE_OVERLAP且低于RPN_POSITIVE_OVERLAP的anchor标记为忽略。默认设为0.3。
  • TRAIN.RPN_BATCHSIZE:前景/背景的anchor的总数量。默认值为256。
  • TRAIN.RPN_FG_FRACTION:前景anchors占batch size的比例。默认为0.5。如果前景anchor的数量超过了RPN_BATCHSIZExRPN_FG_FRACTION,则从中随机标记超出的数量的anchor为忽略。

到这里,bounding box的偏移量就基本计算完成。后面的proposal layer,ROI Pooling layer和classification layer关注分类误差。

Proposal Layer

Proposal Layer负责综合变换量和foreground anchors,计算出精准的proposal,送入后续的ROI Pooling Layer。通过回归系数将上一层生成的anchors调整为新的anchors,并使用NMS减少anchors的数量。并判断anchor为前景区域的概率。

ROI Pooling Layer

ROI Pooling Layer将RPN输出的大小各不相同proposal boxes转化为固定大小的proposal。

Classification Layer

Classification部分利用已经获得的proposal feature maps,通过full connect层与softmax计算每个proposal具体属于那个类别(如人,车,电视等),输出cls_prob概率向量;同时再次利用bounding box regression获得每个proposal的位置偏移量bbox_pred,用于回归更加精确的目标检测框。

Classification Loss

与RPN loss相似。

Classification Layer Loss=Classification Loss+Bounding Box Regression LossClassification\ Layer\ Loss = Classification\ Loss + Bounding\ Box\ Regression\ Loss

这里的分类误差和RPN层的分类误差不同的是,RPN层的分类误差只分两类:前景/背景。分类层预测所有的目标类和背景类。

这里分类误差是cross entropy loss计算公式如下:
Faster-R-CNN学习笔记
Faster-R-CNN学习笔记
因此,计算分类层损失需要以下量:

  1. 预测的类别标签和bounding box的回归系数(它们是分类网络的输出)
  2. 每个anchor box的类别标签
  3. 目标bounding box的回归系数

论文:https://arxiv.org/abs/1506.01497

参考:

https://zhuanlan.zhihu.com/p/31426458

http://www.telesens.co/2018/03/11/object-detection-and-classification-using-r-cnns/