SSD: The Single Shot Detector

  • YOLO: You Only Look Once 还要快,还要精确。保证速度的同时,其结果的 mAP 可与使用 region proposals 技术的方法(如 Faster R-CNN)相媲美。
  • 为了得到高精度的检测结果,在不同层次的 feature maps 上去 predict objectbox offsets,同时,还得到不同 aspect ratio predictions
  • 能够在当输入分辨率较低的图像时,保证检测的精度。同时,这个整体 end-to-end 的设计,训练也变得简单。在检测速度、检测精度之间取得较好的 trade-off

 

SSD: The Single Shot Detector

基本网络-VGG-16

Layer name

"图像"规格

input

3x300x300

conv1_1 (3*3 s1 p1)

64x300x300

conv1_2(3*3 s1 p1)

64x300x300

pool_1 (3*3 s1 p1)

64x150x150

conv2_1 (3*3 s1 p1)

128x150x150

conv2_2(3*3 s1 p1)

128x150x150

pool_2(3*3 s1 p1)

128x75x75

conv3_1(3*3 s1 p1)

256x75x75

conv3_2(3*3 s1 p1)

256x75x75

conv3_3(3*3 s1 p1)

256x75x75

pool_3(3*3 s1 p1)

256x38x38

conv4_1(3*3 s1 p1)

512x38x38

conv4_2(3*3 s1 p1)

512x38x38

conv4_3(3*3 s1 p1)

512x38x38

pool_4(3*3 s1 p1)

512x19x19

conv5_1(3*3 s1 p1)

512x19x19

conv5_2(3*3 s1 p1)

512x19x19

conv5_3(3*3 s1 p1)

512x19x19

-----------

VGG昏割线

fc6(convolution kernel dilation) (3*3, p6, s1, dilation=6)

1024x19x19

fc7 (1*1 s1 p0)

1024x19x19

conv8_1 (1*1 s1 p0)

256x19x19

conv8_2 (3*3 s2 p1)

512x10x10

conv9_1 (1*1 s1 p0)

128x10x10

conv9_2 (3*3 s2 p1)

256x5x5

conv10_1 (1*1 s1 p0)

128x5x5

conv10_2 (3*3 s2 p1)

256x3x3

conv11_1 (1*1 s1 p0)

128x3x3

conv11_2 (3*3 s2 p1)

256x1x1

   

YOLO在卷积层后接全连接层,即检测时只利用了最高层feature maps(包括Faster RCNN也是如此)

SSD采用了特征金字塔结构进行检测,即检测时利用了conv4-3conv-7FC7),conv8-2conv9-2conv10_2conv11_2这些大小不同的feature maps,在多个feature maps上同时进行softmax分类和位置回归

SSD: The Single Shot Detector

Prior Box 

anchor非常类似,就是一些目标的预选框,后续通过softmax分类+bounding box regression获得真实目标的位置。SSD按照如下规则生成prior box

  • feature map上每个点的中点为中心(offset=0.5),生成一些列同心的prior box(然后中心点的坐标会乘以step,相当于从feature map位置映射回原图位置).
  • 正方形prior box

    最小边长为min_size

    最大边长为sqrt(max_size * min_size).

     

    每在prototxt设置一个aspect ratio会生成2个长方形:

    min_size*sqrt(aspect ratio)

    min_size/sqrt(aspect ratio)

SSD: The Single Shot Detector

 

每个feature map对应prior boxmin_sizemax_size由以下公式决定,公式中m是使用feature map的数量(SSD 300m=6):

SSD: The Single Shot Detector

第一层feature map对应的min_size=S1max_size=S2;第二层min_size=S2max_size=S3;其他类推。在原文中,Smin=0.2Smax=0.9,但是在SSD 300prior box设置并不能和paper中上述公式对应

 

min_size

max_size

conv4_3

30

60

fc7

60

111

conv6_2

111

162

conv7_2

162

213

conv8_2

213

264

conv9_2 

264

315

不过依然可以看出,SSD使用低层feature map检测小目标,使用高层feature map检测大目标

 

分类和回归网络:

SSD: The Single Shot Detector

 

conv4_3 feature map网络pipeline分为了3条线路:

  1. 经过一次batch norm+一次卷积后,生成了[1, num_class*num_priorbox, layer_height, layer_width]大小的feature用于softmax分类目标和非目标(其中num_class是目标类别,SSD 300num_class = 21)
  2. 经过一次batch norm+一次卷积后,生成了[1, 4*num_priorbox, layer_height, layer_width]大小的feature用于bounding box regression(即每个点一组[dxmindymindxmaxdymax],参考Faster RCNN 2.5节)
  3. 生成了[1, 2, 4*num_priorbox]大小的prior box blob其中2channel分别存储prior box的4个点坐标和对应的4个variance

 prior box的生成基准是在原图上,即min_sizemax_size都是相对于原图的。

3步的第1个输出为prior box4个点坐标,一般归一化到[0,1],具体操作为原图上生成的xmin,xmax,ymin,ymax分别除以原图的长宽

 

图像规格

备注

conv4_3

N, 512, 38, 38

 

conv4_3_norm

N, 512, 38, 38

Scale=20,cross_channel=false

conv4_3_norm_mbox_loc

N, 16, 38, 38

3*3 s1 p1

conv4_3_norm_mbox_loc_perm

N, 38, 38, 16

NCHW->NHWC

conv4_3_norm_mbox_loc_flat

N, 38*38*16

4boxid*4个坐标

 

图像规格

备注

conv4_3

N, 512, 38, 38

 

conv4_3_norm

N, 512, 38, 38

Scale=20,cross_channel=false

conv4_3_norm_mbox_conf

N, 84, 38, 38

3*3 s1 p1

conv4_3_norm_mbox_conf_perm

N, 38, 38, 84

NCHW->NHWC

conv4_3_norm_mbox_conf_flat

N, 38*38*84

4boxid*21类(含背景)

 

图像规格

备注

conv4_3

N, 512, 38, 38

 

conv4_3_norm

N, 512, 38, 38

Scale=20,cross_channel=false

conv4_3_norm_mbox_priorbox

 

Min_size=30, max_size=60, aspect_rato=2

 SSD网络结构优劣分析

SSD算法的优点应该很明显:运行速度可以和YOLO媲美,检测精度可以和Faster RCNN媲美。

缺点:

1.需要人工设置prior boxmin_sizemax_sizeaspect_ratio。网络中prior box的基础大小和形状不能直接通过学习获得,而是需要手工设置。而网络中每一层feature使用的prior box大小和形状恰好都不一样,导致调试过程非常依赖经验。
2.虽然采用了pyramdial feature hierarchy的思路,但是对小目标的recall依然一般,并没有达到碾压Faster RCNN的级别。作者认为,这是由于SSD使用conv4_3低级feature去检测小目标,而低级特征卷积层数少,存在特征提取不充分的问题。
 

SSD训练过程

SSD: The Single Shot Detector

对于SSD,虽然paper中指出采用了所谓的“multibox loss”,但是依然可以清晰看到SSD loss分为了confidence losslocation loss两部分,其中NmatchGTGround Truth)的prior box数量;而α参数用于调整confidence losslocation loss之间的比例,默认α=1SSD中的confidence loss是典型的softmax loss

SSD: The Single Shot Detector

SSD: The Single Shot Detector

xijp代表第iprior box匹配到了第jclassp类别的GT box

 
location loss是典型的smooth L1 loss
SSD: The Single Shot Detector
SSD: The Single Shot Detector
SSD: The Single Shot Detector

Hard negative mining

值得注意的是,一般情况下negative default boxes数量>>positive default boxes数量,直接训练会导致网络过于重视负样本,从而loss不稳定。所以需要采取:

所以SSD在训练时会依据confidience score排序default box,挑选其中confidience高的box进行训练,控制positivenegative=13
 

Data augmentation

数据增广,即每一张训练图像,随机的进行如下几种选择:

使用原始的图像
采样一个 patch,与物体之间最小的 jaccard overlapiou 为:0.10.30.50.7 0.9
随机的采样一个 patch

采样的 patch 是原始图像大小比例是[0.11]aspect ratio1/22之间。当 groundtruth box 的 中心(center)在采样的patch中时,保留重叠部分。在这些采样步骤之后,每一个采样的patchresize到固定的大小,并且以0.5的概率随机的 水平翻转(horizontally flipped)。

翻来覆去的randomly crop,保证每一个prior box都获得充分训练而已。

 

Result

SSD: The Single Shot Detector

SSD: The Single Shot Detector

 
 
 
原文献链接:
 
参考: