介紹
終于可以說一下Resnet分類網(wǎng)絡(luò)了,它差不多是當前應(yīng)用最為廣泛的CNN特征提取網(wǎng)絡(luò)。它的提出始于2015年,作者中間有大名鼎鼎的三位人物He-Kaiming, Ren-Shaoqing, Sun-Jian。絕對是華人學者的驕傲啊。
VGG網(wǎng)絡(luò)試著探尋了一下深度學習網(wǎng)絡(luò)的深度究竟可以深幾許以能持續(xù)地提高分類準確率。我們的一般印象當中,深度學習愈是深(復雜,參數(shù)多)愈是有著更強的表達能力。憑著這一基本準則CNN分類網(wǎng)絡(luò)自Alexnet的7層發(fā)展到了VGG的16乃至19層,后來更有了Googlenet的22層??珊髞砦覀儼l(fā)現(xiàn)深度CNN網(wǎng)絡(luò)達到一定深度后再一味地增加層數(shù)并不能帶來進一步地分類性能提高,反而會招致網(wǎng)絡(luò)收斂變得更慢,test dataset的分類準確率也變得更差。排除數(shù)據(jù)集過小帶來的模型過擬合等問題后,我們發(fā)現(xiàn)過深的網(wǎng)絡(luò)仍然還會使分類準確度下降(相對于較淺些的網(wǎng)絡(luò)而言)。
常規(guī)CNN網(wǎng)絡(luò)后期層數(shù)增加帶來的分類準確率的降低
正是受制于此不清不楚的問題,VGG網(wǎng)絡(luò)達到19層后再增加層數(shù)就開始導致分類性能的下降。而Resnet網(wǎng)絡(luò)作者則想到了常規(guī)計算機視覺領(lǐng)域常用的residual representation的概念,并進一步將它應(yīng)用在了CNN模型的構(gòu)建當中,于是就有了基本的residual learning的block。它通過使用多個有參層來學習輸入輸出之間的殘差表示,而非像一般CNN網(wǎng)絡(luò)(如Alexnet/VGG等)那樣使用有參層來直接嘗試學習輸入、輸出之間的映射。實驗表明使用一般意義上的有參層來直接學習殘差比直接學習輸入、輸出間映射要容易得多(收斂速度更快),也有效得多(可通過使用更多的層來達到更高的分類精度)。
當下Resnet已經(jīng)代替VGG成為一般計算機視覺領(lǐng)域問題中的基礎(chǔ)特征提取網(wǎng)絡(luò)。當下Facebook乍提出的可有效生成多尺度特征表達的FPN網(wǎng)絡(luò)也可通過將Resnet作為其發(fā)揮能力的基礎(chǔ)網(wǎng)絡(luò)從而得到一張圖片最優(yōu)的CNN特征組合集合。
深度殘差學習(Deep Residual learning)
殘差學習
若將輸入設(shè)為X,將某一有參網(wǎng)絡(luò)層設(shè)為H,那么以X為輸入的此層的輸出將為H(X)。一般的CNN網(wǎng)絡(luò)如Alexnet/VGG等會直接通過訓練學習出參數(shù)函數(shù)H的表達,從而直接學習X -> H(X)。
而殘差學習則是致力于使用多個有參網(wǎng)絡(luò)層來學習輸入、輸出之間的參差即H(X) - X即學習X -> (H(X) - X) + X。其中X這一部分為直接的identity mapping,而H(X) - X則為有參網(wǎng)絡(luò)層要學習的輸入輸出間殘差。
下圖為殘差學習這一思想的基本表示。
殘差學習的基本單元
Identity mapping
上小節(jié)中,我們知道殘差學習單元通過Identity mapping的引入在輸入、輸出之間建立了一條直接的關(guān)聯(lián)通道,從而使得強大的有參層集中精力學習輸入、輸出之間的殘差。一般我們用F(X, Wi)來表示殘差映射,那么輸出即為:Y = F(X, Wi) + X。當輸入、輸出通道數(shù)相同時,我們自然可以如此直接使用X進行相加。而當它們之間的通道數(shù)目不同時,我們就需要考慮建立一種有效的identity mapping函數(shù)從而可以使得處理后的輸入X與輸出Y的通道數(shù)目相同即Y = F(X, Wi) + Ws*X。
當X與Y通道數(shù)目不同時,作者嘗試了兩種identity mapping的方式。一種即簡單地將X相對Y缺失的通道直接補零從而使其能夠相對齊的方式,另一種則是通過使用1x1的conv來表示W(wǎng)s映射從而使得最終輸入與輸出的通道達到一致的方式。
實驗比較所用到的殘差網(wǎng)絡(luò)結(jié)構(gòu)與樸素網(wǎng)絡(luò)結(jié)構(gòu)
殘差網(wǎng)絡(luò)與樸素網(wǎng)絡(luò)結(jié)構(gòu)之間的對比
作者為了表明殘差網(wǎng)絡(luò)的有效性,共使用了三種網(wǎng)絡(luò)進行實驗。其一為VGG19網(wǎng)絡(luò)(這是VGG paper中最深的亦是最有效的一種網(wǎng)絡(luò)結(jié)構(gòu)),另外則是順著VGG網(wǎng)絡(luò)思維繼續(xù)加深其層次而形成的一種VGG樸素網(wǎng)絡(luò),它共有34個含參層。最后則是與上述34層樸素網(wǎng)絡(luò)相對應(yīng)的Resnet網(wǎng)絡(luò),它主要由上節(jié)中所介紹的殘差單元來構(gòu)成。
在具體實現(xiàn)殘差網(wǎng)絡(luò)時,對于其中的輸入、輸出通道數(shù)目不同的情況作者使用了兩種可能的選擇。A)shortcut直接使用identity mapping,不足的通道通同補零來對齊;B)使用1x1的Conv來表示W(wǎng)s映射,從而使得輸入、輸出通道數(shù)目相同。
自下面兩表中,我們可看出殘差網(wǎng)絡(luò)能夠在深度增加的情況下維持強勁的準確率增長,有效地避免了VGG網(wǎng)絡(luò)中層數(shù)增加到一定程度,模型準確度不升反降的問題。
不同深度的樸素網(wǎng)絡(luò)與殘差網(wǎng)絡(luò)在Imagenet上的性能表現(xiàn)
不同深度的樸素網(wǎng)絡(luò)與殘差網(wǎng)絡(luò)在Imagenet上的性能表現(xiàn)其二
然后自下表中,我們可以看到常規(guī)Resnet網(wǎng)絡(luò)與其它網(wǎng)絡(luò)如VGG/Googlenet等在Imagenet validation dataset上的性能比較。
Resnet常規(guī)網(wǎng)絡(luò)與其它模型之間的性能比較
bottleneck構(gòu)建模塊
為了實際計算的考慮,作者提出了一種bottleneck的結(jié)構(gòu)塊來代替常規(guī)的Resedual block,它像Inception網(wǎng)絡(luò)那樣通過使用1x1 conv來巧妙地縮減或擴張feature map維度從而使得我們的3x3 conv的filters數(shù)目不受外界即上一層輸入的影響,自然它的輸出也不會影響到下一層module。
Bottleneck模塊
不過它純是為了節(jié)省計算時間進而縮小整個模型訓練所需的時間而設(shè)計的,對最終的模型精度并無影響。
CIFAR10上更深的Resnet網(wǎng)絡(luò)
作者進一步在小的CIFAR10數(shù)據(jù)集上嘗試了更深的Resnet網(wǎng)絡(luò),其深度最多達到了1202層。不過卻發(fā)現(xiàn)分類性能終于開始有了一定下降。作者分析認為可能是層數(shù)過多,導致模型過于復雜,而CIFAR-10較小的數(shù)據(jù)集造成了它的過擬合吧。
如下表為其瘋狂的實驗結(jié)果。
CIFAR-10上更深的Resnet網(wǎng)絡(luò)的應(yīng)用
代碼實例
數(shù)據(jù)輸入層
name: "ResNet-50"layer{name:"data"type:"Data"top:"data"top:"label"include {? ? phase: TRAIN? }transform_param{mirror: true? ? crop_size:224mean_file:"data/ilsvrc12/imagenet_mean.binaryproto"}data_param{source:"examples/imagenet/ilsvrc12_train_lmdb"batch_size:50backend: LMDB? ? prefetch:2}}
如下為構(gòu)成Resnet網(wǎng)絡(luò)的一個residual block表示。注意它這里的identity mapping中包含了一個1x1 conv表示的Ws。而網(wǎng)絡(luò)中其它的若干模塊則可能直接使用的identity mapping,而不含任何有參層。
layer{bottom:"pool1"top:"res2a_branch1"name:"res2a_branch1"type:"Convolution"convolution_param {? ? ? ? ? ? ? ? num_output:256kernel_size:1pad:0stride:1bias_term: false? ? ? ? ? ? ? ? weight_filler {? ? ? ? ? ? ? ? ? type:"xavier"}bias_filler{type:"constant"value:0.2}? ? ? ? }}layer{bottom:"res2a_branch1"top:"res2a_branch1"name:"bn2a_branch1"type:"BatchNorm"batch_norm_param {? ? ? ? }}layer{bottom:"res2a_branch1"top:"res2a_branch1"name:"scale2a_branch1"type:"Scale"scale_param {? ? ? ? ? ? ? ? bias_term: true? ? ? ? }}layer{bottom:"pool1"top:"res2a_branch2a"name:"res2a_branch2a"type:"Convolution"convolution_param {? ? ? ? ? ? ? ? num_output:64kernel_size:1pad:0stride:1bias_term: false? ? ? ? ? ? ? ? weight_filler {? ? ? ? ? ? ? ? ? type:"xavier"}bias_filler{type:"constant"value:0.2}? ? ? ? }}layer{bottom:"res2a_branch2a"top:"res2a_branch2a"name:"bn2a_branch2a"type:"BatchNorm"batch_norm_param {? ? ? ? }}layer{bottom:"res2a_branch2a"top:"res2a_branch2a"name:"scale2a_branch2a"type:"Scale"scale_param {? ? ? ? ? ? ? ? bias_term: true? ? ? ? }}layer{bottom:"res2a_branch2a"top:"res2a_branch2a"name:"res2a_branch2a_relu"type:"ReLU"relu_param {? }}layer{bottom:"res2a_branch2a"top:"res2a_branch2b"name:"res2a_branch2b"type:"Convolution"convolution_param {? ? ? ? ? ? ? ? num_output:64kernel_size:3pad:1stride:1bias_term: false? ? ? ? ? ? ? ? weight_filler {? ? ? ? ? ? ? ? ? type:"xavier"}bias_filler{type:"constant"value:0.2}? ? ? ? }}layer{bottom:"res2a_branch2b"top:"res2a_branch2b"name:"bn2a_branch2b"type:"BatchNorm"batch_norm_param {? ? ? ? }}layer{bottom:"res2a_branch2b"top:"res2a_branch2b"name:"scale2a_branch2b"type:"Scale"scale_param {? ? ? ? ? ? ? ? bias_term: true? ? ? ? }}layer{bottom:"res2a_branch2b"top:"res2a_branch2b"name:"res2a_branch2b_relu"type:"ReLU"relu_param {? }}layer{bottom:"res2a_branch2b"top:"res2a_branch2c"name:"res2a_branch2c"type:"Convolution"convolution_param {? ? ? ? ? ? ? ? num_output:256kernel_size:1pad:0stride:1bias_term: false? ? ? ? ? ? ? ? weight_filler {? ? ? ? ? ? ? ? ? type:"xavier"}bias_filler{type:"constant"value:0.2}? ? ? ? }}layer{bottom:"res2a_branch2c"top:"res2a_branch2c"name:"bn2a_branch2c"type:"BatchNorm"batch_norm_param {? ? ? ? }}layer{bottom:"res2a_branch2c"top:"res2a_branch2c"name:"scale2a_branch2c"type:"Scale"scale_param {? ? ? ? ? ? ? ? bias_term: true? ? ? ? }}layer{bottom:"res2a_branch1"bottom:"res2a_branch2c"top:"res2a"name:"res2a"type:"Eltwise"eltwise_param {? }}layer{bottom:"res2a"top:"res2a"name:"res2a_relu"type:"ReLU"relu_param {? }}
Resnet網(wǎng)絡(luò)的最后若干層。與其它VGG/Alexnet或者Googlenet并無不同。
layer{bottom:"res5c"top:"pool5"name:"pool5"type:"Pooling"pooling_param {? ? ? ? ? ? ? ? kernel_size:7stride:1pool: AVE? ? ? ? }}layer{bottom:"pool5"top:"fc1000"name:"fc1000"type:"InnerProduct"inner_product_param {? ? ? ? ? ? ? ? num_output:1000weight_filler {? ? ? ? ? ? ? ? ? type:"xavier"}bias_filler{type:"constant"value:0}? ? ? ? }}layer{bottom:"fc1000"bottom:"label"top:"prob"name:"prob"type:"SoftmaxWithLoss"include {? ? ? ? ? phase: TRAIN? ? ? ? }}layer{name:"probt"type:"Softmax"bottom:"fc1000"top:"probt"include {? ? ? ? ? phase: TEST? ? ? ? }}layer{name:"accuracy/top-1"type:"Accuracy"bottom:"fc1000"bottom:"label"top:"accuracy/top-1"accuracy_param? ? ? ? {? ? ? ? ? ? ? ? top_k:1}include{phase: TEST? ? ? ? }}layer{name:"accuracy/top-5"type:"Accuracy"bottom:"fc1000"bottom:"label"top:"accuracy/top-5"accuracy_param? ? ? ? {? ? ? ? ? ? ? ? top_k:5}include{phase: TEST? ? ? ? }}
參考文獻
Deep Residual Learning for Image Recognition, He-Kaiming, 2015
https://github.com/intel/caffe
作者:manofmountain
鏈接:http://www.itdecent.cn/p/93990a641066
來源:簡書
簡書著作權(quán)歸作者所有,任何形式的轉(zhuǎn)載都請聯(lián)系作者獲得授權(quán)并注明出處。