Image Style Transfer Using Convolutional Neural Network(理論篇)

好久沒有寫博客了,也是慚愧,最近事情比較多,現在抽空寫一篇吧


今天這篇是關於neual art的,也就是style transfer算法;
文章來源:
A Neural Algorithm of Artistic Style, CVPR2015
Image Style Transfer Using Convolutional Neural Networks, CVPR2016

前一段時間有一個比較火的APP叫prisma,可以把自己上傳的一張圖進行風格化,內部原理就是今天說的neural art或者叫style transfer

prisma

上面兩篇文章的內容差不多,下面一篇可以看作是上面一篇的擴展,增加了一些其他的實驗,我們說的就是這篇


介紹

其實沒什麼說的,就是如何學習到一張圖的style或者叫風格吧;比如現在有一張梵高的星空圖,一張你自己拍的風景圖,如何將梵高星空圖的style添加到風景圖之中呢???
大概就是像下面這樣:

合成圖

將一張圖的style加到另外一張圖的content上,這個就是style transfer

結構

其實算法的思想很簡單,就是使用CNN進行特徵提取,然後使用這些提取到的特徵進行reconstruct.我們知道不同的CNN的conv layer提取到特徵是不一樣的,低層次的偏向於點 線等特徵,高層次的更加偏向於texture信息.
所以算法的intuition,就是下圖顯示的:

所以作者使用VGG19的網絡結構來做feature extractor,其最終是將conv2_2作爲content layer,將conv1_1,conv2_1,conv3_1,conv4_1conv5_1作爲style layer

具體實現

算法使用隨機的一個白噪聲圖(white noise image)作爲輸入,定義與內容圖的content loss和風格圖的`style loss’,之後使用標準的BP算法更新weight,調整輸入的圖像(白噪聲圖)

注意這裏是調整輸入的圖,目的就是對於某個特定的輸入圖像x,其loss(包含content loss和style losss)達到最小

content loss

A layer with Nl distinct filters has Nl feature maps each of size Ml , where Ml is the height times the width of the feature map. So the responses in a layer l can be stored in a matrix where is the activation of the ith filter at position j in layer l.

假設px分別代表原始的圖像和生成的圖像,l代表layer,在某層的responce,則他們之間的content loss定義爲:

content loss

style loss

feature correlations are given by the Gram matrix Gl ∈ RNl ×Nl , where is the inner product between the vectorised feature maps i and j in layer l:

grama matrix

特徵之間的相關性可以表示原始圖像在layer中的多尺度表達,也就是表示了紋理信息

Let a and x be the original image and the image that is generated, and Al and Gl their respective style representation in layer l. The contribution of layer l to the total loss is then:

總的loss就是content lossstyle loss的線性組合:

loss

架構

總體的結構如下圖所示:

architecture

補充

style和content的比重

也就是a/b的比重,效果如下圖:

可以看出,比值越小合成的圖風格化越明顯

不同的layer對結果的影響

使用不同的layer作爲content feature extraxtor或者style feature extractor效果是不一樣的.

We find that matching the style representations up to higher layers in the network preserves local images structures an increasingly large scale, leading to a smoother and more continuous visual experience.

所以據此選擇了conv(1-5)_1作爲style layer

下圖顯示不同的conv layer作爲content layer的不同影響:

不同的初始化方法

實驗中我們是使用random white noise image作爲input,但是也可以直接使用content image或者style image作爲input,作者的結論是:

the different initialisations do not seem to have a strong effect on the outcome of the synthesis procedure

但是:

only initialising with noise allows to generate an arbitrary number of new images. Initialising with a fixed image always deterministically leads to the same outcome (up to stochasticity in the gradient descent procedure)

後記

我自己做了實驗,對一張140*480的圖,迭代300次,在titan x上用時30s左右,時間確實非常久

原文也給出了結論:

  • The dimensionality of the optimisation problem as well as the number of units in the Convolutional Neural Network grow linearly with the number of pixels.

  • The images presented in this paper were synthesised in a resolution of about 512 × 512 pixels and the synthesis procedure could take up to an hour on a Nvidia K40 GPU (depending on the exact image size and the stopping criteria for the gradientdescent).

發佈了105 篇原創文章 · 獲贊 123 · 訪問量 58萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章