Uncorrelated Feature Encoding for Faster Image Style Transfer

07/04/2018 ∙ by Minseong Kim, et al. ∙ Kakao Corp. 6

Recent fast style transfer methods use a pre-trained convolutional neural network as a feature encoder and a perceptual loss network. Although the pre-trained network is used to generate responses of receptive fields effective for representing style and content of image, it is not optimized for image style transfer but rather for image classification. Furthermore, it also requires a time-consuming and correlation-considering feature alignment process for image style transfer because of its inter-channel correlation. In this paper, we propose an end-to-end learning method which optimizes an encoder/decoder network for the purpose of style transfer as well as relieves the feature alignment complexity from considering inter-channel correlation. We used uncorrelation loss, i.e., the total correlation coefficient between the responses of different encoder channels, with style and content losses for training style transfer network. This makes the encoder network to be trained to generate inter-channel uncorrelated features and to be optimized for the task of image style transfer which maintained the quality of image style only with a light-weighted and correlation-unaware feature alignment process. Moreover, our method drastically reduced redundant channels of the encoded feature and this resulted in the efficient size of structure of network and faster forward processing speed. Our method can also be applied to cascade network scheme for multiple scaled style transferring and allows user-control of style strength by using a content-style trade-off parameter.



There are no comments yet.


page 2

page 6

page 8

page 9

page 10

page 11

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Figure 1: The overall configuration of our method. Similar to [1], the pre-trained VGG16[2] feature network is used as the initial encoder, and the decoder network is configured to be mirrored structure of the encoder network. The correlation loss is calculated using the feature maps extracted from the content and style images, and the content and style losses are calculated using the pre-trained VGG16 feature network as [3]

. As shown in the above diagram, decoder networks are learned during the training process but the loss network is fixed. We uses the feature alignment method using mean and standard deviation as

[1] in the feature transformer.

Image style transfer is a computer vision application which synthesizes an output stylized image similar to a target image in style and to a source content image in semantic content. There are three major tasks in image style transfer, i.e., how to define content and style of an image, how to generate an image from the defined style and content, and how to transfer the style of the target image to the output image maintaining its content same to the source content image. For the first task, in the first neural approach

[4], the style of an image is defined as Gram matrices, i.e., the correlations of feature maps extracted from several layers of VGG[2] feature network, and the content as a feature map from a higher layer of VGG feature network. These definitions of style and content are continuosly used with slight modification in the subsequent researchs of image style transfer. For the second task, online iterative pixel-wise optimization[4] and offline feed-forward network learning[3, 5, 6, 1, 7] methods have been proposed. The feed-forward network approaches speeded up image generating process to subrealtime by adopting encoder/decoder network architecture and changing the online optimization process of [4] to offine network learning with the objective function similar to [4]. For the last task of style transfer, modified instance normalization methods[6, 8, 1]

have been proposed to embed multiple or arbitrary styles in a feed-forward network. They interpreted the process of style transfer as an encoded feature distribution alignment under the assumptions of channel-uncorrelated Gaussian distribution

[6, 8, 1]. Later, a new alignment technique of channel-correlated Gaussian distribution[7] improved the generated style quality by using feature covariance with cascade network scheme.

However, the encoder/decoder network approach with correlation-considering alignment of feature distribution[7] still has some limitation. First, computing the square root or inverse of covariance matrix in forward process requires high computational cost. Second, VGG feature network in the previous feed-forward network methods[1, 7] is not an optimized encoder for style transferring task but for image classification task. Third, the architecture of encoder/decoder network is also not optimized in structure.

In this paper, we introduce a simple but powerful method for end-to-end learning of feed-forward network to improve image style transfer in those three aspect of view. We define uncorrelation loss of encoded features and use it to train the encoder network to generate channel-uncorrelated features. Once the inter-channel correlation of the encoded features is removed, we need not use the channel-correlated feature alignment[7] anymore and can use the channel-wise independent feature aligment[1] of much less computational cost. And not only decoder network but also encoder network is optimized to the image style transfer task by doing end-to-end learning with style and content losses to train encoder/decoder networks simultaneously. Moreover, the encoder network trained to minimize our uncorrelation loss is experimentally proven to achieve drastical reduction in dimension of the encoded features. This results in a compact network by removing redundant channels in convolution layer of decoder network. As the previous approaches, our method also allows user control of style strength[6, 8, 1, 7] at runtime and can be applied to the cascade network scheme[7] improve style quality to multiple scaled styles.

The remained of this paper consist of four parts. In the part of related work, we will review previous researches which are related to image style transfer and motivated our methods. In the part of method, our uncorrelation loss and end-to-end learning method with or without cascade network scheme will be described. We will verify the effectiveness of our method based on a generalized experimental results in the part of experimental result, and will conclude this work in the last part.

2 Related Work

Gatys et al.[4] proposed a seminal work on image style transfer by adopting VGG[2] feature network, a convolutional neural network trained for image classification. They used the correlation matrix, a.k.a. Gram Matrix, of the feature map extracted from low to high layers of VGG feature network as the style feature of image and the feature map from a higher layer of VGG feature network as the content feature of image. And they iteratively updated each pixel of an initial noisy image to minimize style loss, i.e., an error between the styles of the output image and target style image, and content loss, i.e., an error between the contents of the output image and the source input image, simultaneously by using a gradient-based optimization method. Although they achieved style transferring to arbitrary target style, their method has a pracitcal problem of very slow image generating speed because of their pixel-wise online optimization process.

Style transferring based on a feed-forward network[3, 5] solved the problem of slow image generation by moving online iterative optimization to offline learning of feed-forward network with the same content and style losses in [4]. Additionaly, Ulyanov et al.[9]

replaced batch normalization with instance normalization and this resulted in output style quality improvement. However, those methods based on a feed-forward network

[3, 5, 9] have a limitation of just one style per network.

Several methods have been proposed to deal with diverse tasks such as spatial-color control [10]

, multiple style interpolation

[6, 8, 1] and photorealism [11] in style transfer.

Dumoulin et al.[6] proposed conditional instance normalization (CIN) method which can synthesizes multiple styles in a feed-forward network by learning different affine parameters for each style in training phase and using the affine parameters corresponding to the target styles to transform input content feature to the style feature domain in test phase. Although they achieved multiple styles in a network, their method has a limitation in number of styles in a network and requires an additional training process for unseen styles. Another domain adaptation approach[12] interpreted style transferring task as a domain adaptation problem with maximum mean discrepancy(MMD) with the second order polynomial kernel. Based on this interpretation, Huang et al.[1] proposed adaptive instance normalization (AdaIN) method which transforms content image to arbitrary target style with a feed-forward network. They adjusted the feature distribution of content image into that of target style image by using means and standard deviations directly calculated from the features of content and style images. Their method assumed that the feature distributions are uncorrelated between channels in their AdaIN layer and style loss calculation, and this caused the lower quality of output style than that of previous approaches[4, 3, 5, 9].

Sun et al.[13, 14]

showed that aligning second order statistics of deep feature is useful to adapt a trained network from source domain to target domain. In the same manner, the latest domain adaptation approach

[7] for image style transfer proposed whitening and coloring (WCT) method for distribution adjustment using means and covariance matrices of the features of content and style images. WCT improved the quality of transferred style by considering inter-channel correlation of features with more computational cost of calculating inverse square root of covariance matrices in forward process of network.

3 Method

Here, we describe how to remove the inter-channel correlation from the encoded feature while maintaining its semantic representational ability for image style transfer during end-to-end learning of a feed-forward network.

3.1 Uncorrelation Loss

Pearson’s correlation coefficient[15]

is a popular measure of correlation between two random variables. If

and are random variables, then their correlation coefficient is represented as Eq.1.


In the same manner, if we have an encoded feature of

channel vectors of (

) length, we can calculate inter-channel correlation coefficient between two channel vectors of the feature as Eq.2 because each channel data of the feature can be interpreted as a sample sets of each channel random variable.


Then, we can define uncorrelation loss (Eq.3) as the summation of all the correlation coefficients between different channel vectors of the encoded features, of content image and of target style image.


The inter-channel correlation coefficient of Eq.2 is geometrically equivalent to cosine distance between two channel residual vectors. Therefore, minimizing the uncorrelation loss of Eq.3 is equivalent to learning the orthogonal independent basis of channels.

3.2 End-to-end Learning for Uncorrelated Feature Encoding

Our style transfer network has an architecture of {encoder, feature transformer, decoder} as shown in fig.1. Encoder and decoder networks have the same structure of VGG[2] feature network and the mirrored VGG structure respectively as the previous works[1, 7]. As the feature transformer, AdaIN layer[1] is used to adjust the encoded feature distribution of content image to the encoded feature distribution of style image without considering inter-channel correlation.

For the objective function of network training, we use the weighted combination of content, style, and uncorrelation losses as Eq.4. Here, L2 loss between the encoded features of output and content images is used as the content loss like the previous feed-forward network learning[4, 3, 1] and L2 loss between Gram matrices of output and target style images is used as the style loss like the original neural style method[4] to consider inter-channel correlation in feature distribution. Uncorrelation loss is calculated as Eq.3. Using appropriate weights for style loss and uncorrelation loss is essential for successful training because, with large values of weights, the content of encoded feature can be eliminated while the style expression on the output image will be strong and the inter-channel correlation of encoded feature will be removed completely. Therefore, the weight values of the losses (, , ) are experimentally determined as (, , ).


3.3 Cascade Network Scheme for Multiple Scaled Style Transfer

Figure 2: Our uncorrelated feature encoding method can be also used with the cascade network scheme of [7] to transform multiple scales of style independently. The first network takes original content image, and the second and third networks use the image generated from the previous network as its content input.
Figure 3: These images show the output stylized images of the cascade networks. As the content image goes through the cascade networks, small patterns appear on the stylized image and color tone of the stylized image becomes similar to the style image.

The spatial and abstract information of the encoded feature differs according to the hierarchical level of layers in a convolutional neural network [4, 3]. For this reason, Li et al.[7] proposed a multiple scaled style transferring scheme using cascade networks. Our uncorrelation feature encoding method can also cooperate with this cascade scheme to improve the quality of style transfer. Our cascade networks consist of three networks as shown in fig.2. Each network has encoder and decoder networks according to one scale of style and trained with the same content loss at the content layer and the accumulated style loss up to the corresponding scale.

Fig.3 shows an example of output stylized images through the cascade of three networks. As the image goes through the cascade, small patterns appear and color tone is corrected on the output image.

4 Experimental Results

4.1 Experimental Setup

As the first feed-forward network approach[3], we used response of {} as the content feature and the responses of {, , , } as the style features. According to this content and style configuration, the structure of VGG16 feature network up to {} layer was used for encoder network and its mirrored structure was use for decoder network.

For the training dataset, we used MS-COCO[16] for content images and Painter By Number[17] for style images. Each dataset consists of approximately 80,000 images. As a pre-processing, the images were resized to 256 pixels maintaining the aspect ratio and then randomly cropped to 240 pixels to avoid boundary artifact and to augmenting training data. With those pre-processed images, our network was trained by using Adam optimizer[18]

with training parameters of 4 epochs, 8 random {content image, style image} pairs per batch, and learning rates

for decoder network. For encoder network, we used smaller learning rate for fine-tunning of the encoder parameters from the initial pre-trained VGG16 parameter values.

4.2 Uncorrelated Feature Encoding

Figure 4: Loss reduction in training process: Each loss is stored for every iteration with batch size 8 during 4 epochs and the average values with 100-iteration mask are used to plot these graphs to reduce fluctuating noise in loss. It is possible to encode an uncorrelated feature with our encoder network trained to minimize uncorrelation loss (right) without much degradation in content (left) and style (center) losses compared to AdaIN [1] with Gram style loss and fixed encoder network.

Fig.4 shows the reduction of content, style, and uncorrelation losses during training process compared to the training result of AdaIN[1] with Gram style loss and fixed encoder network. As the training iteration goes, our uncorrelation loss fastly reduced to which is only about of the initial uncorrelation loss . Fig.5

shows an example content image (left) and two correlation coefficient matrices of its encoded features extracted by the initial VGG encoder network (center) and our trained encoder network (right). Each pixel value of the matrices represents correlation coefficient (eq.

2) between two channels corresponding to the coordinate. We can find that the encoded feature with our trained encoder has very low inter-channel correlation (dark off-diagonal pixels) while that of initial VGG encoder has high inter-channel correlation (bright off-diagonal pixels).

Figure 5: A sample content image (left), correlation coefficient matrices of the extracted features from initial VGG16 feature network (center) and from our trained encoder network (right): After training encoder network with uncorrelation loss (eq.3, the inter-channel correlation (off-diagonal pixels of the center image) in the encoded feature is almost diminished (off-diagonal pixels of the right image).

When inter-channel correlation was removed from the encoded feature, there were no change in the final style loss (center image of fig.4) and increase in the final content loss (left image of fig.4) after 40,000 iterations. This slight degradation in content loss did not affect to the quality of output stylized images. We will compare the image qualities of our method and the previous methods in the later subsection.


Figure 6: From left to right on the first row, style image, content image, style transferred image, and the decoded images of each independent channel of the stylized feature map. As shown in the decoded images, each channel represents independent image features like edge, texture, and color.

The decoded channels of the stylized feature of another sample content and target style pair are presented in fig.6. We can find that each channel represents different shape or texture or color as an independent component of the output stylized image.

4.3 Redundant Channel Elimination

During the network training process with our uncorrelation loss, we observed that not only inter-channel correlation but also intra-channel variance was reduced. The sparseness of the diagonal pixels of a sample correlation coefficient matrix on the right image of fig.

5 shows an example of this situation. This can be understood that redundant channels were eliminated as the channels were getting orthogonalized to be independent of each other.

To measure how many channels are eliminated during the training process, we drew the normalized diagonal summation (eq.5) of the correlation coefficient matrices of batch data. Because each diagonal pixel value of the correlation coefficient matrix is one for non-zero channel or zero for zero channel, the normalized diagonal summation represents the ratio of the number of non-zero channels to total number of channels.


As shown in the left image of fig.7, the normalized diagonal summation is reduced to . This means the number of non-zero channels was reduced to of the total channels after training process.

Figure 7: Change of normalized diagonal summation during training process (left), Change of style loss as the number of eliminated channels increases (center), Sorted channel magnitudes of a sample encoded feature of the style image on fig.8 (right)

The right image of fig.7 shows the ordered magnitudes of the encoded feature channels of the style image on fig.8. Here, we can also find that a large portion of channels are redundant. The center image of fig.7 shows how the style loss is changing as the number of removed channels is increasing. The channels of smaller magnitude were eliminated first. Up to 200 eliminated channels, there is almost no change in style loss in the center image of fig.7 and no degradation in the output stylized image as shown in fig.8. For numbers of eliminated channels larger than 200, the style loss increase quickly (fig.7 and the output stylized image became lack of content and style (fig.8). Because the magnitudes of encoded feature channels change image to image, the indices of redundant channels differ depending on image. Therefore, we experimentally decided to keep of total magnitude of channels and this setting was used for further experiments.

Figure 8: Decoded images of encoded feature with channel elimination: The style quality does not change until eliminating 200 channels of smallest magnitudes (-200 channels). As the number of eliminated channels increases from 200 to 256 (all), components of image like color and shape shown in fig.6 disappear from the decoded image.

4.4 Comparing to the Previous Methods

4.4.1 Quality of Stylized Images

Figure 9: Examples of output stylized images with serveral image style transfer methods: The target style images on the first column are not used in network training.

We compared the output stylized images of our method with single network or with cascade of three networks, neural style[4] with 500 iterations, AdaIN[1] with VGG16 and the same network structure of ours, and WCT[7] with VGG16 and three cascade networks. All networks were trained with the same setup described in the section of Experimental Setup.

The output stylized images for several pairs of content and target style images are drawn in fig.9. As the other two feed-forward network methods[1, 7], our methods with single network or cascade networks also have some degradation in style quality of the output images compared to neural style[4]. However, thanks to the fine-tunned encoder network for style transfer, the result images of our method with single network are slightly better than those of [1] in color tone and detailed texture by using the same network structure. Compared to the results of [7], our method with cascade scheme generated the stylized images of various patterns and tones more similar to the style image. Because our method used style loss to train decoder network while Li et al.[7] used reconstruction loss, it seems that our decoder network generated the stylized images more similar to the target style.

4.4.2 Image Generating Speed

240 pixels
512 pixels
in feature
in transformer
Gatys et al.[4] 5210 18400 - -
Huang et al.[1] 8.75 34.70 Yes No No
Li et al.[7] 62.10 104.00 Yes Yes Yes
Ours (single) 7.41 28.80 No No No
Ours (cascade) 12.00 45.20 No No Yes
Table 1: Comparison of style transferring methods: The elapsed times are average values of 1,000 trials and written in milliseconds.

We measured the elapsed times of forward style transfer processing with our method and the previous methods by calculating the average duration of 1,000 trials. Those methods were performed on Pytorch framework with CUDA 9.0, CuDNN 7.0, and NVIDIA 1080 Ti GPU card. Table.

LABEL:table:speed shows the measured elapsed times. Both with 240 pixel sized image and with 512 pixel sized image, our method achieved the fastest forward processing speed. Because of using the light-weighted uncorrelated feature transform (AdaIN) of [1], our method with cascade networks shows much faster forward processing speed than Li el al.[7] with heavy correlated feature transform (WCT). Compared to Huang et al.[1], our method is slightly faster because channel elimination was done on both side of adjacent layers of encode and decoder networks in the same network structure of [1].

4.5 Style Strength Control

Our method can control the style strength of the output image with user control parameter at run time as the same manner of the previous fast style transfer methods[1, 7, 12]. Fig.10 shows an example result of style strength control.

Figure 10: Run time user control of style strength

5 Conclusion

In this work, we proposed an end-to-end network learning method for image style transferring with uncorrelated feature encoding. Based on the experimental result, it was shown that our uncorrelation loss is effective in training the encoder network to generate uncorrelated feature without loss of content and style representing ability. The independent channels of the encoded feature allowed the feature transformer of style transfer network to use AdaIN method of much lower computational cost for correlation-existing style than WCT with heavy calculation of inverse square root of covariance matrices, and this resulted in faster forward processing speed than the previous correlation-considering method. As an another effect of encoder network learning, it was experimentally proven that a large portion of the encoded feature channels is redundant and, therefore, can be removed without degradation in style loss and image quality.

Although our uncorrelation feature encoding technique was applied only to the content feature layer in this work, it can be applied to multiple scales of feature layers without modification. So, we are expecting much more channel reduction in multiple scales of feature layers and this will achieve much faster forward processing speed. And we can consider another loss which forces the encoder network to reduce the number of encoded feature channels directly in consistent indices. Uncorrelated feature encoding in multiple scales of feature layers and forcing further reduction of channels will prune the network efficiently for much faster real-time process. This is remained for our future works.


  • [1] Huang, X., Belongie, S.: Arbitrary style transfer in real-time with adaptive instance normalization. In: The IEEE International Conference on Computer Vision (ICCV). (Oct 2017)
  • [2] Simonyan, K., Zisserman, A.: Very deep convolutional networks for large-scale image recognition. CoRR abs/1409.1556 (2014)
  • [3] Johnson, J., Alahi, A., Fei-Fei, L.:

    Perceptual losses for real-time style transfer and super-resolution.

    In: European Conference on Computer Vision (ECCV). (Oct 2016)
  • [4] Gatys, L.A., Ecker, A.S., Bethge, M.: Image style transfer using convolutional neural networks.

    In: The IEEE Conference on Computer Vision and Pattern Recognition (CVPR). (June 2016)

  • [5] Ulyanov, D., Lebedev, V., Vedaldi, A., Lempitsky, V.S.: Texture networks: Feed-forward synthesis of textures and stylized images.

    In: International Conference on Machine Learning (ICML). (June 2016)

  • [6] Dumoulin, V., Shlens, J., Kudlur, M.: A learned representation for artistic style. In: International Conference on Learning Representations (ICLR). (Apr 2017)
  • [7] Li, Y., Fang, C., Yang, J., Wang, Z., Lu, X., Yang, M.H.: Universal style transfer via feature transforms. In: Advances in Neural Information Processing Systems. (2017) 385–395
  • [8] Ghiasi, G., Lee, H., Kudlur, M., Dumoulin, V., Shlens, J.: Exploring the structure of a real-time, arbitrary neural artistic stylization network. In: British Machine Vision Conference (BMVC). (Sep 2017)
  • [9] Ulyanov, D., Vedaldi, A., Lempitsky, V.: Improved texture networks: Maximizing quality and diversity in feed-forward stylization and texture synthesis. In: The IEEE Conference on Computer Vision and Pattern Recognition (CVPR). (July 2017)
  • [10] Gatys, L.A., Ecker, A.S., Bethge, M., Hertzmann, A., Shechtman, E.: Controlling perceptual factors in neural style transfer. In: The IEEE Conference on Computer Vision and Pattern Recognition (CVPR). (July 2017)
  • [11] Luan, F., Paris, S., Shechtman, E., Bala, K.: Deep photo style transfer. In: The IEEE Conference on Computer Vision and Pattern Recognition (CVPR). (July 2017)
  • [12] Li, Y., Wang, N., Liu, J., Hou, X.: Demystifying neural style transfer. In: IJCAI. (2017)
  • [13] Sun, B., Feng, J., Saenko, K.: Return of frustratingly easy domain adaptation.

    In: Proceedings of the Thirtieth AAAI Conference on Artificial Intelligence. AAAI’16, AAAI Press (2016) 2058–2065

  • [14] Sun, B., Saenko, K.: Deep coral: Correlation alignment for deep domain adaptation. In: ECCV 2016 Workshops. (2016)
  • [15] Sedgwick, P.: Pearson’s correlation coefficient. BMJ 345 (2012)
  • [16] Lin, T.Y., Maire, M., Belongie, S., Hays, J., Perona, P., Ramanan, D., Dollár, P., Zitnick, C.L.: Microsoft COCO: common objects in context. In: European Conference on Computer Vision (ECCV). (Sep 2014)
  • [17] Nichol, K.: Kaggle dataset: Painter by numbers (2016) https://www.kaggle.com/c/painter-by-numbers.
  • [18] Kingma, D.P., Ba, J.: Adam: A method for stochastic optimization. In: International Conference on Learning Representations (ICLR). (May 2015)