(BackBack)
Research//4 min read

Image Style Transfer (CNN)

Paper Review of Image Style Transfer Using Convolutional Neural Networks.

Summary

This paper discusses a "Neural Algorithm of Artistic Style" that can disentangle and blend the image content and style of natural images." While previous algorithms could handle texture transfer, they were mainly effective for low-level image features of the target image.

This paper utilizes Convolutional Neural Networks (CNNs) trained with ample labeled data for tasks like object recognition. These networks extract high-level image content in generic feature representations that are applicable across datasets and even to other visual information processing tasks, including texture recognition and artistic style classification.

This research applies the feature space given by a normalized version of the 16 convolutional and 5 pooling layers of the 19-layer VGG network.


Style Transfer: Goal of formulation

Goal : Ltotal(p,a,x)=αLcontent+βLstyle(a,x)\mathcal{L}_{total}(p^ ⃗,a^ ⃗, x^ ⃗) = \alpha L_{content} + \beta L_{style}(a^{ ⃗}, x^{ ⃗})

Content representation

Lcontent(p,x,l)=12i,j(FijlPijl)2\mathcal{L}_{content}(p^ ⃗, x^ ⃗,l) =\frac{1}{2}\displaystyle∑_{i,j}(F_{ij}^l-P_{ij}^l)^2

Here, pp^ ⃗ represents the original image, and xx^ ⃗ represents the generated image. The content loss between the two features can be computed by the provided formula.

By training, the random image xx^ ⃗ can match the feature of the original image pp^ ⃗ in a specific layer of the CNN. As we go higher in the layers, the network captures high-level content, focusing on the overall content rather than the exact pixel values of the input image. This is defined as content representation.

Style representation

Correlations between various feature maps are used to get the style of the input image. This correlation can be represented by the Gram matrix. The texture information of the input image can be obtained using the feature correlation of several layers.

Here, aa^ ⃗ represents the original image, and xx^ ⃗ represents the generated image. We can define loss by reducing the distance between the original image and the Gram matrix of the image to be generated as described in the paper.

Total style loss is the sum of the losses of each layer weighted by the weighting factor WlW_l.

p:original imagep^ ⃗ : original \ image

x:generated imagex^ ⃗ : generated \ image

If the features of pp^ ⃗ and xx^ ⃗ encoded in layer are FlF_l and PlP_l , respectively, the content loss between the two features can be defined as follows.

Lcontent(p,x,l)=12i,j(FijlPijl)2\mathcal{L}_{content}(p^ ⃗, x^ ⃗,l) =\frac{1}{2}\displaystyle∑_{i,j}(F_{ij}^l-P_{ij}^l)^2

As you learn by changing random image xx^ ⃗ using back-propagation as follows, it becomes the same as the feature of the original image pp^ ⃗ in a specific layer of CNN.

δLcontentδFijl={(FlPl)ijif Fijl>00if Fijl<0\frac{\delta \mathcal{L}_{content}}{\delta F^l_{ij}} = \begin {cases} (F^l-P^l)_{ij} & \text{if} \ F_{ij}^l > 0 \\ 0 & \text{if} \ F_{ij}^l < 0 \end {cases}

In addition, as you go back to the layer, the network captures the high-level content, so you focus on the overall content rather than the exact pixel values of the input image. Accordingly, the feature response of the higher layer was defined as content presentation.

Style transfer

An image with white noise is inputted, to transfer the artwork aa^ ⃗ (style image) style to the photograph pp^ ⃗ (content image). The total loss function is defined as:

Lcontent(p,x,l)=12i,j(FijlPijl)2\mathcal{L}_{content}(p^ ⃗, x^ ⃗,l) =\frac{1}{2}\displaystyle∑{i,j}(F_{ij}^l-P_{ij}^l)^2

Correlations between several feature maps are used to obtain the style of input image. This feature correlation can be expressed in the following Gram matrix.

Gijl=kFiklFjkl{G}_{ij}^l =\displaystyle∑_{k}F_{ik}^lF_{jk}^l

Texture information of input image can be obtained using feature correlation of several layers.

a:original imagea^ ⃗ : original \ image

x:generated imagex^ ⃗ : generated \ image

If the style presentations of aa^ ⃗ and xx^ ⃗ in the layer are AlA_l and GlG_l , respectively, loss can be defined by reducing the distance between the original image and the Gram matrix of the image to be generated as follows.

El=14Nl2Ml2k(GijlAijl)2{E}_{l} =\frac{1}{4N_l^2M_l^2}\displaystyle∑_{k}(G_{ij}^lA_{ij}^l)^2

If the content of each layer is defined as weighting factor WlW_l, total style loss is as follows.

Lstyle(a,x)=l=0LWlEl\mathcal{L}_{style}(a^ ⃗, x^ ⃗) =\displaystyle∑_{l=0}^LW_lE_l

Overall

The paper describes the learning process of the Style transfer algorithm as such:


Code (Tensorflow 2.0)

GitHub - erickim20/tf-style-transfer