论文 [Gatys et al., 2015. A Neural Algorithm of Artistic Style]
给出一张content image(比如照片),再给出一个style image,可以把照片画风转换成style image的风格
主要原理是取一个在content image和style image间的balance
用一张白噪声图像不断学习,生成兼顾content和style的新图像
content image:
在CNN的layer中,低层layer主要关注pixel级别的特征,而高层layer更关注image的content,因此论文中考虑用CNN高层layer的feature map来reconstruct图像的content
style image:
论文中说用所有layer的feature map的correlation来表示style
有一种特征同时又有另一种特征就是相关,比如一个feature map表示它有条纹,另一个feature map表示有橙色,取correlation就会兼顾这些特征,如果取较低层的layer,就会包含比较local的style
由于CNN表示的content和style是分开的,所以可以从一个图像中提取content,另一个图像中提取style,然后mix可以生成新的图像,这样既保持了原来图像中的content,又会有art图像的style。
用object recognition的feature map来获得content和style,模型用VGG-19
既然要保持content和style的balance,就需要学习一个loss function
L
=
α
L
c
o
n
t
e
n
t
+
β
L
s
t
y
l
e
L = \alpha L_{content} + \beta L_{style}
L=αLcontent+βLstyle
接下来就是如何计算 L c o n t e n t L_{content} Lcontent和 L s t y l e L_{style} Lstyle
L
c
o
n
t
e
n
t
L_{content}
Lcontent:
l
l
l层layer的content image的feature map用
F
i
j
l
F_{ij}^{l}
Fijl表示,generated image的feature map用
P
i
j
l
P_{ij}^l
Pijl表示
这个是VGG-19 model
然后,这里i代表i层的feature map,generated image刚开始是白噪声图像
因为relu的关系,back propagation如下
L s t y l e L_{style} Lstyle:
前面说了style image是各个layer的correlation,即各个layer feature map的inner product
这里k是location,也就是遍历feature map,i,j是layer
l
l
l中的各feature map
G称为Gram matrix
layer l l l的style distance也就是content image的Gram matrix和generated image的Gram matrix的mean squared distance
公式中
N
l
N_{l}
Nl代表layer
l
l
l中的filter数,
M
l
M_{l}
Ml代表layer
l
l
l中feature map的size
可以写成
n
C
2
×
n
H
2
×
n
W
2
n_{C}^{2} \times n_{H}^{2} \times n_{W}^{2}
nC2×nH2×nW2
C: channels H: height W: width
总结出来是这样
对下面这幅照片进行风格转换:
使用两种不同的style image和不同的iteration
2个style一个纹理复杂一些,一个偏抽象派
5000次的iteration和1000次差别已经不大,分析cost可以看出在500次前后的时候就已经差不多收敛了
而且可以看出纹理较复杂的style image会对原图中的噪声较为敏感,抽象派的效果就看不出太多噪声