当网络最后一层输出的
prediciton map size
和label map size
大小不匹配时,除了bilinea interpolation
等暴力措施,且不采取unpooling
,deconvolution
等decoder
结构, 为了实现 dense prediction , 该怎么做呢?
《Fully Convolutional Networks for Semantic Segmentation》为了实现dense prediction
,他们比较了三种不同方案,分别是 shift and stitch, decreasing subsampling,deconvolution
作者对 shift and stitch
的描述是:
网上的关于shift-and-stitch的解释:设原图与FCN所得输出图之间的降采样因子是f,那么对于原图的每个fxf 的区域(不重叠),“shift the input x pixels to the right and y pixels down for every (x,y) ,0 < x,y < f." 把这个f x f区域对应的output作为此时区域中心点像素对应的output,这样就对每个 fxf 的区域得到了 f2 个output,也就是每个像素都能对应一个output,所以成为了dense prediction
我看了作者 引用 的关于 shift and stitch
的两篇文章:
shift and stitch
的做法其实就是:
设降采样因子是f , 通过 shift pixels (平移像素)的方式,产生 f2 个
version
的input
,输入网络后相应地产生 f2 个output
, 然后stitch
(这个词不好翻译,先翻译成织联)所有output
就实现了dense prediciton
。
在另一篇论文中找到了对shift and stitch
更详尽的描述 :
接下来受论文[2] 的启发,我们举一个简单的例子来直观地说明 shift and stitch
的做法:
设网络只有一层 2x2 的maxpooling
层且 stride = 2
,所以下采样因子 f =2
, 我们需要对input image
的 pixels
平移 (x,y)
个单位,即将 image
向左平移 x
个pixels
, 再向上平移y
个单位,整幅图像表现向左上方向平移,空出来的右下角就以0
padding
。我们当然可以采取 FCN
论文中的做法,将图像向右下角平移,空出来的左上角用 0 padding
,这两种做法产生的结果是一致的,没有本质区别。(x,y)
取(0
,0
), (0
,1
),(1
,0
),(1
,1
) 后,就产生了 f^2^
= 4
个input
,不妨记为: shifted input (0,0)
、shifted input (0,1)
,shifted input (1,0)
,shifted input (1,1)
(回答一个读者的问题:图中的数字表示像素值,不是索引值 )
shift the pixels of original image, 产生4个version 的 input4
个input
分别进行 2x2
的maxpooling
操作后,共产生了4
个output
。
最后,stitch the 4 different output
获得 dense prediction
:
那么问题来了,是怎样进行 stitch
的呢?FCN 作者的说法是:
Process each of these f2 inputs, and interlace the outputs so that the predictions correspond to the pixels at the centers of their receptive fields
说的很明白了,output
中的每个pixel
都对应 original image
的不同 receptive field
,将receptive field
的中心c
填上来自output
的pixel
值,就是网络对original image
中像素 c
类别的prediction
。
为表述简洁,我用 “ 像素 i ” 表示“ 值为 i 的像素 ”。
-
红色
output
中的像素1
对应shifted input(0,0)
的红色部分, 而对应original image
的部分,也即receptive field
仅仅为像素[1],
所以receptive field
的中心为像素[1]
, 该位置填上红色output
中像素1
的值。 -
黄色
output
中的像素4
对应shifted input
(1,0)
的黄色部分, 而对应original image
的部分,也即receptive field
为像素[3,4]
, 所以receptive field
的中心为像素[4]
, 该位置填上黄色output
中像素4
的值。 -
以此类推..
-
注意: 我们注意到黄色
output
中的像素5
与红色output
中的像素5
对应的receptive field
中心是重叠的,所以将黄色output
中的像素5
标为灰色,表示不予考虑。同理其他ouput
中的灰色区域也代表receptive field
中心重叠的像素。