[UFLDL] ConvNet


 
 
作者認為加噪聲用處不大,且max-pooling功能特別強大,大到像作者說的那樣有了max-pooling后什么約束就可以不用了,好像神器一樣。
 
max-pooling的作用是什么? 
max-pooling提供了非線性, 這是max-pooling效果更好的一個重要原因。
 
 
本篇重點關注反卷積,關於卷積和下采樣求導,可以參見:  [Converge] Backpropagation Algorithm
 
關於卷積,提供兩個非常好的鏈接,表達了我心聲:
 
 
 

反卷積

深度網絡結構是由多個單層網絡疊加而成的,而常見的單層網絡按照編碼解碼情況可以分為下面3類:

  1. 既有encoder部分也有decoder部分:比如常見的RBM系列(由RBM可構成的DBM, DBN等),autoencoder系列(以及由其擴展的sparse autoencoder, denoise autoencoder, contractive autoencoder, saturating autoencoder等)。
  2. 只包含decoder部分:比如sparse coding, 和今天要講的deconvolution network.
  3. 只包含encoder部分,那就是普通的feed-forward network.

卷積:假設A=B*C 表示的是:B和C的卷積是A,也就是說已知B和C,求A這一過程叫做卷積;

反卷積:如果已知A和B求C或者已知A和C求B,則這個過程就叫做反卷積;【由feature map卷積feature filter,得到input image】

 

上圖表示的是DN(deconvolution network的簡稱)的第一層,其輸入圖像是3通道的RGB圖,學到的第一層特征有12個,說明每個輸入通道圖像都學習到了4個特征。而其中的特征圖Z是由對應通道圖像和特征分別卷積后再求和得到的。

 

關於卷積網絡中涉及的相關計算,列出一道題比較直接:
One of the early papers on Deep Q-Learning for Atari games (Mnih et al, 2013) contains this description of its Convolutional Neural Network:
"The input to the neural network consists of an 84 × 84 × 4 image. 
The first hidden layer convolves 16 8 × 8 filters with stride 4 with the input image and applies a rectifier nonlinearity.
The second hidden layer convolves 32 4 × 4 filters with stride 2, again followed by a rectifier nonlinearity.
The final hidden layer is fully-connected and consists of 256 rectifier units.
The output layer is a fully-connected linear layer with a single output for each valid action.
The number of valid actions varied between 4 and 18 on the games we considered." For each layer in this network, compute the number of weights per neuron in this layer (including bias)? neurons in this layer? connections into the neurons in this layer? independent parameters in this layer? You should assume there are 18 valid actions (outputs). First Convolutional Layer: J = K = 84, L = 4, M = N = 8, P = 0, s = 4 weights per neuron: 1 + M × N × L = 1 + 8 × 8 × 4 = 257 width and height of layer: 1+(J-M)/s = 1+(84-8)/4 = 20 neurons in layer: 20 × 20 × 16 = 6400 connections: 20 × 20 × 16 × 257 = 1644800 independent parameters: 16 × 257 = 4112
Second Convolutional Layer: J = K = 20, L = 16, M = N = 4, P = 0, s = 2 weights per neuron: 1 + M × N × L = 1 + 4 × 4 × 16 = 257 width and height of layer: 1+(J-M)/s = 1+(20-4)/2 = 9 neurons in layer: 9 × 9 × 32 = 2592 connections: 9 × 9 × 32 × 257 = 666144 independent parameters: 32 × 257 = 8224 Fully Connected Layer: weights per neuron: 1 + 2592 = 2593 neurons in layer: 256 connections: 256 × 2593 = 663808 independent parameters: 663808 Output Layer: weights per neuron: 1 + 256 = 257 neurons in layer: 18 connections: 18 × 257 = 4626 independent parameters: 4626

 

鏈接:https://www.zhihu.com/question/43609045/answer/132235276

[1] Zeiler M D, Krishnan D, Taylor G W, etal. Deconvolutional networks[C]. Computer Vision and Pattern Recognition, 2010.
[2] Zeiler M D, Taylor G W, Fergus R, etal. Adaptive deconvolutional networks for mid and high level featurelearning[C]. International Conference on Computer Vision, 2011.
[3] Zeiler M D, Fergus R. Visualizing andUnderstanding Convolutional Networks[C]. European Conference on ComputerVision, 2013.
[4] Long J, Shelhamer E, Darrell T, et al.Fully convolutional networks for semantic segmentation[C]. Computer Vision andPattern Recognition, 2015.
[5] Unsupervised Representation Learningwith Deep Convolutional Generative Adversarial Networks
[6] Sparse Coding - Ufldl
[7] Denoising Autoencoders (dA)
[8] Convolution arithmetic tutorial
Reference

 

逆卷積【就是反卷積】的一個很有趣的應用是GAN(Generative Adversarial Network)里用來生成圖片:Generative Models 

deconv的用處挺廣,涉及到visualization  pixel-wiseprediction  unsupervised learning  image generation都會用到deconv的結構。
比如 Deconvolutional Network[1][2]做圖片的unsupervised feature learning, ZF-Net論文中的卷積網絡可視化[3], FCN網絡中的upsampling[4], GAN中的Generative圖片生成[5]。
 

Deconvolution大致可以分為以下幾個方面:

  1. unsupervised learning,其實就是covolutional sparse coding 卷積稀疏編碼[1][2]:這里的deconv只是觀念上和傳統的conv反向,傳統的conv是從圖片生成feature map,而deconv是用unsupervised的方法找到一組kernel和feature map,讓它們重建圖片
  2. CNN可視化[3]:通過deconv將CNN中conv得到的feature map還原到像素空間,以觀察特定的feature map對哪些pattern的圖片敏感,這里的deconv其實不是conv的可逆運算,只是conv的transpose,所以tensorflow里一般取名叫transpose_conv
  3. upsampling[4][5]:在pixel-wise prediction比如image segmentation[4]以及image generation[5]中,由於需要做原始圖片尺寸空間的預測,而卷積由於stride往往會降低圖片size, 所以往往需要通過upsampling的方法來還原到原始圖片尺寸,deconv就充當了一個upsampling的角色

 


 

作者:譚旭
鏈接: https://www.zhihu.com/question/43609045/answer/132235276


[1. covolutional sparse coding]

第一篇文章 Deconvolutional Networks[1] 主要用於學習圖片的中低層級的特征表示,

屬於unsupervised feature learning,和傳統的auto-encoder,RBM比較類似,和它最像的還是sparse coding,

 

Ref: [UFLDL] Sparse Representation

Sparse coding一個不足就是runtime cost比較高。

  • learning階段需要學習a和phi
  • inference階段還是需要學習a

 

接下來開始介紹Deconvolutional Network,和sparse coding的思路比較類似,

是學輸入圖片y的latent feature map z,同時也要學卷積核f。

 

如果非要用sparse coding那套來類比解釋的話,就是學習圖片在basis空間f的系數表示z。

只是操作由點乘變成了卷積,如下圖所示,

是圖片的feature map(color channel)數量;

是feature map數量;

是feature map,a,系數】

是卷積核,phi,基】

y 是輸入圖片。

 

 

Loss function是:

上述結構只是單層的deconvolutional layer,可以繼續按照這個方法疊加layer,第一層的z就作為第二層的圖片輸入。Loss function如式3:

其中

 就是上一層的feature map表示,作為當前層的輸入,

 是一個0-1矩陣,相當於一個mask,用來決定哪些位置的輸入需要連接,

有點denoising auto-encoder的味道,附上denoising auto-encoder的關於denoising的解釋[7]:

 
上圖說明基於一部分變量去預測另一部分變量的能力是學習變量的聯合分布的關鍵,這也是Gibbs sampling能work的原因。

 

(1) learning

Deconcolutional Network的學習也是alterlative交替優化,

  1. 先優化 feature map z
  2. 再優化 filter f

如果有多層的話也是逐層訓練。


首先第一步是學習feature map。

學習Deconcolutional Network的loss function有些困難,原因是feature map中的不同位置的點因為filter互相耦合比較嚴重。

作者嘗試了GD,SGD,IRLS(Iterative Reweighted Least Squares)這些優化方法,效果都不理想。

因此作者使用了另外一個優化方法,不是直接優化式3中的z,而是選擇了一個代理變量x,讓z接近x,同時正則化x達到和式3中loss function同樣的效果:

優化上式也是采用交替優化z和x的方法。


第二步是學習filter,正常的梯度下降即可。

整個Deconvolutional Network的學習算法如下圖所示,其中紅色框是學習feature map,其實也相當於做inference,藍色框是學習filter,相當於模型本身的參數學習。

 

(2) inference

Inference包括兩個層面:

第一,根據輸入圖片和學到的filter 從而 inference latent feature map,

第二,根據latent feature map reconstruct圖片。

以兩層Deconcolutional Network為例,首先學習第一層z1,然后學習第二層的z2,注意第二層的學習有兩個loss,

  • 一個是重建z1的loss,即project 1次學習和z1的誤差
  
  • 一個是繼續重建原圖片的loss,即project兩次學習和原始圖片y的誤差
  
  

下圖是Deconcolutional Network學習到的filter示例,可以看到通過unsupervised的方法一樣能學到線條以及線條組合等中低層特征,具體分析可見論文。




第二篇文章 Adaptive Deconvolutional Networks for Mid and High Level Feature Learning[2]也是通過deconvolutional network學習圖片的特征表示,

和上一篇不同的是加入了poolingunpoolingdeconv (transpose conv,deconv的參數只是原卷積的轉置,並不原卷積的可逆運算)

這篇文章才是可視化常用的反卷積,上篇文章的deconv只是說conv的方向從feature map到圖片,也還是feedforward的概念,不是這篇里用的conv和transpose conv。

這篇文章就是要學習圖片的所有層級的特征,還是用unsupervised的方法。以往的其它方法在逐層學習的時候圖片原始像素丟掉了,學習的target只是上一層的feature map,所以高層的filter和輸入圖片的連接就沒那么強了,導致學得不好,所以它要end to end的學習,學習都是以原始像素作為target學習。


網絡結構還是一樣有deconvolution。

然后引入了pooling,采用的是3D pooling,both in a 2D map and between maps,

然后記錄max pooling value and switch idx,也就是pooling的receptive field中最大值的位置。

unpooling的時候最大值的位置還原,其它位置填0,如下圖所示:


整個網絡結構(兩層)如下圖所示:


首先看右邊的卷積通道:y--conv1--z1--pool1--p1--conv2--z2--pool2--p2

然后是左邊的反卷積通道:p2--unpool2--z2--devonv2--p1--unpool2--z1--deconv1--y^

同一層中的conv與deconv的參數是轉置關系,整個conv通道用

 表示,deconv通道用

 表示,下標l代表deconv網絡的層數,conv通道的組成為:


網絡的學習也是分兩個步驟,先固定filter學習feature map (inference),然后固定feature map學習filter (learning),和上一篇文章一樣,學習沒什么難的,大致步驟如下圖,具體可以參見paper細節,

圖片中的紅框代表inference,藍框代表learning。


最后將提出來的feature用於圖片識別分類,使用中間層的feature map作為SPM (Spatial Pyramid Matching) 的輸入,M個feature map的reconstruction average 起來,得到一個SPM的single pyramid,

最后SPM分類器的效果能達到comparable的效果。

 
 
[2. CNN可視化]
deconv第二個方面是用來做CNN的可視化。
ZF-Net[3]中用到了deconv來做可視化,它是將CNN學習到的feature map用得到這些feature map的卷積核,取轉置,將圖片特征從feature map空間轉化到pixel空間,以發現是哪些pixel激活了特定的feature map,達到分析理解CNN的目的。
 
 

[3. upsampling]
分別簡單介紹兩篇文章,FCN和DCAN。FCN[4]主要用來做pixel-wise的image segmentation預測,先用傳統的CNN結構得到feature map,同時將傳統的full connected轉換成了對應參數的卷積層,比如傳統pool5層的尺寸是7×7×512,fc6的尺寸是4096,傳統的full connected weight是7×7×512×4096這樣多的參數,將它轉成卷積核,kernel size為7×7,input channel為512,output channel為4096,則將傳統的分別帶有卷積和全連接的網絡轉成了全卷積網絡(fully convolutional network, FCN)。FCN的一個好處是輸入圖片尺寸大小可以任意,不受傳統網絡全連接層尺寸限制,傳統的方法還要用類似SPP結構來避免這個問題。FCN中為了得到pixel-wise的prediction,也要把feature map通過deconv轉化到像素空間。論文中還有一些具體的feature融合,詳情可參見論文。

DCGAN[5]中使用deconv就更自然了,本身GAN就需要generative model,需要通過deconv從特定分布的輸入數據中生成圖片。GAN這種模式被Yann LeCun特別看好,認為是unsupervised learning的一個未來。

 
 Jeff: 這篇文章是未來GAN系列的基礎,Reference中的論文需要細啃。
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM