Neural Style Transfer解读与实现

论文 [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会对原图中的噪声较为敏感,抽象派的效果就看不出太多噪声
在这里插入图片描述

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值