An arbitrary style transfer method based on multi-attention network

Through the combination of multi-attention network and attention loss function, content and style features are extracted and fused, which solves the problem of structure and texture loss in style transfer in the existing technology, and achieves high-quality stylized image generation.

CN114170066BActive Publication Date: 2024-08-23TONGJI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111326217.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-10
Publication Date
2024-08-23
Estimated Expiration
2041-11-10

AI Technical Summary

Technical Problem

It is difficult for the existing technology to effectively retain the salient structure of the content image and the detailed texture of the style image in any style transfer, resulting in insufficient quality of the generated image.

Method used

Using a method based on multi-attention network, the pre-trained VGG-19 network is used to extract content and style features, and feature enhancement and fusion are performed through the unary content attention module, paired style attention module and attention fusion module, and the design attention force loss function to preserve the salient features of the original content image and generate high-quality stylized images.

Benefits of technology

Effective use of the attention mechanism improves the quality of stylized images, retains the salient information of content images and the detailed texture of style images, and achieves efficient arbitrary style transfer.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114170066B
    Figure CN114170066B
Patent Text Reader

Abstract

The present invention discloses an arbitrary style transfer method based on a multi-attention network. Aiming at the problem that the existing style transfer methods have limitations in retaining significant content structures and detailed style patterns, the present invention proposes a multi-attention network for arbitrary style transfer, uses a multi-attention mechanism to extract the significant structure of the content image and the detailed texture of the style image, and transfers the rich style patterns in the artwork to the content image; and designs an attention loss to retain important information of the content. Experimental results show that the present invention can retain the significant content structure and style detailed texture through the multi-attention network, and can effectively generate higher quality stylized images.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of image style transfer and computer vision, and in particular to an arbitrary style transfer method based on a multi-attention network. Background Art

[0002] Arbitrary style transfer is a technique that applies the style of any style image to another content image while retaining the structure of the original content image. Style transfer can be widely used in the creation of artworks, movie special effects rendering, and mobile device camera rendering, saving time and human and material resource costs.

[0003] With the rapid development of deep learning in recent years, image style transfer has made continuous progress. In particular, with the success of convolutional neural networks (CNNs), it has become the main research method for image style transfer. Gatys et al. first showed that content information can be extracted from natural images and style information can be obtained from artistic images through a pre-trained VGG network, and proposed an image reconstruction algorithm to achieve stylization. However, the algorithm is limited by low efficiency. In order to reduce computational costs, researchers have developed several feedforward network-based methods that can effectively generate stylized images, but they are limited to fixed styles or insufficient visual quality. Recently, several methods have been proposed to achieve arbitrary style transfer.

[0004] The closest existing technology and its review:

[0005] In the closest existing technology, some scholars have proposed the AdaIN algorithm (Huang X, Belongie S. Arbitrary style transfer in real-time with adaptive instance normalization [C] / / Proceedings of the IEEE International Conference on Computer Vision. 2017: 1501-1510.), which simply adjusts the mean and variance of the content image to match the style image by transferring global feature statistics. The WCT method (Li Y, Fang C, Yang J, et al. Universal style transfer via feature transforms [C] / / Proceedings of the 31st International Conference on Neural Information Processing Systems. 2017: 385-395.) performs a pair of feature transformations, namely whitening and coloring, to embed features into pre-trained encoder / decoder modules. Park et al. (Park DY, Lee K H. Arbitrary style transfer with style-attentional networks [C] / / Proceedings of the IEEE / CVF Conference on Computer Vision and Pattern Recognition. 2019: 5880-5888.) proposed a style attention network to match style features with content features. Yao et al. (Yao Y, Ren J, Xie X, et al. Attention-aware multi-stroke style transfer [C] / / Proceedings of the IEEE / CVF Conference on Computer Vision and Pattern Recognition. 2019: 1467-1475.) added multi-stroke control and self-attention mechanisms.Svoboda et al. (Svoboda J, Anoosheh A, Osendorfer C, et al. Two-stage peer-regularized feature recombination for arbitrary image style transfer [C] / / Proceedings of the IEEE / CVF Conference on Computer Vision and Pattern Recognition. 2020: 13816-13825.) proposed a two-stage peer regularization layer that uses graph convolution to reorganize the style and content in the latent space. Although these methods have achieved good results, they may encounter the problem of distorted semantic structure of content images and may not reflect the detailed texture of style images. Summary of the invention

[0006] The purpose of the present invention is to provide an arbitrary style transfer method based on a multi-attention network.

[0007] The technical solution of the present invention is based on the problem that the prior art cannot effectively preserve significant content structures and detailed style textures. A pre-trained VGG-19 network is used as an encoder to extract deep features. For the input content image and any style image, their respective features after the encoder are extracted. Considering that only a few features in specific fields can be extracted using a common encoder, and lack of attention to the significant structural part of the content and the internal pixel relationship of the style, an attention mechanism is introduced to extract content features that preserve the significant structure, and at the same time extract style features that preserve the rich texture. The enhanced features are then appropriately fused to obtain stylized features. The two layers (Relu_4_1 layer and Relu_5_1 layer) of features are integrated and input into a decoder symmetrical to the encoder to obtain a generated picture. During the training process, an attention loss function is designed to preserve the significant features of the original content image to obtain a final high-quality stylized image.

[0008] The technical solution to be protected in the present invention is characterized by:

[0009] A method for arbitrary style transfer based on a multi-attention network, characterized by comprising the following steps:

[0010] Step 1: Use MS-COCO as the content image training set and WikiArt as the style image training set;

[0011] Step 2: Construct a style transfer network, including an encoder, a multi-attention module, and a decoder. The encoder and symmetric decoder use a pre-trained VGG-19 network.

[0012] Step 3: Input the paired content training image and style training image into the style transfer network to obtain the generated image;

[0013] Step 4: Input the generated image obtained in step 3, the original content training image, and the original style training image into the style transfer network, calculate the content loss, attention loss, style loss, and identity loss, and get the total loss;

[0014] Step 5: According to the total loss obtained in step 4, the style transfer network model is optimized using the Adam optimizer;

[0015] Step 6: Loop through steps 3 to 5 until the style transfer network converges and save the trained model file.

[0016] Step 7: Input a set of paired content images and style images into the style transfer model obtained in step 6 to obtain the generated stylized image.

[0017] Furthermore, the step 2:

[0018] For the encoder, the content image I c and style image I s As input, extract their respective feature maps and (i is the number of a certain layer); In order to consider both the overall style distribution and the local style, the features of two layers (Relu_4_1 layer and Relu_5_1 layer) are extracted in the encoder, and the results after passing through the multi-attention module are combined to obtain F cs , input it into the symmetric decoder to obtain the stylized image I cs =D(F cs );

[0019] The multi-attention module consists of three parts: a unary content attention module, a paired style attention module, and an attention fusion module;

[0020] The unary content attention module models salient boundaries. The content feature map from the encoder Normalized and input into two convolutional layers to obtain new feature maps and At the same time, the unnormalized Input to another convolutional layer to obtain feature maps Unary Content Attention Map The formula is as follows:

[0021]

[0022] Where expand(·) indicates the enlarged size, represents matrix multiplication, μ(·) represents the mean of the feature. Then we get the enhanced content feature

[0023]

[0024] The pairwise style attention module learns the pixel relationships within the same category region in the style image. The style feature map from the encoder Normalized and input into two convolutional layers to obtain new feature maps and Then subtract the mean from them; Send it to another convolutional layer to get the feature map Paired Style Attention Map The formula is as follows:

[0025]

[0026] Then we get the enhanced style features

[0027]

[0028] After obtaining the enhanced content and style features, the attention fusion module appropriately integrates the content and style features. and style features Normalize to get and Then and Send it to three convolutional layers to generate three new feature maps and Correlation graph The formula is as follows:

[0029]

[0030] In the formula Mapping enhanced content features and enhanced style features The corresponding relationship between them; then, the stylized feature map of each layer (Relu_4_1 layer and Relu_5_1 layer) is calculated as follows:

[0031]

[0032] Then, the final stylized feature map is obtained:

[0033]

[0034] Furthermore, the step 4:

[0035] Content loss L c It is used to make the generated image close to the content image in terms of content. The calculation formula is as follows:

[0036]

[0037] Where φ i (·) represents the feature map extracted from the i-th layer in the encoder;

[0038] Attention loss L attn It is used to minimize the attention difference between the generated image and the content image, which is calculated as follows:

[0039]

[0040] In the formula represents the attention map obtained by feeding the features extracted by the i-th layer in the encoder into the content attention module;

[0041] Style loss L s It is used to make the generated image close to the style image in style. The calculation formula is as follows:

[0042]

[0043] Where σ(·) represents the variance of the feature;

[0044] Identity loss L id Considering the global statistics and the local mapping relationship between content and style features, the calculation formula is as follows:

[0045]

[0046] Where I cc (I ss ) means that two identical content (style) images are simultaneously used as the result of generating content and style images; id1 and λ id2 The weight representing the identity loss can be set by the user according to his / her needs; the total loss function formula is as follows:

[0047] L=λ c L c +λ attn L attn +λ s L s +L id

[0048] Where λ c ,λ attn and λ s It is a weight parameter, which can be set by the user according to needs.

[0049] By adopting the above scheme, the beneficial effects of the present invention are:

[0050] 1. This invention avoids the problem that a single style transfer network loses important information of the content image and rich texture of the style image, effectively utilizes the advantages of the attention mechanism, and improves the quality of the stylized image;

[0051] 2. This paper proposes an efficient multi-attention network for arbitrary style transfer, which can retain the salient information of the content image and the detailed texture of the style image, and flexibly combine content features and style features;

[0052] 3. The present invention proposes a method of enhancing the salient features of the content by using an attention loss function, which can preserve the salient structure of the original content image. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 It is a basic flow chart of the arbitrary style transfer method based on multi-attention network of the present invention.

[0054] Figure 2 It is a structural diagram of the style transfer network of the present invention.

[0055] Figure 3 It is a structural diagram of the multi-attention network of the present invention.

[0056] Figure 4 The following are the results without and with attention loss.

[0057] Figure 5 This is the loss comparison result between the present invention and the prior art.

[0058] Figure 6 It is a comparison chart of the experimental results of the present invention and the prior art. DETAILED DESCRIPTION

[0059] Key points of technical solution:

[0060] 1. About Multi-Attention Networks ( Figure 2 shown):

[0061] When the content and style features output from the encoder enter the multi-attention module, the content features are passed through the unary content attention module to obtain content features that retain significant structures, while the style features are passed through the paired style attention module to obtain style features that retain detailed textures; then, the enhanced content and style features enter the attention fusion module to appropriately embed the style features into the content features; finally, the features of the Relu_4_1 layer and the Relu_5_1 layer are merged. Specifically, the network structure and algorithm are:

[0062] The style transfer network consists of: encoder, multi-attention module and decoder.

[0063] The encoder and symmetric decoder use the pre-trained VGG-19 network to transform the content image I c and style image I s Input encoder, extract their respective feature maps and (i is the number of a certain layer); In order to consider both the overall style distribution and the local style, the features of two layers (Relu_4_1 layer and Relu_5_1 layer) are extracted in the encoder and input into the multi-attention module (the content features are input into the unary content attention module, the style features are input into the paired style attention module, and the outputs of the unary content attention module and the paired style attention module are input into the attention fusion module); The outputs of the two layers (Relu_4_1 layer and Relu_5_1 layer) of the multi-attention module are merged to obtain the style feature F cs , input it into the symmetric decoder to obtain the stylized image I cs =D(F cs ).

[0064] During the training process, the stylized image I cs With the original content training image I c and the original style training image I c Input to the style transfer network, using the stylized image I cc With the original content training image I c Calculate the content loss L c , attention loss L attn ; Use stylized image I cs With the original style training image I s Calculate the style loss L s ; Put two identical content images I c Generating both content and style images I cc , put two same style images I s Generating both content and style images I ss , use I cc , I c , I ss and I s Calculate the identity loss L id .

[0065] 2. About the attention loss function ( Figure 3 Shown Network structure ):

[0066] An attention loss is designed in the loss function to minimize the attention difference between the generated image and the content image. The attention loss takes into account the fact that the significant information in the content may be distorted, retains the significant features of the original content image, and helps to make the visual effect of the generated image better. Figure 4 The following figure shows the comparison of the results when attention loss is used or not. Specifically, the network structure and algorithm are as follows:

[0067] The unary content attention module models salient boundaries. The content feature map from the encoder Normalized and input into two convolutional layers to obtain new feature maps and At the same time, the unnormalized Input to another convolutional layer to obtain feature maps Unary Content Attention Map The formula is as follows:

[0068]

[0069] Where expand(·) indicates the enlarged size, represents matrix multiplication, μ(·) represents the mean of the feature. Then we get the enhanced content feature

[0070]

[0071] The pairwise style attention module learns the pixel relationships within the same category region in the style image. The style feature map from the encoder Normalized and input into two convolutional layers to obtain new feature maps and Then subtract the mean from them; Send it to another convolutional layer to get the feature map Paired Style Attention Map The formula is as follows:

[0072]

[0073] Then we get the enhanced style features

[0074]

[0075] After obtaining the enhanced content and style features, the attention fusion module appropriately integrates the content and style features. and style features Normalize to get and Then and Send it to three convolutional layers to generate three new feature maps and Correlation graph The formula is as follows:

[0076]

[0077] In the formula Mapping enhanced content features and enhanced style features The corresponding relationship between them; then, the stylized feature map of each layer (Relu_4_1 layer and Relu_5_1 layer) is calculated as follows:

[0078]

[0079] Then, the final stylized feature map is obtained:

[0080]

[0081] The technical solution of the present invention is further described below in conjunction with the accompanying drawings. The described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.

[0082] Figure 1 The flowchart shown:

[0083] Step 1: Use MS-COCO as the content image training set and WikiArt as the style image training set, scale the smaller dimension of the image to 512 pixels, and randomly crop a 256*256 pixel area. The content dataset used in the experiment is from the public image dataset MS-COCO, and the style dataset is from the public art image dataset WikiArt. Both datasets contain about 80,000 training images.

[0084] Step 2: Construct a style transfer network, including an encoder, a multi-attention module, and a decoder. The network structure is as follows: Figure 2 The encoder and symmetric decoder use the pre-trained VGG-19 network to transform the content image I c and style image I s As input, extract their respective feature maps and (i is the number of a certain layer); In order to consider both the overall style distribution and the local style, the features of two layers (Relu_4_1 layer and Relu_5_1 layer) are extracted in the encoder, and the results after passing through the multi-attention module are combined to obtain F cs , input it into the symmetric decoder to obtain the stylized image I cs =D(F cs).

[0085] The multi-attention module consists of three parts: a unary content attention module, a paired style attention module, and an attention fusion module. The network structure of each module is as follows Figure 3 Shown .

[0086] The unary content attention module models salient boundaries. The content feature map from the encoder Normalized and input into two convolutional layers to obtain new feature maps and At the same time, the unnormalized Input to another convolutional layer to obtain feature maps Unary Content Attention Map The formula is as follows:

[0087]

[0088] Where expand(·) indicates the enlarged size, represents matrix multiplication, μ(·) represents the mean of the feature. Then we get the enhanced content feature

[0089]

[0090] The pairwise style attention module learns the pixel relationships within the same category region in the style image. The style feature map from the encoder Normalized and input into two convolutional layers to obtain new feature maps and Then subtract the mean from them; Send it to another convolutional layer to get the feature map Paired Style Attention Map The formula is as follows:

[0091]

[0092] Then we get the enhanced style features

[0093]

[0094] After obtaining the enhanced content and style features, the attention fusion module appropriately integrates the content and style features. and style features Normalize to get and Then and Send it to three convolutional layers to generate three new feature maps and Correlation graph The formula is as follows:

[0095]

[0096] In the formula Mapping enhanced content features and enhanced style features The corresponding relationship between them; then, the stylized feature map of each layer (Relu_4_1 layer and Relu_5_1 layer) is calculated as follows:

[0097]

[0098] Then, the final stylized feature map is obtained:

[0099]

[0100] Step 3: Input the paired content training images and style training images into the style transfer network to obtain the generated images. The batch size is set to 5.

[0101] Step 4: Input the generated image obtained in step 3, the original content training image, and the original style training image into the style transfer network, calculate the content loss, attention loss, style loss, and identity loss, and get the total loss;

[0102] Content loss L c It is used to make the generated image close to the content image in terms of content. The calculation formula is as follows:

[0103]

[0104] Where φ i (·) represents the feature map extracted from the i-th layer in the encoder;

[0105] Attention loss L attn It is used to minimize the attention difference between the generated image and the content image, which is calculated as follows:

[0106]

[0107] In the formula represents the attention map obtained by feeding the features extracted by the i-th layer in the encoder into the content attention module;

[0108] Style loss L s It is used to make the generated image close to the style image in style. The calculation formula is as follows:

[0109]

[0110] Where σ(`) represents the variance of the feature;

[0111] Identity loss L id Considering the global statistics and the local mapping relationship between content and style features, the calculation formula is as follows:

[0112]

[0113] Where I cc (I ss ) means that two identical content (style) images are simultaneously used as the result of generating content and style images; id1 and λ id2 The weights representing identity loss are set to 50 and 1 respectively; the total loss function formula is as follows:

[0114] L=λ c L c +λ attn L attn +λ s L s +L id

[0115] Where λ c ,λ attn and λ s are weight parameters, which are set to 3, 5 and 3 respectively in this example.

[0116] Step 5: According to the total loss obtained in step 4, the style transfer network model is optimized using the Adam optimizer, and the learning rate is set to 0.0001.

[0117] Step 6: Loop through steps 3 to 5 until the style transfer network converges and save the trained model file.

[0118] Step 7: Input a set of paired content images and style images into the style transfer model obtained in step 6 to obtain the generated stylized image.

[0119] The above-mentioned arbitrary style transfer implementation method based on multi-attention network proposes an attention loss function. For this purpose, this implementation method also conducts additional comparative experiments, which are the test results obtained without and with attention loss during training, such as Figure 4 As shown, the experimental results show that the attention loss makes the content structure clearer. This implementation method also conducts additional comparative experiments with the closest prior art. Figure 5 The content and style loss comparison results of 360 stylized images generated by the implementation method of the present invention and the prior art on 18 content images and 20 style images are shown in Figure 2. The experimental results show that the content and style loss of the implementation method of the present invention is the lowest in this test data. Figure 6As shown: A comparison chart of the style transfer results of 8 content-style image pairs using the implementation method and the prior art. The experimental results show that the implementation method can effectively retain the significant structure of the content and the detailed texture of the style, and obtain a higher quality stylized image.

Claims

1. A method for arbitrary style transfer based on multi-attention network, characterized in that: The steps include: Step 1: Use MS-COCO as the content image training set and WikiArt as the style image training set; Step 2: Construct a style transfer network, including an encoder, a multi-attention module, and a decoder. The encoder and the decoder are symmetrical and both use a pre-trained VGG-19 network. Step 3: Input the paired content training image and style training image into the style transfer network to obtain the generated image; Step 4: Input the generated image obtained in step 3, the original content training image, and the original style training image into the style transfer network, calculate the content loss, attention loss, style loss, and identity loss, and get the total loss; Step 5: According to the total loss obtained in step 4, the style transfer network model is optimized using the Adam optimizer; Step 6: Loop through steps 3 to 5 until the style transfer network converges and save the trained model file. Step 7: Input a set of paired content images and style images into the style transfer model obtained in step 6 to obtain the generated stylized image; Step 2: For the encoder, the content image I c and style image I s As input, extract their respective feature maps and i is the number of a certain layer; in order to consider both the overall style distribution and the local style, the features of the Relu_4_1 layer and the Relu_5_1 layer are extracted in the encoder, and the results after passing through the multi-attention module are combined to obtain F cs , input it into the symmetric decoder to obtain the stylized image I cs =D(F cs ); The multi-attention module consists of three parts: a unary content attention module, a paired style attention module, and an attention fusion module; The unary content attention module models salient boundaries; the content feature map from the encoder Normalized and input into two convolutional layers to obtain new feature maps and At the same time, the unnormalized Input to another convolutional layer to obtain feature maps Unary Content Attention Map The formula is as follows: Where expand(·) indicates the enlarged size, represents matrix multiplication, μ(·) represents the mean of the feature; Then we get the enhanced content features The paired style attention module learns the pixel relationships in the same category region in the style image; the style feature map from the encoder Normalized and input into two convolutional layers to obtain new feature maps and Then subtract the mean from them; Send it to another convolutional layer to get the feature map Paired Style Attention Map The formula is as follows: Then we get the enhanced style features After obtaining the enhanced content and style features, the attention fusion module appropriately integrates the content and style features; Enhanced content features and style features Normalize to get and Then and Send it to three convolutional layers to generate three new feature maps and Correlation graph The formula is as follows: In the formula Mapping enhanced content features and enhanced style features The corresponding relationship between them; then, the stylized feature maps of each layer of Relu_4_1 layer and Relu_5_1 layer are calculated as follows: Then, the final stylized feature map is obtained: Step 4: Content loss L c It is used to make the generated image close to the content image in terms of content. The calculation formula is as follows: Where φ i (·) represents the feature map extracted from the i-th layer in the encoder; Attention loss L attm It is used to minimize the attention difference between the generated image and the content image, which is calculated as follows: In the formula represents the attention map obtained by feeding the features extracted by the i-th layer in the encoder into the content attention module; Style loss L s It is used to make the generated image close to the style image in style. The calculation formula is as follows: Where σ(·) represents the variance of the feature; Identity loss L id Considering the global statistics and the local mapping relationship between content and style features, the calculation formula is as follows: Where I cc and I ss Indicates that two identical content and style images are simultaneously used as the result of generating content and style images; id1 and λ id2 The weight representing the identity loss can be set by the user according to his / her needs; the total loss function formula is as follows: L=λ c L c +λ attn L attn +λ s L s +L id Where λ c ,λ attn and λ s It is a weight parameter, which can be set by the user according to needs.