经典网络DenseNet介绍
經(jīng)典網(wǎng)絡(luò)DenseNet(Dense Convolutional Network)由Gao Huang等人于2017年提出,論文名為:《Densely Connected Convolutional Networks》,論文見(jiàn):https://arxiv.org/pdf/1608.06993.pdf
DenseNet以前饋的方式(feed-forward fashion)將每個(gè)層與其它層連接起來(lái)。在傳統(tǒng)卷積神經(jīng)網(wǎng)絡(luò)中,對(duì)于L層的網(wǎng)絡(luò)具有L個(gè)連接,而在DenseNet中,會(huì)有L(L+1)/2個(gè)連接。每一層的輸入來(lái)自前面所有層的輸出。
DenseNet網(wǎng)絡(luò):
(1).減輕梯度消失(vanishing-gradient)。
(2).加強(qiáng)feature傳遞。
(3).鼓勵(lì)特征重用(encourage feature reuse)。
(4).較少的參數(shù)數(shù)量。
Dense Block:像GoogLeNet網(wǎng)絡(luò)由Inception模塊組成、ResNet網(wǎng)絡(luò)由殘差塊(Residual Building Block)組成一樣,DenseNet網(wǎng)絡(luò)由Dense Block組成,論文截圖如下所示:每個(gè)層從前面的所有層獲得額外的輸入,并將自己的特征映射傳遞到后續(xù)的所有層,使用級(jí)聯(lián)(Concatenation)方式,每一層都在接受來(lái)自前幾層的”集體知識(shí)(collective knowledge)”。增長(zhǎng)率(growth rate)是每個(gè)層的額外通道數(shù)。
Growth rate:如果每個(gè)函數(shù)產(chǎn)生個(gè)feature-maps,那么第層產(chǎn)生個(gè)feature-maps。是輸入層的通道數(shù)。將超參數(shù)稱為網(wǎng)絡(luò)的增長(zhǎng)率。
DenseNet Basic Composition Layer:BatchNorm(BN)-ReLu-3*3 Conv
DenseNet-B(Bottleneck Layers):在BN-ReLu-3*3 Conv之前進(jìn)行BN-ReLU-1*1 Conv操作,減少feature maps size。
Transition Layer(過(guò)渡層):采用1*1 Conv和2*2平均池化作為相鄰Dense Block之間的轉(zhuǎn)換層,減少feature map數(shù)和縮小feature map size,size指width*height。在相鄰Dense Block中輸出的feature map size是相同的,以便它們能夠很容易的連接在一起。
DenseNet-BC:如果Dense Block包含個(gè)feature-maps,則Transition Layer生成輸出feature maps,其中<img src="https://img.api-racing.com/2023/02/20230214101956328.png" title="" alt="0<\theta <img onload="Wpfcll.r(this,true);" src="https://javaforall.cn/wp-content/plugins/wp-fastest-cache-premium/pro/images/blank.gif" class="j-lazy" data-wpfc-original-src="http://javaforall.cn/wp-content/uploads/2020/11/2020110816061913.jpg" data-original="https://img.api-racing.com/2023/02/20230214101956328.png" title="" alt="0<\theta 稱為壓縮因子。當(dāng)時(shí),通過(guò)Transition Layers的feature-maps數(shù)保持不變。當(dāng)<img src="https://img.api-racing.com/2023/02/20230214101956328.png" title="" alt="\theta <img onload="Wpfcll.r(this,true);" src="https://javaforall.cn/wp-content/plugins/wp-fastest-cache-premium/pro/images/blank.gif" class="j-lazy" data-wpfc-original-src="http://javaforall.cn/wp-content/uploads/2020/11/2020110816061913.jpg" data-original="https://img.api-racing.com/2023/02/20230214101956328.png" title="" alt="\theta 時(shí),稱為DenseNet-C,在實(shí)驗(yàn)中。當(dāng)同時(shí)使用Bottleneck和<img src="https://img.api-racing.com/2023/02/20230214101956328.png" title="" alt="\theta <img onload="Wpfcll.r(this,true);" src="https://javaforall.cn/wp-content/plugins/wp-fastest-cache-premium/pro/images/blank.gif" class="j-lazy" data-wpfc-original-src="http://javaforall.cn/wp-content/uploads/2020/11/2020110816061913.jpg" data-original="https://img.api-racing.com/2023/02/20230214101956328.png" title="" alt="\theta 的Transition Layers時(shí),稱為DenseNet-BC。
下圖是一個(gè)DenseNet結(jié)構(gòu)圖,來(lái)自于論文:使用了3個(gè)Dense Blocks。DenseNet由多個(gè)Desne Block組成。每個(gè)Dense Block中的feature-map size相同。兩個(gè)相鄰Dense Block之間的層稱為Transition Layers。通過(guò)卷積和池化來(lái)更改feature-map size。
論文中給出了4種層數(shù)的DenseNet,論文截圖如下所示:所有網(wǎng)絡(luò)的增長(zhǎng)率是32,表示每個(gè)Dense Block中每層輸出的feature map個(gè)數(shù)。
DenseNet-121、DenseNet-169等中的數(shù)字121、169是如何計(jì)算出來(lái)的:以121為例,1個(gè)卷積(Convolution)+6個(gè)Dense Block*2個(gè)卷積(1*1、3*3)+1個(gè)Transition Layer(1*1 conv)+12個(gè)Dense Block*2個(gè)卷積(1*1、3*3)+ 1個(gè)Transition Layer(1*1 conv)+24個(gè)Dense Block*2個(gè)卷積(1*1、3*3)+ 1個(gè)Transition Layer(1*1 conv)+ 16個(gè)Dense Block*2個(gè)卷積(1*1、3*3)+最后的1個(gè)全連接層=121。這里的層僅指卷積層和全連接層,其它類型的層并沒(méi)有計(jì)算在內(nèi)
公式表示:其中表示非線性轉(zhuǎn)換函數(shù)
(1).傳統(tǒng)的網(wǎng)絡(luò)在層的輸出為:
(2).ResNet在l層的輸出為:
(3).DenseNet在l層的輸出為:
假如輸入圖像大小為n*n,過(guò)濾器(filter)為f*f,padding為p,步長(zhǎng)(stride)為s,則輸出大小為:計(jì)算卷積層大小,如果商不是整數(shù),向下取整,即floor函數(shù);計(jì)算池化層大小,如果商不是整數(shù),向上取整,即ceil函數(shù)。參考:https://blog.csdn.net/fengbingchun/article/details/80262495
在https://github.com/fengbingchun/Caffe_Test/tree/master/test_data/Net/DenseNet 上整理了DenseNet prototxt文件。
這里描述下DenseNet-121架構(gòu):k=32,與上表中”DenseNet-121″有所差異
(1).輸入層(Input):圖像大小為224*224*3。
(2).卷積層Convolution+BatchNorm+Scale+ReLU:使用64個(gè)7*7的filter,stride為2,padding為3,輸出為112*112*64,64個(gè)feature maps。
(3).Pooling:最大池化,filter為3*3,stride為2,padding為1,輸出為57*57*64,64個(gè)feature maps。
(4).Dense Block1:輸出為57*57*(64+32*6)=57*57*256,256個(gè)feature maps。
連續(xù)6個(gè)Dense Block,每個(gè)Dense Block包含2層卷積,卷積kernel大小依次為1*1、3*3,在卷積前進(jìn)行BatchNorm+Scale+ReLU操作,第1、2個(gè)卷積輸出feature maps分別為128、32。因?yàn)閗=32,所以每個(gè)Dense Block輸出feature maps數(shù)會(huì)比上一個(gè)Dense Block多32。每個(gè)Dense Block后做Concat操作。
(5).Transition Layer1:輸出為29*29*128,128個(gè)feature maps。
A.BatchNorm+Scale+ReLU+1*1 conv,輸出57*57*128。
B.平均池化,filter為2*2,stride為2,輸出29*29*128。
(6).Dense Block2:輸出為29*29*(128+32*12)=29*29*512,512個(gè)feature maps。
連續(xù)12個(gè)Dense Block,每個(gè)Dense Block包含2層卷積,卷積kernel大小依次為1*1、3*3,在卷積前進(jìn)行BatchNorm+Scale+ReLU操作,第1、2個(gè)卷積輸出feature maps分別為128、32。因?yàn)閗=32,所以每個(gè)Dense Block輸出feature maps數(shù)會(huì)比上一個(gè)Dense Block多32。每個(gè)Dense Block后做Concat操作。
(7).Transition Layer2:輸出為15*15*256,256個(gè)feature maps。
A.BatchNorm+Scale+ReLU+1*1 conv,輸出29*29*256。
B.平均池化,filter為2*2,stride為2,輸出15*15*256。
(8).Dense Block3:輸出為15*15*(256+32*24)=15*15*1024,1024個(gè)feature maps。
連續(xù)24個(gè)Dense Block,每個(gè)Dense Block包含2層卷積,卷積kernel大小依次為1*1、3*3,在卷積前進(jìn)行BatchNorm+Scale+ReLU操作,第1、2個(gè)卷積輸出feature maps分別為128、32。因?yàn)閗=32,所以每個(gè)Dense Block輸出feature maps數(shù)會(huì)比上一個(gè)Dense Block多32。每個(gè)Dense Block后做Concat操作。
(9).Transition Layer3:輸出為8*8*512,512個(gè)feature maps。
A.BatchNorm+Scale+ReLU+1*1 conv,輸出15*15*512。
B.平均池化,filter為2*2,stride為2,輸出8*8*512。
(10).Dense Block4:輸出為8*8*(512+32*16)=8*8*1024,1024個(gè)feature maps。
連續(xù)16個(gè)Dense Block,每個(gè)Dense Block包含2層卷積,卷積kernel大小依次為1*1、3*3,在卷積前進(jìn)行BatchNorm+Scale+ReLU操作,第1、2個(gè)卷積輸出feature maps分別為128、32。因?yàn)閗=32,所以每個(gè)Dense Block輸出feature maps數(shù)會(huì)比上一個(gè)Dense Block多32。每個(gè)Dense Block后做Concat操作。
(11).Classification Layer:
A.平均池化:filter為8*8,stride為1,padding為0,輸出為1*1*1024,1024個(gè)feature maps。
B.卷積:kernel大小為1*1,輸出1000個(gè)feature maps。
C.輸出層(Softmax):輸出分類結(jié)果,看它究竟是1000個(gè)可能類別中的哪一個(gè)。
可視化結(jié)果如下圖所示:
GitHub:https://github.com/fengbingchun/NN_Test
總結(jié)
以上是生活随笔為你收集整理的经典网络DenseNet介绍的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: matlab中的ezplot函数(Mat
- 下一篇: java中quicksort的参数_Ja