引言

之前做object detection用到的都是two stage,one stage如YOLO、SSD很少接触,这里开一篇blog简单回顾该系列的发展。很抱歉,我本人只能是蜻蜓点水,很多细节也没有弄清楚。有需求的朋友请深入论文和代码,我在末尾也列出了很多优秀的参考文章。

YOLOv1

You Only Look Once: Unified, Real-Time Object Detection

核心思想

  • 用一个CNN实现end-to-end,将目标检测作为回归问题解决。

helcon目标检测 onestage目标检测_helcon目标检测

将输入图片分割为\(S\times S\)网格,如果物体的中心落入网格中央,这个网格将负责检测这个物体。因此网络学会了去预测中心落在该网格中的物体。

每个网格预测\(B\)个bounding boxesconfidence scores。confidence scores包含两方面:

  1. 这个boundingbox包含物体的可能性\(Pr(Object)\):bb包含物体时\(Pr(Object)=1\)否则为0。
  2. 这个boundingbox的准确度\(IOU^{truth}_{pred}\):pred和gt的IoU。

因此,confidence scores可定义为$Pr(Object)*IoU^{truth}_{pred} $

每个bbox包含5个predictions:\(x,y,w,h和confidence\):\((x,y)\)表示bbox中心坐标,\(h,w\)表示bbox长宽,\(confidence\)表示pred和gt box的IoU。

每个网格预测\(C\)个类别概率\(Pr(Class_i|Object)\),表示该网格负责预测的边界框目标属于各类的概率。我们不考虑box的数量即\(B\)。

测试阶段我们将类别概率和confidence score相乘,得每个box的类特定confidence score:

\[Pr(Class_i|Object)*Pr(Object)*IoU^{truth}_{pred}=Pr(Class_i)*IoU^{truth}_{pred} \]

表示box中类别出现的概率和预测box与目标的拟合程度。

helcon目标检测 onestage目标检测_helcon目标检测_02

将图片分解为$S\times S \(个gird,每个grid预测\)B\(个bbox,confidence和\)C\(个类概率,预测值为\)S\times S \times (B*5+C)$

网络架构

helcon目标检测 onestage目标检测_helcon目标检测_03

网络结构参考GooLeNet,包含24个卷积层和2个激活层,卷积层使用1x1卷积降维然后跟3x3卷积。对于卷积层和全连接层,采用Leaky ReLU:\(max(x,0.1x)\),最后一层采用线性激活层。

网络输出维度为30(\(B=2\)),前20个元素是类别概率值,然后2个是边界框置信度,最后8个是bbox的\((x,y,w,h)\)。

  • Loss:YOLO把分类问题转化为回归问题

helcon目标检测 onestage目标检测_卷积_04

第一项是bbox中心坐标误差项;第二项是bbox高与宽误差项;

第三项是包含目标bbox置信度误差项;第四项是不包含目标bbox置信度误差项;

最后一项是包含目标的grid分类误差项。

将Loss对应到predtion张量上:

helcon目标检测 onestage目标检测_目标检测_05

实验结果

helcon目标检测 onestage目标检测_目标检测_06

SSD

SSD:Single Shot MultiBox Detector

核心思想

速度比YOLO快,精度可以跟Faster RCNN媲美。

  1. 采用多尺度特征图用于检测:大特征图检测小目标,小特征图检测大目标。
  2. 采用卷积进行检测:与YOLO最后采用全连接层不同,SSD直接采用卷积提取检测结果。
  3. 设置先验框:借鉴Faster RCNN中anchor理念,为每个网格设置不同长宽比的anchor,bbox以anchor为基准。

网络架构

在VGG16基础上增加了卷积层获得更多特征图用于检测。

上是SSD,下是YOLO

helcon目标检测 onestage目标检测_目标检测_07

实验结果

helcon目标检测 onestage目标检测_ide_08

YOLOv2

YOLO9000: Better, Faster, Stronger

核心思想

YOLOv1虽然检测速度快,但检测精度不如RCNN,YOLOv1定位不够准确,召回率也低。于是YOLOv2提出了几种改进策略来提升YOLO模型的定位准确度和召回率,并保持检测速度。

helcon目标检测 onestage目标检测_卷积_09

  • Better
  • Batch Normalization:加快收敛并起到正则化效果,防止过拟合。
  • High Resolution Classifier:在ImageNet数据上使用\(448\times448\)输入来finetune。
  • Convolutional With Anchor Boxes:借鉴Faster R-CNN中RPN的anchor boxes策略,预测offset而不是coordinate。
  • Dimension Clusters:采用k-means来替代人工选取anchor。并使用下式来度量距离。
    \[d(box,centroid)=1-IOU(box, centroid) \]
  • Direct location prediction:改变了预测bbox的计算公式
  • Fine-Grained Features:小物体需要更精细的特征图。采用passthrough层将高分辨率特征concat低分辨率特征,类似于ResNet。
  • Multi-Scale Training:每隔10batch,网络随机选择新的图像尺寸。
  • Faster
  • Darknet-19
  • Training for classification
  • Training for detection
  • Stronger
  • Hierarchical classification
  • Dataset combination with WordTree
  • Joint classification and detection

网络架构

helcon目标检测 onestage目标检测_卷积_10

实验结果

helcon目标检测 onestage目标检测_helcon目标检测_11

YOLOv3

YOLOv3: An Incremental Improvement

核心思想

  • Bounding Box Prediction:和v2一样使用聚类来获得anchor并预测bbox坐标。
  • Class Prediction:不使用softmax,使用二元交叉熵进行类别预测。
  • Predictions Across Scales:跨尺度预测,类似FPN使用3个尺度,预测为\(N\times N\times[3*(4+1+80)]\),4个box offsets、1个obj prediction和80个类prediction。
  • Feature Extractor:Darknet-53,加入了Residual。

网络架构

helcon目标检测 onestage目标检测_helcon目标检测_12

helcon目标检测 onestage目标检测_卷积_13

实验结果

helcon目标检测 onestage目标检测_目标检测_14

helcon目标检测 onestage目标检测_卷积_15

参考

  • paper

[1]Redmon J, Divvala S, Girshick R, et al. You only look once: Unified, real-time object detection[C]//Proceedings of the IEEE conference on computer vision and pattern recognition. 2016: 779-788.

[2]Liu W, Anguelov D, Erhan D, et al. Ssd: Single shot multibox detector[C]//European conference on computer vision. Springer, Cham, 2016: 21-37.

[3]Redmon J, Farhadi A. YOLO9000: better, faster, stronger[C]//Proceedings of the IEEE conference on computer vision and pattern recognition. 2017: 7263-7271.

[4]Redmon J, Farhadi A. Yolov3: An incremental improvement[J]. arXiv preprint arXiv:1804.02767, 2018.