Multi-style image cartoonalization method based on style condition information
By introducing style condition information and multi-style learning discriminators into image cartoonization, and combining multiple loss functions to optimize the generated adversarial network, the problems of model training complexity and resource waste in the existing multi-style cartoonization methods are solved, and high efficiency is achieved. , Multi-style image cartoonization.
Patent Information
- Application Number
- CN202410822459.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-10-11
AI Technical Summary
Existing multi-style image cartoonization methods require training multiple models separately, resulting in a waste of time and computing resources, and increasing the instability of the generative adversarial network.
Design a multi-style image cartoonization method based on style condition information. By constructing a condition generator and a multi-style learning discriminator, the style condition information is embedded in the feature space, and combined with conditional contrast loss, adversarial loss, content loss, color reconstruction loss and Style loss, optimizes the generated adversarial network model, and realizes single model multi-style conversion.
It simplifies the generation process of different styles of images, significantly improves efficiency, achieves high-quality multi-style cartoon effects, and reduces the complexity of model training.
Smart Images

Figure CN118761901A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to a multi-style image cartoonization method based on style condition information. Background Art
[0002] With the continuous development of human entertainment, computer vision is no longer limited to traditional image recognition and image enhancement, and has begun to involve more artistic visual expressions. It is precisely because of people's pursuit of artistic vision that the innovation and diversity of cartoon image design have been promoted. The craze of anime videos, stickers and emoticons on social software, and filter effects in image beautification software are all examples of the widespread application of cartoon image design. These designs not only make images more interesting, but also provide users with a richer visual experience.
[0003] Cartoonization has made great progress, but existing methods still have some shortcomings. First, most existing cartoonization methods can only cartoonize a single style. If you want to cartoonize multiple styles, you must train them separately and build multiple models, which takes more time and computing resources. Second, existing multi-style cartoonization methods distinguish different styles by adding multiple discriminators and classifiers, which also increases the instability of generative adversarial network training. Summary of the invention
[0004] In order to solve the problems of multiple training of a single style model and the complexity of multi-style models in multi-style cartoonization work, the present invention proposes a multi-style image cartoonization method based on style condition information, which is used to realize the conversion of a single model to multiple styles and improve the quality of the generated image. The training sets of the source domain and the target domain are obtained; two key components for promoting multi-style image cartoonization are included, namely, a conditional generator and a multi-style learning discriminator are designed respectively, and the style condition information is embedded in the feature space to improve the model's ability to achieve different cartoon styles; a loss function is constructed; the parameters of the generative adversarial network model are adjusted using each loss value, the generator and discriminator networks are optimized, and the entire generative adversarial network model is iterated for multiple rounds to obtain a trained multi-style cartoonization generative network; the natural image to be processed is input into the trained multi-style cartoonization generative network to obtain cartoon images of different styles; the present invention only needs to train the model once, which simplifies the generation process of images of different styles and significantly improves efficiency.
[0005] The technical solution of the present invention is achieved in this way:
[0006] A multi-style image cartoonization method based on style condition information, the steps are as follows:
[0007] Step 1: Obtain training sets of source domain and target domain;
[0008] Step 2: Construct a multi-style image cartoonization generative adversarial network based on style condition information;
[0009] Step 3: Construct a loss function and introduce conditional contrast loss to promote cartoon generation of different styles. Combine conditional contrast loss, adversarial loss, content loss, color reconstruction loss, and style loss to construct the total network loss.
[0010] Step 4: using each loss value to adjust the parameters of the generative adversarial network model, and iterating the entire generative adversarial network model for multiple rounds to obtain a trained cartoon image generative network;
[0011] Step 5: Input the natural image to be processed into the trained multi-style cartoon image generation network to obtain cartoon images of different styles.
[0012] Preferably, the implementation steps of constructing a multi-style image cartoonization generative adversarial network based on style condition information in step 2 are:
[0013] S21: Construct a generative network, which consists of 1 2D convolution layer, 2 downsampling layers, 4 conditional information residual blocks, 2 upsampling layers and 1 convolution block. The downsampling layer contains 2D convolution and LReLU nonlinear activation layer, the upsampling layer contains 2D convolution, LReLU nonlinear activation layer and bilinear interpolation layer, the convolution block contains 2D convolution and LReLU nonlinear activation layer, and the 4 conditional information residual blocks contain 2D reflection padding, 2D convolution and conditional instance normalization. In addition, skip connection is used to strengthen the feature conduction of the whole network, and the generated image is obtained by inputting source domain data.
[0014] Preferably, the specific implementation steps of the generative network in step S21 are:
[0015] S211: Use a 7×7 two-dimensional convolutional layer to extract features from the input image;
[0016] S212: The extracted feature map is used as input, and features are downsampled and extracted through two consecutive downsampling layers. The first downsampling layer converts the feature map of 32 input channels into the feature map of 64 output channels, and the second downsampling layer converts the feature map of 64 input channels into the feature map of 128 output channels.
[0017] S213: Input the down-sampling result into four conditional information residual blocks to obtain an output feature map;
[0018] S214: input the feature map into the upsampling layer, restore the feature map, and use bilinear interpolation in the upsampling process to avoid chessboard artifacts;
[0019] S215: Input the feature map into the convolution block to obtain the generated image. The convolution block first further processes and extracts features from the feature map through a 3×3 sized 2D convolution layer and a 7×7 sized 2D convolution layer. After each convolution layer, an LReLU nonlinear activation layer is applied to enhance the expressiveness of the model. In addition, in order to enhance the feature conduction of the entire network, the skip connection technology is used to fuse the feature information with the output of the convolution block. After these fine convolution and feature fusion processes, the desired image is finally generated.
[0020] Preferably, the specific implementation steps of the conditional information residual block in step S213 are:
[0021] S2131: using a two-dimensional reflection filling method on a branch to copy the edge of the feature image obtained after upsampling to ensure that the input and output sizes are consistent;
[0022] S2132: Use a 3×3 convolutional layer to perform convolution operations on the features with a step size of 1 to extract and transform the input features;
[0023] S2133: Input the result of S2132 convolution and the class label into the conditional instance normalization, which can learn a different set of parameters for each style: α and β. Different style categories have different learned parameters. The specific method is:
[0024] The result after S2132 convolution is instance normalized, and the input class label is encoded to obtain two different parameters α and β.
[0025]
[0026] r represents the input image, is the input feature activation, s represents the index in a set of style images, and the feature statistics are normalized using different series of parameters to normalize the input content image into different styles;
[0027] S2134: repeat steps S2131-S2133 to obtain a result of a branch of the conditional information residual block;
[0028] S2135: A 1×1 convolutional layer is used on the other branch to integrate global information in the channel dimension;
[0029] S2136: Add the results of the two branches to fully utilize the image feature information;
[0030] S22: construct a multi-style learning discriminator network, which constitutes the entire adversarial network with the generative network. The discriminator network consists of 7 convolution blocks, 1 Sn_linear layer (consisting of 1 Linear layer and spectral normalization) and 1 Sn_Embedding layer (consisting of 1 Embedding layer and spectral normalization), wherein the convolution block includes a two-dimensional convolution, an LReLU nonlinear activation layer and spectral normalization. The discriminator network adopts a forward propagation operation, receives an input image, and obtains an output result through a series of convolution operations;
[0031] Preferably, the specific implementation steps of the multi-style learning discriminator network in step S22 are:
[0032] S221: The discriminator receives the input image (including the generated image and the cartoon image) and the label. The input image is processed by D φ Network (D φ The network consists of 6 convolutional blocks) to extract features and obtain h;
[0033] S222: The feature h is used as the input of two parts. The first part is input into a convolutional block to calculate the final adversarial loss L adv ; The second part is to use the LReLU activation function to perform a nonlinear transformation on the extracted feature h and sum it in the second and third dimensions to produce a global feature vector;
[0034] S223: Use the Sn_linear layer to map the global feature vector of the second part of S222 into a high-dimensional embedding vector V embed , and use the Sn_Embedding layer to map the input label to a high-dimensional proxy vector V proxy ;
[0035] S224: embedding vector V embed and the proxy vector V proxy Use normalization to improve training stability;
[0036] S225: The conditional contrast loss is calculated through the normalized results and labels to measure the similarity between images. The conditional contrast loss uses the cosine similarity matrix and masking technology to obtain the similarity measure, and then adjusts the similarity measure to maximize the similarity of images with the same style and minimize the similarity of images with different styles, making it more distinguishable and discriminative, which helps to enhance the differences between styles, strengthen the learning of style features, and promote cartoonization of different styles.
[0037] Preferably, in the step 3, a loss function is constructed, and conditional contrast loss is introduced to promote cartoon generation of different styles. The content loss, color reconstruction loss, adversarial loss, style loss, and conditional contrast loss are combined to construct the total network loss. The implementation method is:
[0038] The pre-trained VGG19 is used as the perception network to extract the high-level semantic features of the image. The content loss is the loss of the input image and the image generated in step 2, which ensures the content consistency between the two. The content loss formula is: Where L con is the content loss, l is a specific VGG layer, represents a set of natural images, represents the image set generated in step 2, i represents the i-th natural image;
[0039] The color reconstruction loss in AnimeGAN is used to convert the color of the image from RGB format to YUV format. In this loss, L1 loss is used for the Y channel and Huber loss is used for the U and V channels. The purpose is to make the color reconstruction of the image better. The color reconstruction loss can be expressed as:
[0040] Among them, Y(·), U(·), and V(·) represent the three channels of the image respectively;
[0041] The adversarial loss function is: in, represents a cartoon image set, c i represents the i-th cartoon image, represents the image set generated in step 2, f i represents the image generated by the i-th step 2;
[0042] Style loss: Because the texture of the cartoon image is transferred to the content image instead of the color, the grayscale Gram matrix is used to make the generated image have the texture of the cartoon image. Therefore, the input image is first converted to a grayscale image to eliminate color interference:
[0043] g_c i = rgb2gray(c i )
[0044] g_f i = rgb2gray(f i )
[0045]
[0046] In the formula, Gram represents the Gram matrix of the feature, f i represents the generated image, c iRepresents a real cartoon image, and rgb2gray represents converting a color image into a grayscale image;
[0047] Preferably, the conditional contrast loss is specifically implemented in the following steps:
[0048] S31: Calculate the embedding vector V obtained in S224 embed The cosine similarity matrix of ;
[0049] S32: Create a mask with diagonal zeros and use this mask to remove the diagonal elements and return a flattened matrix;
[0050] S33: Use the mask of S32 to remove the elements on the diagonal of the cosine similarity matrix of S31, and then divide it by the parameter that adjusts the median value of the similarity matrix (set parameter t=1) to perform exponential processing on the similarity matrix;
[0051] S34: Create a negative sample rejection mask, which accepts the label as input and returns a mask in which the positions of negative samples are set to 0 and the positions of positive samples are set to 1;
[0052] S35: using the negative sample removal mask matrix in S34 on the result obtained in S33, and only retaining the cosine similarity matrix of the positive sample similarity;
[0053] S36: Calculate the embedding vector V obtained in S224 embed To the proxy vector V proxy The cosine similarity is divided by the parameter that adjusts the median value of the similarity matrix and then exponentially processed;
[0054] S37: Calculate the numerator of the loss function by summing the similarity between the embedded vector and the proxy vector and the similarity containing only positive samples;
[0055] S38: Construct the denominator of the loss function, merge the similarity from the embedding vector to the proxy vector with the complete similarity matrix, and then sum each row;
[0056] S39: Calculate the loss function, take the negative average of the logarithm of the ratio of the numerator to the denominator as the loss value, and learn a more discriminative embedding representation by maximizing the similarity of images with the same style and minimizing the similarity of images with different styles;
[0057]
[0058] Where: x n (n=1,,a,L,m) represents the input image of the randomly sampled discriminator, y n Indicates its corresponding label, e(y n) means encoding it, p means Sn_linear(D φ (·)), t represents the parameter for adjusting the median value of the similarity matrix (this paper sets parameter t = 1), represents the transpose of the matrix. It explicitly takes into account the image-to-image relationship of the same style (When y a =y n When , we pull images of the same category closer and push images of other styles away. We promote the generation of multi-style cartoon images by minimizing the loss;
[0059] The above five losses are used to jointly constrain the entire network to generate better cartoon images.
[0060] The beneficial effects of the present invention are as follows: the style condition information can be embedded into the feature space through the multi-style conversion model to improve the model's ability to achieve different cartoon styles. At the same time, the conditional contrast loss is used to enhance the differences between different styles, thereby effectively achieving multi-style image cartoonization. The method only needs to train the model once, simplifies the generation process of images of different styles, and significantly improves efficiency. In experimental comparisons with several previous representative methods, the present invention achieves good cartoon stylization effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0062] Figure 1 It is the overall flow chart of the present invention;
[0063] Figure 2 It is the overall architecture diagram of the present invention;
[0064] Figure 3 is a structural diagram of a conditional information residual block according to an embodiment of the present invention;
[0065] Figure 4 It is a partial experimental result diagram of the present invention, wherein, Figure 4 (a) represents the Shinkai style graph generated by the present invention, Figure 4 (b) represents the Hayao style graph generated by the present invention, Figure 4 (c) represents the Hosoda style graph generated by the present invention, Figure 4 (d) represents the DCartoon style image generated by the present invention;
[0066] Figure 5 is a qualitative comparison diagram of the cartoonization method proposed in the present invention and the single-style image cartoonization method, wherein: Figure 5 (a) represents the input graph, Figure 5 (b) represents the image generated by CartoonGAN. Figure 5 (c) represents the image generated by AnimeGANv2, Figure 5 (d) represents the image generated by SDP-GAN, Figure 5 (e) represents the image generated by Learning, Figure 5 (f) represents an image generated by the method of the present invention;
[0067] Figure 6 is a qualitative comparison diagram of the cartoonization method proposed in the present invention and the multi-style image cartoonization method, wherein: Figure 6 (a) represents the input graph, Figure 6 (b) represents the image generated by White-box, Figure 6 (c) represents the image generated by MS-CartoonGAN, Figure 6 (d) represents an image generated by the method of the present invention; DETAILED DESCRIPTION
[0068] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0069] Figure 1 is the overall flow chart of the present invention, Figure 2 This is a general architecture diagram of the multi-style image cartoonization method according to an embodiment of the present invention. As shown in the figure, the specific implementation is as follows:
[0070] Step 1: Obtain training sets of source domain and target domain;
[0071] S11: Collect source domain datasets and select natural image sets as source domains from the training and quantitative test sets of the CycleGAN network;
[0072] S12: Collect the target domain dataset, select three styles of foreign animated films and one style of domestic films, and extract key frames from the films of the same style;
[0073] S13: Perform data preprocessing on the acquired key frame images, that is, crop the dataset images to a size of 256×256, and finally obtain the target domain data.
[0074] Step 2: Construct a multi-style image cartoonization generative adversarial network based on style condition information;
[0075] S21: Construct a generative network, which consists of 1 two-dimensional convolution layer, 2 downsampling layers, 4 conditional information residual blocks, 2 upsampling layers and 1 convolution block. The downsampling layer contains a two-dimensional convolution and an LReLU non-linear activation layer, the upsampling layer contains a two-dimensional convolution, an LReLU non-linear activation layer and a bilinear interpolation layer, the convolution block contains a two-dimensional convolution and an LReLU non-linear activation layer, and the four conditional information residual blocks contain two-dimensional reflection filling, two-dimensional convolution and conditional instance normalization. In addition, jump connections are used to strengthen the feature conduction of the entire network, and the generated image is obtained by inputting the source domain data. The specific steps are as follows:
[0076] S211: Use a 7×7 two-dimensional convolutional layer to extract features from the input image;
[0077] S212: The extracted feature map is used as input, and features are downsampled and extracted through two consecutive downsampling layers. The first downsampling layer converts the feature map of 32 input channels into the feature map of 64 output channels, and the second downsampling layer converts the feature map of 64 input channels into the feature map of 128 output channels.
[0078] S213: Input the down-sampling result into four conditional information residual blocks to obtain an output feature map;
[0079] S214: input the feature map into the upsampling layer, restore the feature map, and use bilinear interpolation in the upsampling process to avoid chessboard artifacts;
[0080] S215: Input the feature map into the convolution block to obtain the generated image. The convolution block first further processes and extracts features from the feature map through a 3×3 sized 2D convolution layer and a 7×7 sized 2D convolution layer. After each convolution layer, an LReLU nonlinear activation layer is applied to enhance the expressiveness of the model. In addition, in order to enhance the feature conduction of the entire network, the skip connection technology is used to fuse the feature information with the output of the convolution block. After these fine convolution and feature fusion processes, the desired image is finally generated.
[0081] Preferably, the specific implementation steps of the conditional information residual block in step S213 are:
[0082] S2131: using a two-dimensional reflection filling method on a branch to copy the edge of the feature image obtained after upsampling to ensure that the input and output sizes are consistent;
[0083] S2132: Use a 3×3 convolutional layer to perform convolution operations on the features with a step size of 1 to extract and transform the input features;
[0084] S2133: Input the result of S2132 convolution and the class label into the conditional instance normalization, which can learn a different set of parameters for each style: α and β. Different style categories have different learned parameters. The specific method is:
[0085] The result after S2132 convolution is instance normalized, and the input class label is encoded to obtain two different parameters α and β.
[0086]
[0087] r represents the input image, is the input feature activation, s represents the index in a set of style images, and the feature statistics are normalized using different series of parameters to normalize the input content image into different styles;
[0088] S2134: repeat steps S2131-S2133 to obtain a result of a branch of the conditional information residual block;
[0089] S2135: A 1×1 convolutional layer is used on the other branch to integrate global information in the channel dimension;
[0090] S2136: Add the results of the two branches to fully utilize the image feature information;
[0091] S22: construct a multi-style learning discriminator network, which constitutes the entire adversarial network with the generative network. The discriminator network consists of 7 convolution blocks, 1 Sn_linear layer (consisting of 1 Linear layer and spectral normalization) and 1 Sn_Embedding layer (consisting of 1 Embedding layer and spectral normalization), wherein the convolution block includes a two-dimensional convolution, an LReLU nonlinear activation layer and spectral normalization. The discriminator network adopts a forward propagation operation, receives an input image, and obtains an output result through a series of convolution operations, that is, the discriminator's discrimination result of the input image;
[0092] S221: The discriminator receives the input image (including the generated image and the cartoon image) and the label. The input image is processed by D φ Network (D φ The network consists of 6 convolution blocks) to extract features to get h, the convolution kernel size is 3 and the padding is 1;
[0093] S222: Take the feature h as the input of two parts, one part is input into a convolution block with a step size of 1 and a padding of 0 to calculate the final adversarial loss L adv ; The other part is to use the LReLU activation function to perform a nonlinear transformation on the extracted feature h and sum it in the second and third dimensions to produce a global feature vector;
[0094] S223: Use the Sn_linear layer to map the global feature vector obtained by S222 into a high-dimensional embedding vector V embed , the Sn_linear layer includes the linear layer linear and spectral normalization, and uses the Sn_Embedding layer to map the input label to a high-dimensional proxy vector V proxy , Sn_Embedding layer includes coding layer Embedding and spectral normalization, and the number of output channels is 512;
[0095] S224: Embedding vector V obtained from S223 embed and the proxy vector V proxy Use normalization to improve training stability;
[0096] S225: Calculate the conditional contrast loss using the normalized results and labels to measure the similarity between images.
[0097] Step 3: Construct a loss function and introduce conditional contrast loss to promote cartoon generation of different styles. Combine content loss, color reconstruction loss, adversarial loss, style loss, and conditional contrast loss to construct the total network loss.
[0098] The pre-trained VGG19 is used as the perception network to extract the high-level semantic features of the image. The content loss is the loss of the input image and the image generated in step 2, which ensures the content consistency between the two. The content loss formula is: Where L con is the content loss, l is a specific VGG layer, represents a set of natural images, represents the image set generated in step 2, i represents the i-th natural image;
[0099] The color reconstruction loss in AnimeGAN is used to convert the color of the image from RGB format to YUV format. In this loss, L1 loss is used for the Y channel and Huber loss is used for the U and V channels. The purpose is to make the color reconstruction of the image better. The color reconstruction loss can be expressed as:
[0100] Among them, Y(·), U(·), and V(·) represent the three channels of the image respectively;
[0101] The adversarial loss function is: in, represents a cartoon image set, c i represents the i-th cartoon image, represents the image set generated in step 2, f i represents the image generated by the i-th step 2;
[0102] Style loss: Because the texture of the cartoon image is transferred to the content image instead of the color, the grayscale Gram matrix is used to make the generated image have the texture of the cartoon image. Therefore, the input image is first converted to a grayscale image to eliminate color interference:
[0103] g_c i = rgb2gray(c i )
[0104] g_f i = rgb2gray(f i )
[0105]
[0106] In the formula, Gram represents the Gram matrix of the feature, f i represents the generated image, c i Represents a real cartoon image, and rgb2gray represents converting a color image into a grayscale image;
[0107] Preferably, the conditional contrast loss is specifically implemented in the following steps:
[0108] S31: Calculate the embedding vector V obtained in S224 embed The cosine similarity matrix of ;
[0109] S32: Create a mask with diagonal zeros and use this mask to remove the diagonal elements and return a flattened matrix;
[0110] S33: Use the mask of S32 to remove the elements on the diagonal of the cosine similarity matrix of S31, and then divide it by the parameter that adjusts the median value of the similarity matrix (set parameter t=1) to perform exponential processing on the similarity matrix;
[0111] S34: Create a negative sample rejection mask, which accepts the label as input and returns a mask in which the positions of negative samples are set to 0 and the positions of positive samples are set to 1;
[0112] S35: using the negative sample removal mask matrix in S34 on the result obtained in S33, and only retaining the cosine similarity matrix of the positive sample similarity;
[0113] S36: Calculate the embedding vector V obtained in S224 embed To the proxy vector V proxy The cosine similarity is divided by the parameter that adjusts the median value of the similarity matrix and then exponentially processed;
[0114] S37: Calculate the numerator of the loss function by summing the similarity between the embedded vector and the proxy vector and the similarity containing only positive samples;
[0115] S38: Construct the denominator of the loss function, merge the similarity from the embedding vector to the proxy vector with the complete similarity matrix, and then sum each row;
[0116] S39: Calculate the loss function, take the negative average of the logarithm of the ratio of the numerator to the denominator as the loss value, and learn a more discriminative embedding representation by maximizing the similarity of images with the same style and minimizing the similarity of images with different styles;
[0117]
[0118] Where: x n (n=1,,a,L,m) represents the input image of the randomly sampled discriminator, y n Indicates its corresponding label, e(y n ) means encoding it, p means Sn_linear(D φ (·)), t represents the parameter for adjusting the median value of the similarity matrix (this paper sets parameter t = 1), represents the transpose of the matrix. It explicitly takes into account the image-to-image relationship of the same style (When y a =y n When , we pull images of the same category closer and push images of other styles away. We promote the generation of multi-style cartoon images by minimizing the loss;
[0119] The above five losses are used to jointly constrain the entire network to generate better cartoon images.
[0120] Step 4: Use the loss value to adjust the parameters of the generative adversarial network model, iterate the entire generative adversarial network model for multiple rounds, and obtain a trained cartoon image generative network;
[0121] S41: repeat steps 2 to 3. In this embodiment, pre-training is performed for 30,000 rounds to accelerate the convergence of GAN, so that the generator network can reconstruct the content of the input natural image and avoid the loss of semantic information.
[0122] S42: The loop is iterated for 280,000 rounds to obtain a trained cartoon image generation network.
[0123] Step 5: Input the natural image to be processed into the trained multi-style cartoon image generation network to obtain cartoon images of different styles.
[0124] Figure 4 Figure 1 is a partial experimental result diagram of the present invention, showing some different cartoon-style images generated by the present invention. Figure 4 (a) represents the Shinkai style graph generated by the present invention, Figure 4 (b) represents the Hayao style graph generated by the present invention, Figure 4 (c) represents the Hosoda style graph generated by the present invention, Figure 4 (d) shows the DCartoon style map generated by the present invention. It can be seen from the red boxes of each style that when the same content map is input, the output is obviously different style images. And when different content maps are input, a good cartoon effect is still achieved, indicating that the proposed method can produce high-quality stylized results. In addition to these four styles, the model can also be expanded to more styles.
[0125] Figure 5 : is a qualitative comparison diagram of the cartoonization method proposed by the present invention and the single-style image cartoonization method. Figure 5 (a) represents the input graph, Figure 5 (b) represents the image generated by CartoonGAN. Figure 5 (c) represents the image generated by AnimeGANv2, Figure 5 (d) represents the image generated by SDP-GAN, Figure 5 (e) represents the image generated by Learning, Figure 5 (f) represents the image generated by the method of the present invention. The stylization degree of CartoonGAN is relatively weak, and the local cartoon texture is not obvious in the generated result. Among them, the method prepared a cartoon dataset with smooth edges in order to perform adversarial learning to improve the edge effect, but did not achieve a satisfactory result. The results generated by the three styles of AnimeGANv2 are generally darker in color, with local artifacts, and are very different from the characteristics of each style. The results of SDP-GAN tend to reproduce some textures of cartoon images, but seem to ignore the semantic information of the image, that is, both content and color are lost to a certain extent. The image generated by Learning has bright colors overall, but it learns more about the color of the target domain image rather than the texture, resulting in an unsatisfactory cartoonization effect. In contrast, by reproducing the necessary cartoon texture and color information while retaining the input content image, the method of the present invention can produce high-quality results. More importantly, only one model needs to be trained to achieve the conversion of multiple styles, which greatly saves time cost and computing resources.
[0126] Figure 6 is a qualitative comparison diagram of the cartoonization method proposed in the present invention and the multi-style image cartoonization method, wherein: Figure 6 (a) represents the input graph, Figure 6 (b) represents the image generated by White-box, Figure 6 (c) represents the image generated by MS-CartoonGAN, Figure 6 (d) represents the image generated by the method of the present invention; White-box This method does not clearly distinguish which style is which, resulting in unclear style categories of the generated images and high training time cost. The MS-CartoonGAN network architecture is relatively complex, and some areas of the generated images are dark, and over-learning stylization results in the semantic content information not being well preserved. Moreover, the color of the results it produces is unnatural. In contrast, the invented method injects the class label information of the style into the generator and the discriminator respectively, guiding the generator to generate images of a specific style. The conditional contrast loss is used to bring the image and the corresponding style category closer, as well as the relationship between images of the same style, and to push the distance between images of different styles further. Therefore, the conversion of different styles of a single model is achieved through a single generator and discriminator.
[0127] In order to conduct an effective objective quantitative evaluation of the method proposed in the present invention in terms of image cartoonization, the FID value is used to evaluate whether the generated image has the style of a cartoon image.
[0128] FID calculates the distance between the real image and the generated image in the feature space. First, the Inception-v3 network is used to extract features, and then the Gaussian model is used to model the feature space. The distance between the two features is then solved, and this distance is used to measure the similarity between the real image and the generated image. The smaller the distance, the closer the generated distribution is to the real distribution, and the higher the similarity, that is, the generated image is closer to the real image. The formula is as follows.
[0129]
[0130] Where, T r represents the sum of the elements on the diagonal of the matrix, which is called the trace of the matrix in matrix theory. c and f represent the real cartoon image and the generated image, μ represents the mean, (μ c ,∑ c ) and (μ f ,∑ f ) are the mean and covariance of the sample embeddings of the target data distribution and the generated data distribution, respectively.
[0131] In one embodiment of the present invention, the index FID is used to evaluate the effects of the method proposed by the present invention and the methods involved in the comparison on image cartoonization. The results are shown in Table 1:
[0132] Table 1 Quantitative comparison of FID values of test images
[0133]
[0134] In this experiment, 1000 images were converted into cartoon images of 3 styles, and a total of 3000 result images were obtained. As shown in Table 1, the method of the present invention achieved a better score compared with most methods. SDP-GAN scored lower in these three styles and MS-CartoonGAN on Hayao, but it can be seen from their generated images that they over-emphasized the style conversion and the image content was destroyed. However, the method of the present invention only needs to be trained once to obtain the three styles, while SDP-GAN needs to be trained three times. In general, the visual effects and objective indicators of the images verify that the method of the present invention achieves better image cartoonization.
[0135] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A multi-style image cartoonization method based on style condition information, characterized in that: The method comprises two key components for promoting cartoonization of multi-style images, namely, designing a conditional generator and a multi-style learning discriminator, respectively, embedding style condition information into the feature space, and improving the model's ability to achieve different cartoon styles; constructing a loss function, wherein the conditional contrast loss is introduced to promote the generation of cartoonization of different styles; using each loss value to adjust the parameters of the generative adversarial network model, optimizing the generator and discriminator networks, and obtaining the optimal multi-style cartoonization model, specifically comprising the following steps: Step 1: Obtain training sets of source domain and target domain; Step 2: Construct a multi-style image cartoonization generative adversarial network based on style condition information, which includes the following execution steps: S21: Construct a generative network, which consists of 1 two-dimensional convolution layer, 2 downsampling layers, 4 conditional information residual blocks, 2 upsampling layers and 1 convolution block. The downsampling layer contains a two-dimensional convolution and an LReLU non-linear activation layer, the upsampling layer contains a two-dimensional convolution, an LReLU non-linear activation layer and a bilinear interpolation layer, the convolution block contains a two-dimensional convolution and an LReLU non-linear activation layer, and the four conditional information residual blocks contain two-dimensional reflection filling, two-dimensional convolution and conditional instance normalization. In addition, jump connections are used to strengthen the feature conduction of the entire network, and the generated image is obtained by inputting the source domain data. The specific steps are as follows: S211: Use a 7×7 two-dimensional convolutional layer to extract features from the input image; S212: Taking the extracted feature map as input, downsample and extract features through two consecutive downsampling layers. The first downsampling layer converts the feature map of 32 input channels into the feature map of 64 output channels, and the second downsampling layer converts the feature map of 64 input channels into the feature map of 128 output channels; S213: Input the down-sampling result into four conditional information residual blocks to obtain an output feature map; S214: input the feature map into the upsampling layer, restore the feature map, and use bilinear interpolation in the upsampling process to avoid chessboard artifacts; S215: Input the feature map into the convolution block to obtain the generated image. The convolution block first further processes and extracts features from the feature map through a 3×3 sized 2D convolution layer and a 7×7 sized 2D convolution layer. After each convolution layer, an LReLU nonlinear activation layer is applied to enhance the expressiveness of the model. In addition, in order to enhance the feature conduction of the entire network, the skip connection technology is used to fuse the feature information with the output of the convolution block. After these fine convolution and feature fusion processes, the desired image is finally generated; S22: construct a multi-style learning discriminator network, which constitutes the entire adversarial network with the generative network. The discriminator network consists of 7 convolution blocks, 1 Sn_linear layer (consisting of 1 Linear layer and spectral normalization) and 1 Sn_Embedding layer (consisting of 1 Embedding layer and spectral normalization), wherein the convolution block includes a two-dimensional convolution, an LReLU nonlinear activation layer and spectral normalization. The discriminator network adopts a forward propagation operation, receives an input image, and obtains an output result through a series of convolution operations; Step 3: Construct a loss function and introduce conditional contrast loss to promote cartoon generation of different styles. Combine conditional contrast loss, adversarial loss, content loss, color reconstruction loss, and style loss to construct the total network loss. Step 4: using each loss value to adjust the parameters of the generative adversarial network model, and iterating the entire generative adversarial network model for multiple rounds to obtain a trained cartoon image generative network; Step 5: Input the natural image to be processed into the trained multi-style cartoon image generation network to obtain cartoon images of different styles.
2. The multi-style image cartoonization method based on style condition information according to claim 1, characterized in that: The steps for implementing the conditional information residual block in S213 are: S2131: using a two-dimensional reflection filling method on a branch to copy the edge of the feature image obtained after upsampling to ensure that the input and output sizes are consistent; S2132: Use a 3×3 convolutional layer to perform convolution operations on the features with a step size of 1 to extract and transform the input features; S2133: Input the result of S2132 convolution and the class label into the conditional instance normalization, which can learn a different set of parameters, α and β, for each style. Different style categories have different learned parameters. The specific method is: The result after S2132 convolution is instance normalized, and the input class label is encoded to obtain two different parameters α and β. r represents the input image, is the input feature activation, s represents the index in a set of style images, and the feature statistics are normalized using different series of parameters to normalize the input content image into different styles; S2134: repeat steps S211-S213 to obtain a result of a branch of the conditional information residual block; S2135: A 1×1 convolutional layer is used on the other branch to integrate global information in the channel dimension; S2136: Add the results of the two branches to fully utilize the image feature information.
3. The multi-style image cartoonization method based on style condition information according to claim 1, characterized in that: The implementation steps of constructing a multi-style learning discriminator network in S22 are: S221: The discriminator receives the input image (including the generated image and the cartoon image) and the label. The input image is processed by D φ The network performs feature extraction to obtain h; S222: The feature h is used as the input of two parts. The first part is input into a convolutional block to calculate the final adversarial loss L adv ; The second part is to use the LReLU activation function to perform a nonlinear transformation on the extracted feature h and sum it in the second and third dimensions to produce a global feature vector; S223: Use the Sn_linear layer to map the global feature vector of the second part of S222 into a high-dimensional embedding vector V embed , and use the Sn_Embedding layer to map the input label to a high-dimensional proxy vector V proxy ; S224: embedding vector V embed and the proxy vector V proxy Use normalization to improve training stability; S225: The conditional contrast loss is calculated by the normalized results and labels to measure the similarity between images. The conditional contrast loss uses the cosine similarity matrix and masking technology to obtain the similarity measure, and then adjusts the similarity measure to maximize the similarity of images with the same style and minimize the similarity of images with different styles, making it more distinguishable and discriminative, which helps to enhance the differences between styles, strengthen the learning of style features, and promote cartoonization of different styles.
4. The multi-style image cartoonization method based on style condition information according to claim 1, characterized in that: The method for implementing the above step 3 by combining content loss, color reconstruction loss, adversarial loss, style loss, and conditional contrast loss to construct the total network loss is: The pre-trained VGG19 is used as the perception network to extract the high-level semantic features of the image. The content loss is the loss of the input image and the image generated in step 2, which ensures the content consistency between the two. The content loss formula is: Where L con is the content loss, l is a specific VGG layer, represents a set of natural images, represents the image set generated in step 2, i represents the i-th natural image; The color reconstruction loss in AnimeGAN is used to convert the color of the image from RGB format to YUV format. In this loss, L1 loss is used for the Y channel and Huber loss is used for the U and V channels. The purpose is to make the color reconstruction of the image better. The color reconstruction loss can be expressed as: Among them, Y(·), U(·), and V(·) represent the three channels of the image respectively; The adversarial loss function is: in, represents a cartoon image set, c i represents the i-th cartoon image, represents the image set generated in step 2, f i represents the image generated by the i-th step 2; Style loss: Because the texture of the cartoon image is transferred to the content image instead of the color, the grayscale Gram matrix is used to make the generated image have the texture of the cartoon image. Therefore, the input image is first converted to a grayscale image to eliminate color interference: g_c i =rgb2gray(c i ) g_f i =rgb2gray(f i ) In the formula, Gram represents the Gram matrix of the feature, f i represents the generated image, c i Represents a real cartoon image, and rgb2gray represents converting a color image into a grayscale image; The specific implementation steps of the conditional contrast loss are: S31: Calculate the embedding vector V obtained in S224 embed The cosine similarity matrix of ; S32: Create a mask with diagonal zeros and use this mask to remove the diagonal elements and return a flattened matrix; S33: using the mask of S32 to remove the elements on the diagonal of the cosine similarity matrix of S31, and then dividing by the parameter for adjusting the median value of the similarity matrix (setting parameter t=1), the similarity matrix is indexed; S34: Create a negative sample rejection mask, which accepts the label as input and returns a mask in which the positions of negative samples are set to 0 and the positions of positive samples are set to 1; S35: using the negative sample removal mask matrix in S34 on the result obtained in S33, and only retaining the cosine similarity matrix of the positive sample similarity; S36: Calculate the embedding vector V obtained in S224 embed To the proxy vector V proxy The cosine similarity is divided by the parameter that adjusts the median value of the similarity matrix and then exponentially processed; S37: Calculate the numerator of the loss function by summing the similarity between the embedded vector and the proxy vector and the similarity containing only positive samples; S38: Construct the denominator of the loss function, merge the similarity from the embedding vector to the proxy vector with the complete similarity matrix, and then sum each row; S39: Calculate the loss function, take the negative average of the logarithm of the ratio of the numerator to the denominator as the loss value, and learn a more discriminative embedding representation by maximizing the similarity of images with the same style and minimizing the similarity of images with different styles; Where: x n (n=1,,a,L,m) represents the input image of the randomly sampled discriminator, y n Indicates its corresponding label, e(y n ) means encoding it, p means Sn_linear(D φ (·)), t represents the parameter for adjusting the median value of the similarity matrix (this paper sets parameter t = 1), represents the transpose of the matrix, which explicitly takes into account the image-to-image relationship of the same style (When y a =y n When , we pull images of the same category closer and push images of other styles away, thus promoting the generation of multi-style cartoon images by minimizing the loss; The above five losses are used to jointly constrain the entire network to generate better cartoon images.
