经典论文重读---风格迁移篇(一):Image Style Transfer Using Convolutional Neural Networks

核心思想

采用深层卷积网络提取图像风格特征与内容,并将其进行融合生成效果很好的艺术图。

引言部分

将一幅图像的风格迁移到另一副图像可以看作是纹理迁移的一个分支。对于纹理迁移,它的目标是从源图合成一种纹理同时施加一定的限制条件来保留目标图像内容的显著性。在采用神经网络进行风格迁移之前有很多研究方法,但效率或者效果都不尽如人意。

以前传统的方法普遍存在的弱点在于:

they use only low-level image features of the target image to inform the texture transfer.

即传统方法只是使用了目标图像的低级特征来进行转移。但是完备的风格迁移算法应该能提取目标图像的语义内容,之后再进行纹理迁移,从而达到即保留了目标图像的语义特征又囊括了源图像的风格或者纹理。

以上的一个先觉条件是:

a fundamental prerequisite is to find image representations that independently model variations in the semantic image content and the style in which it is presented.

即找到图像的特征:图像风格的特征,图像内容的特征。

在过去,想要把图像内容从图像风格分离是极其困难的。然而利用CNN(例如在目标检测任务上训练好的网络,因为这些网络具备一定的学习能力,能够提取高层的特征)。

It was shown that Convolutional Neural Networks trained with sufficient labeled data on specific tasks such as object recognition learn to extract high-level image content in generic feature representations that generalise across datasets and even to other visual information processing tasks.

接下来作者简要介绍了CNN是如何处理图像的内容和风格的,作者提出了一种新颖的方法称之为A Neural Algorithm of Artistic Style.

实际上该算法可看作是通过CNN提取特征进行纹理合成的一种方法。该模型依靠深层次的图像特征,因此风格迁移方法也变为了神经网络的优化问题。该算法总结下来就是:将一个基于CNN的参数化纹理提取模型和根据图像特征反求图像的方法结合起来的一种算法。

In fact, our style transfer algorithm combines a parametric texture model based on Convolutional Neural Networks with a method to invert their image representations

模型实现细节

作者对VGG-19 网络进行了稍许修改:

  • scale the networks
  • replacing the maximum pooling operation by average pooling
  • do not use any of the fully connected layers

深层次图像特征—图像内容特征

了解CNN的学者都知道,一副图像 x 在CNN的每一层都被编码,如假设一个卷积层有 N l 个卷积核,那么就会输出 N l 个特征图,每个特征图大小为 M l ,因此我们可以用矩阵 F l 存储每一层结果,矩阵大小为 N l × M l 。那么其每个矩阵元素 F i j l 的含义为:在第 l 层,第 i 个卷积核在位置 j 的结果。

为了对图像信息进行可视化,可以进行如下操作,首先有几个变量定义:

  • p :原图像
  • x :初始化的白噪声图像
  • P l :原图像的内容特征
  • F l :白噪声图像的内容特征

然后对图像 x 运用梯度下降,可以生成与原图特征相对应的人造图,使用如下的损失函数:

L c o n t e n t ( p , x , l ) = 1 2 i , j ( F i j l P i j l ) 2

通过后向传导可以计算出图像 x 的梯度,跟据梯度调整白噪图( x )直到其产生的特征描述矩阵与原图一致。

作者发现:对于在目标识别上训练出来的CNN网络有这种潜质——它的层次越深,对物体信息的描述就越明显。即存在如下特性:

higher layers in the network capture the high-level content in terms of objects and their arrangement in the input image but do not constrain the exact pixel values of the reconstruction very much

即深层网络可以捕获到高等级的图像内容,但却不能对具体像素值是否接近原图像进行很好限制,以此类比:

In contrast, reconstructions from the lower layers simply reproduce the exact pixel values of the original image

浅层次的网络则可以重构与原图接近的像素值,如下图:

这里写图片描述

深层次图像特征—图像风格特征

为了获取风格特征(a representation of the style),作者主要使用了用于捕捉纹理信息的特征空间。而这个特征空间(feature space)之所以可以用来描述风格,在于它包含了不同卷积层间的联系:

This feature space can be built on top of the filter responses in any layer of the network. It consists of the correlations between the different filter responses

可以通过Gram矩阵计算得出:

G i j l = k F i k l F j k l

其中 G i j l 表示第 l 层中第 i 个feature map与第 j 个feature map的联系,即部分风格特征。

通过获取多个层之间的feature correlations,便可以获得图像的总体风格特征:

By including the feature correlations of multiple layers, we obtain a stationary, multi-scale representation of the input image.

同生成图像内容特征的方法一样,作者先初始化一个白噪声图像 x ,用 a 代表风格图像,用 A l G l 表示白噪声图像和风格图像在第 l 层的风格特征,通过让梯度下降的方式来让白噪声图像逐渐逼近风格图像,损失函数如下:

E l = 1 4 N l 2 M l 2 i , j ( G i j l A i j l ) 2 L s t y l e ( a , x ) = l = 0 L w l E l

其中 w l 代表每一层网络的权重。

风格转换

整个风格转换流程如论文中的Fig.2:

这里写图片描述

其中有:

  • (artwork)风格图像: a
  • (photograph)内容图像: p
  • 最终生成的图像(初始为白噪声): x

对如下的损失函数进行梯度下降,minimise即可生成想要的结果:

L t o t a l ( p , a , x ) = α L c o n t e n t ( p , x ) + β L s t y l e ( a , x )

其中 α , β 用于调节风格特征和内容特征损失函数各自的权重。作者在论文中展示了一些结果:

这里写图片描述

结果与讨论

风格和内容的一些权衡

通过修改超参数,可以使得生成的图像more content matching或者more style matching.首先作者探讨了 α / β 对图像生成的影响:

这里写图片描述

不同卷积层的生成效果

As outlined above, the style representation is a multi-scale representation that includes multiple layers of the neural network

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

深层的网络可以更好保留图像结构,给人更好的视觉体验,对于风格特征来说。作者通过match不同卷积层得出的content representation来说明深层的网络结果可以跟好的融合风格和内容:

这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_37762749/article/details/81569068