VGG中卷積堆疊
在贏得其中一屆ImageNet比賽里VGG網(wǎng)絡的文章中甥温,他最大的貢獻并不是VGG網(wǎng)絡本身,而是他對于卷積疊加的一個巧妙觀察聊倔。
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 的卷積層的疊加匀们。而這樣的設計不僅可以大幅度的減少參數(shù),其本身帶有正則性質(zhì)的 convolution map 能夠更容易學一個 generlisable, expressive feature space敢订。這也是現(xiàn)在絕大部分基于卷積的深層網(wǎng)絡都在用小卷積核的原因。
代碼驗證
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的大蟹瘛)不是很清楚就繼續(xù)看下面的圖
其實第一件事情是我們需要搞清楚每一張畫的是啥阱驾,畫的不是feature map,是感受野怪蔑,準確來說是每一個新卷積層卷出的feature map中的一個像素能夠看到原圖中的多大的一塊區(qū)域
這樣應該就可以理解了
下面是用代碼來驗證:
代碼中用到了感受野的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