笔者小白最近发现Neural-Style做出来的效果非常神奇。这里把我学习到的一些信息记录下来。

Neural-Style主要做的一件事情很有意思,就是如下图的等式,通过将a图的style和p图的content进行融合,得到第三幅图x。style+content=styled content

DeepLearning-风格迁移(Neural-Style)

怎么做呢?首先他定义了两个loss,分别表示最终生成的图x和style图a的样式上的loss,以及图x和content图p的内容上的loss,α,β是调节两者比例的参数。最终的loss function是两者的加和。通过optimize总的loss求得最终的x。

DeepLearning-风格迁移(Neural-Style)

DeepLearning-风格迁移(Neural-Style)

content loss

假设p和x在CNN中的响应分别为Pl和Fl,将他们内容上的loss表示成每个pixel的二范数:

DeepLearning-风格迁移(Neural-Style)

则用梯度下降法,content loss对F求导为:

DeepLearning-风格迁移(Neural-Style)

Style Loss

DeepLearning-风格迁移(Neural-Style)

那么每一层style loss为 :

DeepLearning-风格迁移(Neural-Style)

其中style图a的在CNN中的响应为A。
则总的style loss为每一层的加权和:

DeepLearning-风格迁移(Neural-Style)

Total Loss

在定义好了两个loss的形式以后,又回到了最初的问题,就是最小化总的loss:

DeepLearning-风格迁移(Neural-Style)

要注意的是,不同于一般的CNN优化,这里优化的参数不再是网络的w和b,而是初始输入的一张噪声图片x

DeepLearning-风格迁移(Neural-Style)

最终我们想让他变成右图这样styled content。

Experiments

1、对同一张content图片运用不同style的结果如下图所示,fantastic!!

DeepLearning-风格迁移(Neural-Style)

2、total loss中α和β的比例:
从上到下表示的是运用不同conv层的feature进行style,conv1->conv5是一个从整体到局部的过程;
从左到右表示的是不同的α/β的比例,10的5次->10的2次是指更注重style还是更强调content。

DeepLearning-风格迁移(Neural-Style)

文章地址:A Neural Algorithm of Artistic Style
代码地址一:https://github.com/jcjohnson/neural-style
代码地址二:https://github.com/fchollet/keras/blob/master/examples/neural_style_transfer.py

根据上述代码二,笔者小白在实验机上学习了测试程序,测试程序的环境配置请参考
资料3的地址。

实验结果如下:
DeepLearning-风格迁移(Neural-Style)

原图1:

DeepLearning-风格迁移(Neural-Style)

风格图2:

DeepLearning-风格迁移(Neural-Style)

迭代10次之后的效果图3:

DeepLearning-风格迁移(Neural-Style)

参考资料:
1、http://blog.csdn.net/elaine_bao/article/details/50502929 2017.9.25
2、http://blog.csdn.net/victoriaw/article/details/71663332 2017.9.25
3、http://blog.csdn.net/hungryof/article/details/52037405 2017.9.25
4、http://blog.csdn.net/u011129494/article/details/47708015 2017.9.25
5、https://zhuanlan.zhihu.com/p/24102375 2017.9.11
6、http://www.jianshu.com/p/8f8fc2aa80b3 2017.9.11

相关文章:

  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-07-25
  • 2021-09-19
  • 2021-12-30
  • 2021-11-14
猜你喜欢
  • 2021-04-29
  • 2021-07-19
  • 2021-04-14
  • 2021-12-15
  • 2021-07-28
  • 2021-12-04
相关资源
相似解决方案