Faster-R-CNN
(未完成)
Faster RCNN其实可以分为4个主要内容:
- Conv layers。作为一种CNN网络目标检测方法,Faster RCNN首先使用一组基础的conv+relu+pooling层提取image的feature maps。该feature maps被共享用于后续RPN层和全连接层。
- Region Proposal Networks。RPN网络用于生成region proposals。该层通过softmax判断anchors属于foreground或者background,再利用bounding box regression修正anchors获得精确的proposals。
- Roi Pooling。该层收集输入的feature maps和proposals,综合这些信息后提取proposal feature maps,送入后续全连接层判定目标类别。
- Classification。利用proposal feature maps计算proposal的类别,同时再次bounding box regression获得检测框最终的精确位置。
上面这一部分来自:https://zhuanlan.zhihu.com/p/31426458
网络架构
图中head为Conv layers:首先预处理的图像先经过一组基础的卷积层生成feature map。
图中上面那部分为Region Proposal Networks。RPN网络用于生成region proposals。该层通过softmax判断anchors属于foreground或者background,再利用bounding box regression修正anchors获得精确的proposals。
图中蓝色的圆矩形为Roi Pooling。该层输入feature map和proposals,通过proposals从feature map提取proposal feature maps,送入后续全连接层判定目标类别。
图中右边为Classification。通过全连接层预测类别和boundary box的偏移量。
下面逐个具体讲这四个部分:
1. Conv layers
首先预处理的图像先经过一组基础的卷积层生成feature map。
2. RPN
经过rpn_net和relu层得到feature maps。在RPN中,使用3x3的卷积核滑动计算整个feature map,每次计算通过卷积层最后得到的1x1x256(ZF network的结果),然后分别通过两个全连接层得到4k coordinates和2k scores。k为anchor boxes的数量。4代表4个位置偏移量,2代表前景/背景两个类别。前景anchor是指它与GT box的IOU大于某threshold。背景anchor是指它与GT box的IOU小于某个threshold。
Anchor Generation Layer
这一层通过在每一个feature map的每个格子上生成不同尺度和纵横比的9个anchors,生成固定数量的anchors。大部分的bounding boxes不会包含前景目标,但有一些会。RPN的目的就是学会辨别这些boxes中好的box。
RPN Loss
下面来看RPN Loss是如何计算的。
Classification Loss:
cross_entropy(predicted_class, actual_class)
Bounding Box Regression Loss:
输入:
- 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为前景区域的概率。
Proposal Target Layer
这一层的目的是从proposal Layer输出的ROIs中选择有希望的ROIs。
输入:
- proposal layer生成的ROIs
- GT信息
输出:
- 被选择的符合重叠条件的前景和背景ROIs
- ROIs的特定类别的目标回归系数
系数:
- TRAIN.FG_THRESH:默认值为0.5,用来选择前景ROIs。ROI最大重叠超过FG_THRESH的被标记为前景。
- TRAIN.BG_THRESH_HI:默认值0.5。
- TRAIN.BG_THRESH_LO:默认值0.1。在BG_THRESH_HI与BG_THRESH_LO之间的别标记为背景。
- TRAIN.BATCH_SIZE:默认值128。前景/背景的最大总数量。
- TRAIN.FG_FRACTION:默认0.25。前景数量不能超过BATCH_SIZE*FG_FRACTION
3. ROI Pooling Layer
ROI Pooling Layer将Proposal Target Layer输出的大小各不相同proposal boxes转化为固定大小的proposal。
4. Classification Layer
Classification部分利用已经获得的proposal feature maps,通过full connect层与softmax计算每个proposal具体属于那个类别(如人,车,电视等),输出cls_prob概率向量;同时再次利用bounding box regression获得每个proposal的位置偏移量bbox_pred,用于回归更加精确的目标检测框。
Classification Loss
与RPN loss相似。
这里的分类误差和RPN层的分类误差不同的是,RPN层的分类误差只分两类:前景/背景。分类层预测所有的目标类和背景类。
这里分类误差是cross entropy loss计算公式如下:
因此,计算分类层损失需要以下量:
- 预测的类别标签和bounding box的回归系数(它们是分类网络的输出)
- 每个anchor box的类别标签
- 目标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/