Image style migration method based on residual network
Through the image style transfer method based on the residual network, VGG is used for feature extraction and fusion, and the Laplacian operator is used for loss calculation, which solves the problem of long time for large-size image style transfer in the existing technology and achieves fast and High-quality style transfer effects.
Patent Information
- Application Number
- CN202410724506.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-09-10
AI Technical Summary
Existing image style transfer methods based on neural networks take a long time to process large-size images, resulting in a slow style transfer process.
An image style transfer method based on residual network is adopted. By constructing content image and style image data sets, the convolutional neural network VGG is used for feature extraction and fusion, and the Laplacian operator is introduced for loss calculation, combining content loss and style loss. and Laplacian loss, utilizing an optimizer to update the decoder parameters to generate style transfer images.
It achieves rapid image style transfer while maintaining good image quality while significantly reducing the generation time. The style transfer training process is faster, the image effect is better, and the structural details are better controlled.
Smart Images

Figure CN118628336A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to an image style transfer method based on a residual network. Background Art
[0002] Image style transfer is the combination of different images and is widely used in artistic creation. Gatys et al. pioneered the use of deep neural networks to extract features from images and used the Gram matrix for loss measurement, effectively transferring style and introducing style transfer into the era of neural style transfer. It is now developing in the fields of video stylization, font conversion, portrait change, artistic creation, image enhancement, etc.
[0003] The style transfer method based on neural network not only includes obtaining high-quality style transfer images, but also includes improving the speed of image generation. In the prior art, the image iteration method represented by Gatys et al. is an extremely excellent style transfer method, which has the advantages of wide application range, large adjustment range, and the ability to combine multiple images. It can be applied to a large range of image style transfer, but a great disadvantage of the image iteration method for style transfer is that the running time is long, which is not conducive to fast style transfer. Among them, the image block matching method for style transfer takes longer time, and the disadvantage is more obvious in the style transfer of large-size images. Summary of the invention
[0004] The purpose of the present invention is to overcome the above-mentioned shortcomings and propose an image style transfer method based on a residual network, which can effectively avoid the time limitations of the slow generation method and obtain good image quality in the fast image style transfer.
[0005] The present invention provides an image style transfer method based on a residual network, the method specifically comprising the following steps:
[0006] Step 1: Image dataset construction: First, the content image dataset and style image dataset are constructed, in which the image is corrected to reduce the distortion of the original image, and then the image data is cropped to reduce the distortion of the scaled image caused by the large aspect ratio during the input process, and the dataset is expanded at the same time;
[0007] Step 2: Image input: Input the content image and style image to be optimized, and unify the tensor shapes of all input images;
[0008] Step 3: Encoder construction: The encoder is constructed using the convolutional neural network VGG. It extracts features by reducing the height and width by several times. It extracts features from the content image and style image respectively to form feature maps of the content image and style image.
[0009] Step 4: Feature fusion: Perform feature fusion calculation on the content image feature map and the style image feature map. After fusion, hyperparameters can be controlled in actual use.
[0010] Step 5, decoder construction: The structure of the decoder is established corresponding to the encoder to form a mirror relationship. The feature maps after feature fusion are used to reconstruct the image respectively, so that the reconstructed image is consistent with the input image shape, in preparation for loss calculation;
[0011] Step 6, loss calculation: The generated image is again extracted using the convolutional neural network VGG19 as the feature extraction network to form a feature map, define the loss function, and calculate the loss of the feature map;
[0012] The loss function L total Defined as:
[0013]
[0014] in, represents the computational content loss, Indicates that the content loss is calculated in the i-th layer of the feature extraction network, and α is the content loss weight parameter;
[0015] represents the calculation style loss, Indicates that the style loss is calculated at the jth layer of the feature extraction network, and β is the local loss weight parameter;
[0016] Indicates the calculation of Laplacian matrix loss, Indicates that the Laplace loss is calculated at the kth layer of the feature extraction network, and γ is the Laplace matrix weight parameter;
[0017] The content loss Defined as:
[0018]
[0019] Among them, F x Represents the feature map obtained by the feature extraction network of the reconstructed image, that is, the generated style transfer feature map, F x_c It represents the content feature map obtained by the feature extraction network of the content image. The two have the same shape and the corresponding shape size is [b,c,h,w], where b represents the batch data of the input image, c represents the number of channels, and h and w represent the height and width of the feature map;
[0020] The style loss Defined as:
[0021]
[0022] Among them, std(F x )、std(F x_s ) represent the variance of the obtained style migration feature map and content feature map, mean(F x )、mean(F x_s ) represent the means of the obtained style feature map and content feature map respectively, and n and m are the corresponding weight parameters;
[0023] The Laplace loss: In order to perform corresponding structural control on the details of the style transfer image, the Laplace operator is introduced for loss calculation to better preserve the structural integrity of the acquired style transfer image. In the process of calculating the Laplace loss, the feature map of the style transfer image and the feature map of the content image are first obtained, and then the Laplace operator is used to perform convolution calculation on the feature map, and the edge filling is performed to keep the height and width of the acquired Laplace matrix unchanged. The Laplace loss is calculated using formula (5):
[0024] lap_f = [[0,-1,0],[-1,4,-1],[0,-1,0]] (4)
[0025]
[0026] in Indicates the calculation of image Laplace loss, lap(F x ,lap_f) represents the style transfer feature map F x Use the operator lap_f to perform convolution processing to obtain the Laplacian matrix of the feature map; lap(F x_c ,lap_f) represents the content feature map F x_c Use the operator lap_f to perform convolution processing to obtain the Laplacian matrix of the content feature map.
[0027] Step 7, image reconstruction: The total loss is obtained by merging the content loss, style loss, and Laplace loss. The loss is derived and updated through the optimizer to update the parameters of the decoder, and the network forward reasoning is used to obtain the corresponding final style transfer image.
[0028] The above-mentioned image style transfer method based on residual network, wherein: in step 1, the image dataset is constructed, and a batik content image dataset and an embroidery style image dataset are established respectively.
[0029] The above-mentioned image style transfer method based on residual network, wherein: in step 2, the shape of the tensor is unified as [b,3,h i ,w i ], b represents the batch size of the input image, 3 represents the channel of the image, and h i,w i Represents the scaled height and width of the i-th input image.
[0030] The above-mentioned image style transfer method based on residual network, wherein: in step 3, the encoder is constructed using the convolutional neural network VGG19, and feature extraction is performed by reducing the height and width by 4 times.
[0031] The above-mentioned image style transfer method based on residual network, wherein: in step 4, the fusion calculation uses a fusion method consistent with multi-scale transform MST.
[0032] The above-mentioned image style transfer method based on residual network, wherein: in step 7, the optimizer is the optimizer L_BFGS.
[0033] Compared with the prior art, the present invention has obvious beneficial effects. It can be seen from the above scheme that first, the corresponding content and style image data sets are constructed, and batch content images and style images are input; then, the encoder is used to extract the corresponding feature maps of the content graphics and style images, and the corresponding extracted content feature maps and style feature maps are used to perform corresponding feature fusion, and the features of the two are combined, and the input features are consistent with the input features; the fused feature maps are input into the decoder for image reconstruction to obtain the corresponding style transfer image. The VGG19 network is used to extract the feature map, and the content loss, style loss, Laplace loss, etc. are calculated according to the obtained feature map. After that, the loss is derived and updated by the optimizer to update the network model parameters of the decoder, and the final decoder model parameters are obtained, and then the style transfer image is obtained by forward reasoning. The invention is a method for image style transfer using a feedforward neural network, in which the mean and variance are used to measure the loss in the style loss calculation, and the Laplace operator is introduced for structural refinement to better retain the structural integrity of the style transfer image. In addition, the VGG19 network is used to calculate the loss of the reconstructed image, the content loss is measured using the Euclidean distance, and the style loss function uses the mean and variance for corresponding measurements, making the image migration process faster.
[0034] In summary, the main advantages of the present invention are:
[0035] 1. Using the mean as the style loss measurement can be faster than using Gram for loss measurement, achieving faster style transfer training and making the effect more significant.
[0036] 2. Using the Laplace operator to perform corresponding structural enhancement can make the resulting image more effective
[0037] The beneficial effects of the present invention are further illustrated below through specific implementation modes. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0039] In combination with the accompanying drawings and preferred embodiments, the specific implementation methods, features and effects of an image style transfer method based on a residual network proposed in the present invention are described in detail as follows.
[0040] See also Figure 1 The present invention provides an image style transfer method based on a residual network, the method specifically comprising the following steps:
[0041] Step 1: Image dataset construction: First, the content image dataset and style image dataset are constructed, in which the image is corrected to reduce the distortion of the original image. Then the image data is cropped to reduce the image distortion caused by the large aspect ratio during the input process, and the dataset is also expanded.
[0042] The image data is constructed to respectively establish a batik content image dataset and an embroidery style image dataset.
[0043] Step 2: Image input: Input the content image, style image, content image mask, and style image mask to be optimized, and unify the tensor shapes of all input images;
[0044] During the input process, all input images are unified into a tensor shape of [b,3,h i ,w i ], b represents the batch size of the input image, 3 represents the channel of the image, and h i ,w i Represents the scaled height and width of the i-th input image;
[0045] Step 3: Encoder construction: The encoder is constructed using the convolutional neural network VGG19. The feature extraction is performed by reducing the height and width by 4 times. The feature extraction is performed on the content image and the style image respectively to form the feature graphs of the content image and the style image. The encoder parameters are frozen and the encoder parameters are not updated.
[0046] Step 4, feature fusion: perform feature fusion calculation on the content image feature map and the style image feature map, using a fusion method consistent with multi-scale transform MST. After fusion, hyperparameters can be controlled in actual use, and different images can be used for fusion to achieve arbitrary style transfer.
[0047] Step 5, decoder construction: The structure of the decoder is established corresponding to the encoder to form a mirror relationship. The feature map after feature fusion is input into the decoder for image reconstruction, so that the reconstructed image is consistent with the input image shape, in preparation for loss calculation;
[0048] The network model of the encoder and decoder includes a convolution layer, a pooling layer, and a residual module. The convolution layer and the pooling layer are used to extract image features and obtain feature maps. In the decoder, the network model is constructed by inserting residual blocks and the image is reconstructed and restored.
[0049] Step 6, loss calculation: The generated image is again extracted using the convolutional neural network VGG19 as the feature extraction network to form a feature map, define the loss function, and calculate the loss of the feature map;
[0050] The loss function L total Defined as:
[0051]
[0052] in, represents the computational content loss, Indicates that the content loss is calculated in the i-th layer of the feature extraction network, and α is the content loss weight parameter;
[0053] represents the calculation style loss, Indicates that the style loss is calculated at the jth layer of the feature extraction network, and β is the local loss weight parameter;
[0054] Indicates the calculation of Laplacian matrix loss, Indicates that the Laplace loss is calculated at the kth layer of the feature extraction network, and γ is the Laplace matrix weight parameter;
[0055] The content loss Defined as:
[0056]
[0057] Among them, F x Represents the feature map obtained by the feature extraction network of the reconstructed image, that is, the generated style transfer feature map, F x_c It represents the content feature map obtained by the feature extraction network of the content image. The two have the same shape and the corresponding shape size is [b,c,h,w], where b represents the batch data of the input image, c represents the number of channels, and h and w represent the height and width of the feature map;
[0058] The style loss Defined as:
[0059]
[0060] Among them, std(F x )、std(F x_s ) represent the variance of the obtained style migration feature map and content feature map, mean(F x )、mean(F x_s ) represent the means of the obtained style feature map and content feature map respectively, and n and m are the corresponding weight parameters;
[0061] The Laplace loss: In order to perform corresponding structural control on the details of the style transfer image, the Laplace operator is introduced for loss calculation to better preserve the structural integrity of the acquired style transfer image. In the process of calculating the Laplace loss, the feature map of the style transfer image and the feature map of the content image are first obtained, and then the Laplace operator is used to perform convolution calculation on the feature map, and the edge filling is performed to keep the height and width of the acquired Laplace matrix unchanged. The Laplace loss is calculated using formula (5):
[0062] lap_f = [[0,-1,0],[-1,4,-1],[0,-1,0]] (4)
[0063]
[0064] in Indicates the calculation of image Laplace loss, lap(F x ,lap_f) represents the style transfer feature map F x Use the operator lap_f to perform convolution processing to obtain the Laplacian matrix of the feature map; lap(F x_c ,lap_f) represents the content feature map F x_c Use the operator lap_f to perform convolution processing to obtain the Laplacian matrix of the content feature map.
[0065] Step 7, image reconstruction: Based on the total loss obtained by combining the content loss, style loss, and Laplace loss, the optimizer is used to derive and update the loss, thereby updating the decoder parameters, and using network forward reasoning to obtain the corresponding final style transfer image. In the optimization process, the optimizer L_BFGS is used for optimization processing to obtain the final model parameters.
[0066] In summary, the method of the present invention uses a residual network to train a feedforward network on batik and embroidery datasets, which can effectively reduce the network training degradation problem. At the same time, the mean and variance are used to measure the style loss, which can make the style transfer training process faster and the transfer effect better. At the same time, the Laplace operator is used to enhance the structural constraints; the final style transfer image effect is better, the structural distortion is less, and it is conducive to the control of structural details.
[0067] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Any simple modification, equivalent change and modification made to the above embodiment according to the technical essence of the present invention without departing from the technical solution of the present invention still falls within the scope of the technical solution of the present invention.
Claims
1. An image style transfer method based on residual network, Features: The specific steps of the method include: Step 1: Image dataset construction: First, the content image dataset and style image dataset are constructed, in which the image is corrected to reduce the distortion of the original image, and then the image data is cropped to reduce the distortion of the scaled image caused by the large aspect ratio during the input process, and the dataset is expanded at the same time; Step 2: Image input: Input the content image and style image to be optimized, and unify the tensor shapes of all input images; Step 3: Encoder construction: The encoder is constructed using the convolutional neural network VGG. It extracts features by reducing the height and width by several times. It extracts features from the content image and style image respectively to form feature maps of the content image and style image. Step 4: Feature fusion: Perform feature fusion calculation on the content image feature map and the style image feature map. After fusion, hyperparameters can be controlled in actual use. Step 5, decoder construction: The structure of the decoder is established corresponding to the encoder to form a mirror relationship. The feature maps after feature fusion are used to reconstruct the image respectively, so that the reconstructed image is consistent with the input image shape, in preparation for loss calculation; Step 6, loss calculation: The generated image is again extracted using the convolutional neural network VGG19 as the feature extraction network to form a feature map, define the loss function, and calculate the loss of the feature map; The loss function L total Defined as: in, represents the computational content loss, Indicates that the content loss is calculated in the i-th layer of the feature extraction network, and α is the content loss weight parameter; represents the calculation style loss, Indicates that the style loss is calculated at the jth layer of the feature extraction network, and β is the local loss weight parameter; Indicates the calculation of Laplacian matrix loss, Indicates that the Laplace loss is calculated at the kth layer of the feature extraction network, and γ is the Laplace matrix weight parameter; The content loss Defined as: Among them, F x Represents the feature map obtained by the feature extraction network of the reconstructed image, that is, the generated style transfer feature map, F x_c It represents the content feature map obtained by the feature extraction network of the content image. The two have the same shape and the corresponding shape size is [b,c,h,w], where b represents the batch data of the input image, c represents the number of channels, and h and w represent the height and width of the feature map; The style loss Defined as: Among them, std(F x )、std(F x_s ) represent the variance of the obtained style migration feature map and content feature map, mean(F x )、mean(F x_s ) represent the means of the obtained style feature map and content feature map respectively, and n and m are the corresponding weight parameters; The Laplace loss: In order to perform corresponding structural control on the details of the style transfer image, the Laplace operator is introduced for loss calculation to better preserve the structural integrity of the acquired style transfer image. In the process of calculating the Laplace loss, the feature map of the style transfer image and the feature map of the content image are first obtained, and then the Laplace operator is used to perform convolution calculation on the feature map, and the edge filling is performed to keep the height and width of the acquired Laplace matrix unchanged. The Laplace loss is calculated using formula (5): lap_f = [[0,-1,0],[-1,4,-1],[0,-1,0]] (4) in Indicates the calculation of image Laplace loss, lap(F x ,lap_f) represents the style transfer feature map F x Use the operator lap_f to perform convolution processing to obtain the Laplacian matrix of the feature map; lap(F x_c ,lap_f) represents the content feature map F x_c Use the operator lap_f to perform convolution processing to obtain the Laplacian matrix of the content feature map; Step 7, image reconstruction: The total loss is obtained by merging the content loss, style loss, and Laplace loss. The loss is derived and updated through the optimizer to update the parameters of the decoder, and the network forward reasoning is used to obtain the corresponding final style transfer image.
2. The image style transfer method based on residual network according to claim 1, Features: In step 1, the image dataset is constructed, and a batik content image dataset and an embroidery style image dataset are respectively established.
3. The image style transfer method based on residual network as claimed in claim 1, Features: In step 2, the tensor shape is unified to [b,3,h i ,w i ], b represents the batch size of the input image, 3 represents the channel of the image, and h i ,w i Represents the scaled height and width of the i-th input image.
4. The image style transfer method based on residual network according to claim 1, Features: In step 3, the encoder is constructed using the convolutional neural network VGG19, and feature extraction is performed by reducing the height and width by 4 times.
5. The image style transfer method based on residual network according to claim 1, Features: In step 4, the fusion calculation uses a fusion method consistent with multi-scale transform MST.
6. An image style transfer method based on a residual network according to any one of claims 1 to 5, Features: In step 7, the optimizer is the optimizer L_BFGS.
Citation Information
Cited By
A method for generating editable conditional printing images
CN119227549B
Progressive multi-branch video style migration method based on confidence weighted loss
CN119295294A
Embroidery-imitating style generation method of printed pattern
CN120219147A
