看懂paper中的卷积堆叠感受野计算

VGG中卷积堆叠

在赢得其中一届ImageNet比赛里VGG网络的文章中,他最大的贡献并不是VGG网络本身,而是他对于卷积叠加的一个巧妙观察。

This (stack of three 3 × 3 conv layers) can be seen as imposing a regularisation on the 7 × 7 conv. filters, forcing them to have a decomposition through the 3 × 3 filters (with non-linearity injected in between).

这里意思是 7 x 7 的卷积层的正则等效于 3 个 3 x 3 的卷积层的叠加。而这样的设计不仅可以大幅度的减少参数,其本身带有正则性质的 convolution map 能够更容易学一个 generlisable, expressive feature space。这也是现在绝大部分基于卷积的深层网络都在用小卷积核的原因。

image

代码验证

def receptiveField(net, layernum):
    RF = 1
    for layer in reversed(range(layernum)):
        kSize, stride, pad, dilation = net[layer]
        RF = (RF - 1) * stride + (dilation * (kSize - 1) + 1)  
    return RF
    
""" VGG 两层3x3卷积感受野等价于7x7卷积"""
vgg = [[3, 2, 1, 1], [3, 2, 1, 1]] # kSize, stride, pad, dilation
print(receptiveField(vgg, 2)) # 7

""" VGG 两层3x3卷积感受野等价于7x7卷积"""
vgg = [[3, 1, 1, 1], [3, 1, 1, 1]]
print(receptiveField(vgg, 2)) # 5

空洞卷积常见图

借用了知乎上的图,画的很好

当前层卷积核作用于前一层的feature map,蓝色框代表当前层卷积核视野,红色框表示前一层的感受野(图b红框表示图a的大小,图c中红框表示图b的大小)不是很清楚就继续看下面的图

image

其实第一件事情是我们需要搞清楚每一张画的是啥,画的不是feature map,是感受野,准确来说是每一个新卷积层卷出的feature map中的一个像素能够看到原图中的多大的一块区域

image

这样应该就可以理解了

下面是用代码来验证:

代码中用到了感受野的top to down公式 参照之前的博文

def receptiveField(net, layernum):
    RF = 1
    for layer in reversed(range(layernum)):
        kSize, stride, pad, dilation = net[layer]
        RF = (RF - 1) * stride + (dilation * (kSize - 1) + 1)  # dilation*(fsize-1) + 1 代表新的kernel size 其中dilation表示查插入缝隙长度+1 没有插入时 dilation=1
    return RF

net = [[3, 1, 1, 1], [3, 1, 1, 2], [3, 1, 1, 4]] # kSize, stride, pad, dilation
print(receptiveField(net, 3)) # 15

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务