Cascade 阅读笔记
Cascade R-CNN: High Quality Object Detection and Instance Segmentation(CVPR 2018)
论文链接:论文链接
代码链接:代码链接Caffe 代码链接Detectron
Abstract
- IoU常用的阈值 0.5 会导致检测噪声(低质量检测),但检测性能经常会因IoU阈值较大而降低——这被称作高质量检测悖论
- 导致上述悖论的原因有两个:
- 大的IoU阈值将会导致正样本的减少
- 推理时 检测器 和 检测假设 之间的质量不匹配(dismatch问题)
- cascade rcnn有多个stage,每一个stage的输出作为下一个stage的输入;这种重采样逐渐提高了假设质量,保证了所有检测器的正训练集大小相等,并最大限度地减少了过拟合
- cascade rcnn用于目标检测以及实例分割,并且适用于通用或特定(例如x光)任务
1. Introduction
目标检测中的问题
- 目标检测有两个任务:
- 识别问题:区分前景和背景,并且给它们分配正确的类别标签
- 定位问题:给对象分配正确的bb
- 这两个问题不能准确地解决,原因是有许多与gt框相近的false positive样本
- 正样本和负样本的定义一般用IoU,一般这个值 u = 0.5 u=0.5 u=0.5, 而许多false positive经常满足这个值( I o U ≥ 0.5 IoU \geq 0.5 IoU≥0.5)
原因剖析
- 作者把检测假设的质量 定义为 推理阶段的proposal与gt的IoU(例如Input IoU是rpn网络的proposal和gt的IoU,Output IoU是经过regressor回归后的bb与gt的IoU),把检测器的质量 定义为 用于训练它的IoU阈值u
- 下面这个图分别在IoU阈值为 u = 0.5 , 0.6 , 0.7 u=0.5,0.6,0.7 u=0.5,0.6,0.7 的条件下进行训练,得到在推理时不同IoU条件下回归器、分类器和检测器的性能。可以看出,阈值决定了分类器最具鉴别力的分类边界;
- 上述观察表明,高质量的检测需要检测器的质量与检测假设的质量密切匹配
解决方案
- 提出了cascade rcnn,是一个基于R-CNN的 multi-stage 检测器
- 将一个stage的输出作为另一个stage的输入进行训练,这利用了bb regressor的输出IoU几乎总是优于其输入IoU的观察结果(上面那个图的(a))
2. Related Work
3. High Quality Object Detection
- 这一节讨论高质量目标检测的挑战
3.1 Object Detection
3.1.1 Bounding Box Regression
- 边界框
b
=
(
b
x
,
b
y
,
b
w
,
b
h
)
\boldsymbol{b}=(b_x,b_y,b_w,b_h)
b=(bx,by,bw,bh)包含图像块
x
\boldsymbol{x}
x的四个坐标,而bb regression是使用一个regressor
f
(
x
,
b
)
f(\boldsymbol x,\boldsymbol b)
f(x,b)将一个候选的bb
b
\boldsymbol b
b 回归到一个目标bb
g
\boldsymbol g
g ,这个过程可以使用下面这个loss 来进行训练:
R l o c [ f ] = ∑ i L l o c ( f ( x i , b i ) , g i ) \mathcal{R}_{loc}[f]=\sum _iL_{loc}(f(\boldsymbol{x}_i, \boldsymbol{b}_i),\boldsymbol{g}_i) Rloc[f]=i∑Lloc(f(xi,bi),gi)
其中,
L l o c ( a , b ) = ∑ i ∈ { x , y , w , h } s m o o t h L 1 ( a i − b i ) L_{loc}(\boldsymbol a,\boldsymbol b)=\sum_{i\in\{x,y,w,h\}}smooth_{L_1}(a_i-b_i) Lloc(a,b)=i∈{x,y,w,h}∑smoothL1(ai−bi)
其中,
s m o o t h L 1 ( x ) = { 0.5 x 2 , ∣ x ∣ < 1 ∣ x ∣ − 0.5 , o t h e r w i s e smooth_{L_1}(x)=\left\{ \begin{aligned} &0.5x^2,&|x|<1\\ &|x|-0.5, &otherwise \end{aligned} \right. smoothL1(x)={0.5x2,∣x∣−0.5,∣x∣<1otherwise
为了尺度和位置不变性, s m o o t h L 1 smooth_{L_1} smoothL1作用在距离向量 Δ = ( δ x , δ y , δ w , δ h ) \Delta=(\delta_x,\delta_y,\delta_w,\delta_h) Δ=(δx,δy,δw,δh)上
δ x = ( g x − b x ) / b w , δ y = ( g y − b y ) / b h , δ w = l o g ( g w / b w ) , δ h = l o g ( g h / b h ) \delta_x=(g_x-b_x)/b_w,\delta_y=(g_y-b_y)/b_h,\delta_w=log(g_w/b_w),\delta_h=log(g_h/b_h) δx=(gx−bx)/bw,δy=(gy−by)/bh,δw=log(gw/bw),δh=log(gh/bh) - 由于边界框回归通常对
b
\boldsymbol b
b 进行较小的调整,因此
Δ
\Delta
Δ各个
δ
\delta
δ的数值可能非常小。这通常使回归损失比分类损失小得多。为了提高多任务学习的有效性,
Δ
Δ
Δ通过其均值和方差进行归一化,例如
δ
x
δ_x
δx 被替换为
δ x ′ = δ x − μ x σ x \delta'_x=\frac{\delta_x-\mu_x}{\sigma_x} δx′=σxδx−μx
3.1.2 Classification
- 当bb和gt的IoU大于某个阈值u的时候,认为该bb含有object,并将对应gt的标签分配给该bb
- 在进行inference时,rpn网络产生的大部分proposal质量都比较低,检测器需要对低质量的proposal有更强的辨别力
3.2 Challenge to High Quality Detection
- 高质量检测的难点有如下几个:
- 评估指标历来更加强调低质量检测机制,也就是u=0.5的检测器
- 检测假设和检测器的质量必须匹配
4. Cascade R-CNN
4.1 Architecture
- 如下图,这里作者简单采用了(a)图中的RPN进行proposal
4.2 Cascade Bounding Box Regression
- training阶段很容易产生高质量正样本(只需要在gt旁边进行取样即可),问题是如何在inference阶段产生高质量的proposal,这个问题可以用cascade bb regression来解决
- 如下图所示,每个u对应的检测器不可能在所有的Input IoU上有好的效果,但是从图中看出每一个u对应的检测器的输出IoU都可以提高一点点(在灰色线上面),因此考虑把多个不同的检测器进行级联,这样每一个stage的IoU都会逐渐变高
- 从下图可以看到,级联检测器回归的bb越来越接近于gt(
δ
x
,
δ
y
,
δ
w
,
δ
h
\delta_x,\delta_y,\delta_w,\delta_h
δx,δy,δw,δh分布接近(0,0))
4.3 Cascade Detection
- 级联检测的损失函数:在每个stage t,分类器
h
t
h_t
ht和回归器
f
t
f_t
ft根据IoU阈值
u
t
u^t
ut进行优化,
u
t
>
u
t
−
1
u^t>u^{t-1}
ut>ut−1,loss为
L ( x t , g ) = L c l s ( h t ( x t ) , y t ) + λ [ y t ≥ 1 ] L l o c ( f t ( x t , b t ) , g ) L(\boldsymbol x^t,g)=L_{cls}(h_t(\boldsymbol x^t), y^t)+\lambda [y^t\geq 1]L_{loc}(f_t(\boldsymbol x^t,\boldsymbol b^t), \boldsymbol g) L(xt,g)=Lcls(ht(xt),yt)+λ[yt≥1]Lloc(ft(xt,bt),g)
其中 b t = f t − 1 ( x t − 1 , b t − 1 ) \boldsymbol b^t=f_{t-1}(\boldsymbol x^{t-1}, \boldsymbol b^{t-1}) bt=ft−1(xt−1,bt−1), g \boldsymbol g g是 x t \boldsymbol x^t xt对应的gt框, y t y^t yt是 x t \boldsymbol x^t xt在 u t u^t ut下的标签 - 这种级联学习法对检测器训练由3个重要影响:
- 大IoU导致过拟合现象的概率减小了,因为在每一个stage正样本变得更多了
- 更深stage的检测器对于更高的IoU阈值来说更佳
- 随着IoU阈值的增加,一些异常值被去除,因此bb regression的学习效果在后期增加
- 总之,这样使得 检测假设和检测器质量同时增加,解决了 “高质量检测悖论”
4.4 Differences from Previous Works
- Cascade R-CNN和iterative bounding box regression 和 integral loss有相似的地方,但也有不同的地方
Iterative Bounding Box Regression
- 这个方法说一次的bb regression不够,它在inference时用多个相同的regressor来进行多次回归,但是在训练的时候和使用u=0.5的普通的two-stage检测器没有区别
- 这个方法的两个问题:
- 如图 2 所示,在 u = 0.5 时训练的回归器 f 对于更高 IoU 的假设是次优的。它实际上会降低大于 0.85 的 IoU 的边界框精度
- 如图5所示,边界框的分布在每次迭代后都会发生显着变化,虽然回归量对于初始分布是最优的,但在此之后可能会非常不理想
Integral Loss
- Integral Loss的公式如下:
L c l s ( h ( x ) , y ) = ∑ u ∈ U ( h u ( x ) , y u ) L_{cls}(h(\boldsymbol x), y)=\sum_{u\in U}(h_u(\boldsymbol x), y_u) Lcls(h(x),y)=u∈U∑(hu(x),yu)
这个公式可以根据选择的IoU来选择最合适的loss