Deformable Convolutional Networks
背景
如何有效地建模几何形变或变化(包括尺度、姿势等变化)一直以来都是一个挑战。大体上有两种方法来处理该问题:1)构建一个包含各种变化的数据集。其实就是数据扩增。2)使用具有形变不变性( transformation-invariant)的特征和算法(例如SIFT )。然而,以上的方法存在着如下缺点:1)几何形变被假设是固定和已知的,这是一种先验信息,用这些有限的、已知的形变来进行数据扩增或设计算法,可想而知,对于新的、未知的形变则无法处理。2)手工设计的特征或算法无法应对过度复杂的形变,即便该形变是已知的。
近年来,CNNs在许多计算机视觉任务上都取得了巨大成功,如图像分类,语义分割以及目标检测。然而,CNN由于固定的几何结构,导致对几何形变的建模受到限制。
a convolution unit samples the input feature map at fixed locations; a pooling layer reduces the spatial resolution at a fixed ratio; a RoI (region-of-interest) pooling layer separates a RoI into fixed spatial bins; There lacks internal mechanisms to handle the geometric transformations. This
causes noticeable problems, for example: CNN中处于同一层的神经元的感受野都是相同的大小
为了解决或减轻这个问题,论文引入了两种新的模块可变形卷积 (deformable convolution) 和 可变形感兴趣区域池化 (deformable RoI pooling) ,来提高对形变的建模能力。这两个模型都是基于一个平行网络学习offset(偏移),使卷积核在input feature map的采样点发生偏移,集中于我们感兴趣的区域或目标。
可变形卷积网络deformable convolutional networks,也算是在STN之后的一个新的变换——STN是说CNN Kernel放死了(比如3*3大小),但是可以通过图片变换让CNN效果更好;而deformable是说既然图片可能各种情况,那我索性CNN的Kernel本身是不规整的,比如可以有dilation,也可以旋转的,或者看起来完全没有规则的。STN主要是学习global and sparse的空间变换特征(旋转缩放等)去做整图的归一化,DCN所引入学习的是更加local and dense的变换特征,针对每一个filter都预测了offset,使其能更加有效地覆盖target所在的区域。
如果要做语义分割,只需要用Deformable Convolution即可,但如果要做目标检测,則需要另外使用Deformable RoI Pooling,对多个Region of Interest (ROI)进行处理,缩放成相同大小的feature map。
Deformable Convolution
很多人以为deformable conv学习的是个deformabe的kernel,比方说本来是一个 3×33\times33×3 相互连接的kernel,最后变成了一个每个位置都有一个offset的kernel。实际情况并不是这样的,作者并没有对kernel学习offset,而是对feature的每个位置学习一个offset,一步一步的解释就是:首先有一个原始的feature map F,在上面做channel为18的 3×33\times33×3 的卷积,得到channel=18的feature map F_offset,然后再对F做deformable conv并且传入offset 的值F_offset,在新得到的结果上,每个值对应原来的feature map F上是从一个 3∗33*33∗3 的kernel上计算得到的,每个值对应的F上的 3∗33*33∗3 的区域上的每个值都有x、y方向上的两个offset,这 3∗3∗2=183*3*2=183∗3∗2=18 的值就由刚才传入的F_offset决定。其实理清楚关键的一点就是:学习出来的offset是channel=18并且和原始feature map一样大小的,对应的是main branch上做deformable conv时候每位置上的kernel的每个位置的offset。
如下图所示,把原来的卷积过程分成两路,共享input feature maps。上面一路用一个额外的conv层来学习offset △pn\triangle \mathrm p_n△pn ,得到 H∗W∗2NH*W*2NH∗W∗2N 的输出(offset),N=∣R∣N=|\mathcal R|N=∣R∣ 表示 grid 中像素个数,2N2N2N 的意思是有 xxx ,yyy 两个方向的 offset 。有了这个 offset 以后,对于原始卷积的每一个卷积窗口,都不再是原来规整的sliding window(input feaure map中的绿框),而是经过平移后的window(蓝框),取到数据后计算过程和卷积一致。即input feature maps和offset共同作为deformable conv层的输入,deformable conv层操作采样点发生偏移,再进行卷积。
传统卷积(The 2D convolution ),主要包含两步:
- sampling using a regular grid R\mathcal RR over the input feature map x\mathrm xx ;
- summation of sampled values weighted by w\mathrm ww .
The grid R\mathcal RR defines the receptive field size and dilation. 以 3×33\times33×3 ,dilation = 1的 kernel 为例:
R={(−1,−1),(−1,0),...,(0,1),(1,1)}
\mathcal R=\{(−1,−1),(−1,0),...,(0,1),(1,1)\}
R={(−1,−1),(−1,0),...,(0,1),(1,1)}
对于output feature map y\mathrm yy 中每一个location p0\mathrm p_0p0 ,一般的卷积就是:
y(p0)=∑pn∈Rw(pn)⋅x(p0+pn)
\mathrm y(\mathrm p_0)=\sum_{\mathrm p_n\in \mathcal R} \mathrm w(\mathrm p_n) \cdot \mathrm x(\mathrm p_0+\mathrm p_n)
y(p0)=pn∈R∑w(pn)⋅x(p0+pn)
而 deformable convolution中,the regular grid R\mathcal RR 用 offsets {△pn∣n=1,...,N},N=∣R∣\{\triangle\mathrm p_n|n=1,...,N\},N=|\mathcal R|{△pn∣n=1,...,N},N=∣R∣ , 进行了调整,得到:
y(p0)=∑pn∈Rw(pn)⋅x(p0+pn+△pn)
\mathrm y(\mathrm p_0)=\sum_{\mathrm p_n\in \mathcal R} \mathrm w(\mathrm p_n) \cdot \mathrm x(\mathrm p_0+\mathrm p_n+\triangle\mathrm p_n)
y(p0)=pn∈R∑w(pn)⋅x(p0+pn+△pn)
注意到 △pn\triangle\mathrm p_n△pn 很可能不是整数像素,而是一个高精度的小数,不能直接获取像素坐标,而如果采用简单粗暴的取整不仅会产生误差也无法采用梯度下降求解,所以要用到Spatial Transformer Networks 里采用的双线性插值(bilinear interpolation):
x(p)=∑qmax(0,1−∣qx−px∣)⋅max(0,1−∣qy−py∣)⋅x(q)
\mathrm x(\mathrm p)=\sum_\mathrm qmax(0,1-|q_x-p_x|)\cdot max(0,1-|q_y-p_y|)\cdot \mathrm x(\mathrm q)
x(p)=q∑max(0,1−∣qx−px∣)⋅max(0,1−∣qy−py∣)⋅x(q)
其中 p=(p0+pn+△pn)\mathrm p=(\mathrm p_0+\mathrm p_n+\triangle\mathrm p_n)p=(p0+pn+△pn) , max()max()max() 函数将 q\mathrm qq 的集合范围约束为距离 p\mathrm pp 最近的4个grid。
Deformable RoI Pooling
Given input feature map x\mathrm xx 和 w×hw\times hw×h 的 RoI 以及左上角 p0\mathrm p_0p0 ,传统RoI pooling把 RoI 分成 k×kk\times kk×k 个bins,对每个bin内的多个像素做average pooling (注意这篇文章不是用的max pooling,我猜测是为了和位置敏感RoI pooling兼容?),最后输出 k×kk\times kk×k 的output feature map,对于 (i,j)(i,j)(i,j)-th bin(0≤i,j<k0\leq i,j < k0≤i,j<k ),有:
y(i,j)=∑p∈bin(i,j)x(p0+p)/nij
\mathrm y(i,j)=\sum_{\mathrm p\in bin(i,j)}\mathrm x(\mathrm p_0+\mathrm p)/n_{ij}
y(i,j)=p∈bin(i,j)∑x(p0+p)/nij
其中 nijn_{ij}nij 是一个bin中的像素的个数,(i,j)(i,j)(i,j)-th bin的范围为 ⌊iwk⌋≤px<⌈(i+1)wk⌉\lfloor i\frac wk\rfloor \le p_x < \lceil(i+1)\frac wk \rceil⌊ikw⌋≤px<⌈(i+1)kw⌉ , ⌊jhk⌋≤py<⌈(j+1)hk⌉\lfloor j\frac hk \rfloor \le p_y < \lceil(j+1)\frac hk \rceil⌊jkh⌋≤py<⌈(j+1)kh⌉ 。而deformable RoI pooling类似deformable convolution,在spatial binning positions中也增加了offsets {△pij∣0≤i,j<k}\{\triangle \mathrm p_{ij}|0\le i,j<k\}{△pij∣0≤i,j<k} ,公式变为:
y(i,j)=∑p∈bin(i,j)x(p0+p+△pij)/nij
\mathrm y(i,j)=\sum_{\mathrm p\in bin(i,j)}\mathrm x(\mathrm p_0+\mathrm p+\triangle \mathrm p_{ij})/n_{ij}
y(i,j)=p∈bin(i,j)∑x(p0+p+△pij)/nij
和前面一样,因为offset是带小数的,不能直接得到像素,需要用双线性插值算法得到每一个像素值。
注意,这里的offset只有 k∗kk*kk∗k 个,而不是每一个像素一个。
Figure 3展示了offsets是如何获得的。如图所示,一个 fc layer 从 RoI pooling 层生成的 pooled feature map 中生成 normalized offsets △p^ij\triangle \widehat{\mathrm p}_{ij}△pij ,之后转换为上面公式中的 △pij\triangle \mathrm p_{ij}△pij 。(???)
和 deformable convolution 的区别在于用的是FC层,原因是RoI pooling之后的结果是固定大小的 k∗kk*kk∗k feature map,直接用FC得到 k∗kk *kk∗k 个offset。但是这些offset不能直接用,因为RoI区域大小不一,并且input feature map的 www 和 hhh 也是大小不一。作者提出的方法是用一个 scaler(element-wise product with RoI’s www and hhh ):
△pij=γ⋅△p^ij∘(w,h) \triangle \mathrm p_{ij}=\gamma\cdot\triangle \widehat{\mathrm p}_{ij}\circ (w,h) △pij=γ⋅△pij∘(w,h)
其中,γ\gammaγ 是一个预定义的scalar,根据经验设为0.1。
Deformable Position-Sensitive RoI Pooling
这个结构主要是针对R-FCN的position-sensitive RoI pooling层做的修改。
Deformable Position-Sensitive RoI Pooling和Deformable RoI pooling层的区别就是把之前公式中的 input feature map x\mathrm xx 替换为了位置敏感分值图中的 xij\mathrm x_{ij}xij (9个颜色的feature map块之一)。
However, the offset learning is different. It follows the “fully convolutional” spirit in [7], as illustrated in Figure 4. In the top branch, a conv layer generates the full spatial resolution offset fields. For each RoI (also for each class), PS RoI pooling is applied on such fields to obtain normalized offsets ∆p bij, which are then transformed to the real offsets ∆pij in the same way as in deformable RoI pooling described above.