Light-weight cartoon style migration method based on image decoupling
Through image decoupling training and feature extraction technology, the problems of blurred details and large computational load in the cartoon image generation algorithm are solved, and the efficient operation and high-quality generation of the lightweight cartoon style transfer model are achieved.
Patent Information
- Application Number
- CN202410765760.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-09-27
AI Technical Summary
Existing cartoon image generation algorithms suffer from blurred image details, poor texture, and excessive model parameters and calculations, making it difficult to deploy into embedded and mobile devices.
The model is trained using image decoupling, which divides the image into surface representation, texture representation and structural representation. It uses ghost convolution, dynamic convolution and multi-spectral channel attention mechanism, combined with MobileOne feature extraction, to optimize the amount of parameters and calculation amount. At the same time, the image generation effect is improved.
It is possible to improve the cartoon image generation effect while reducing the amount of parameters and calculations, ensuring that the model runs in real time on embedded devices, the generated cartoon images are of higher quality, and the training process is stable.
Smart Images

Figure CN118710489A
Abstract
Description
Technical Field The present invention relates to the technical field of target detection, and in particular to a lightweight cartoon style transfer method based on image decoupling. Background Art
[0002] Painting is an aesthetic art created by drawing lines and filling colors to condense real or imaginary things. It can enrich human entertainment and is highly ornamental. Similar to literary works, people convey their thoughts through painting, and then create excellent works of art, which are appreciated and welcomed by more and more people. Similarly, in the field of computer vision, creative research using non-realistic rendering technology is also developing and progressing. At present, cartoon production mainly relies on manual work. However, due to the strong demand for innovation and carefully designed layout and texture, it is a challenging and time-consuming task for artists to create cartoon pictures. Therefore, the research on automatic technology for converting real images into high-quality cartoon images is very valuable, which can not only allow artists to focus on more creative work and save time, but also make it easier for ordinary people to realize their own cartoons.
[0003] The emergence of the generative adversarial network GAN has caused a great sensation, especially in the field of image generation. With the rapid development of GAN, many derivative models based on GAN have emerged. For example, network models such as CycleGan, Pix2PixHD, and StarGan have solved problems such as paired data matching, image resolution, and multimodality. Although the above methods can generate good artistic style pictures, they are still insufficient in generating cartoon pictures. The reason is that cartoon pictures have clear and sharp edges, obvious color changes, and a large number of color compositions. Therefore, in order to better generate cartoon pictures, Figure 1 Some models specifically designed for generating cartoon images have been proposed. CartoonGan first proposed a cartoon feature that promotes edge adversarial loss to highlight edge clarity and achieve excellent cartoon migration effects. After that, many excellent cartoon style migration networks emerged, such as lightweight networks such as AnimeGan, LwcomicGan, Ganilla, etc. There are also cartoon networks that change the training method, such as CTSS, which proposed an edge detection module. Considering the process of cartoon creation, this paper uses image decoupling to cartoonize real-world images.
[0004] In recent years, with the development of deep learning theory and algorithms, the accuracy and speed of target detection algorithms have been improved. The above networks have problems such as blurred image details, poor texture, model parameters, and excessive floating-point operations. The computing power of the device is high, and the model is difficult to deploy to embedded and mobile devices. Therefore, it is necessary to improve such an algorithm to overcome the above defects. Summary of the invention
[0005] The purpose of the present invention is to provide a lightweight cartoon style transfer method based on image decoupling. The method uses image decoupling to train images. Image decoupling includes dividing the image into surface representation, texture representation, and structure representation. In the network structure, ghost convolution is used to reduce the number of parameters and the amount of calculation. Dynamic convolution is used to use different convolution kernels for different images and reduce the amount of additional calculation. In order to further optimize the effect, a multi-spectral channel attention mechanism is used to reduce information loss during training. In order to avoid optimization bottlenecks during training, MobileOne is used in the network process for feature extraction. It aims to further improve the image generation effect while optimizing the number of parameters and the amount of calculation.
[0006] A lightweight cartoon style transfer method based on image decoupling includes the following steps:
[0007] Step 1: Get the original cartoon image and the real-world initial data set. The cartoon data set is the pictures in the animation, and the real-world initial data set is the pictures of the real scene.
[0008] Step 2: Based on the large number of parameters that appear in the image during the convolution process, GhostMoule is used in the downsampling part of the backbone network to reduce parameters and calculations; to ensure that the entire network can have different convolution operations on different images during the training process, dynamic convolution is used for diversified processing. A multi-spectral channel attention mechanism is added at the end of each downsampling part to enhance the effect of generating pictures; Mobileone is used in the network process to extract features, further lighten the weight and optimize the cartoon effect, and conventional convolution blocks are used in the upsampling part. Finally, an improved generation model is obtained.
[0009] Step 3: Construct the discriminator, which consists of regular convolution, spectral normalization and leakyRelu.
[0010] Step 4: Import the pre-trained Vgg19 network model, cartoon training set and real-world pictures into the model for pre-training and introduce content. Then set the number of pre-training times, perform pre-training and finally obtain the pre-trained model.
[0011] Step 5: Import the training model and the trained Vgg19 model into the model at the same time, set the number of training times, hyperparameters, and weight times, and perform image decoupling processing on the initial cartoon dataset and the generated image during the training process, including the surface representation, structure representation, and texture representation of the image. At the same time, introduce structural loss, texture loss, surface loss, and total variation loss.
[0012] Step 6: As the number of training times increases, the loss function curve of the model gradually converges. When the loss function curve converges and stabilizes, the model is trained to the optimal state and the corresponding model file is generated. Import the trained model file into the generated file and input it into the generated file. Import the test real-world image into the generated file to obtain the corresponding cartoonized image.
[0013] The further improvement of the technical solution of the present invention is:
[0014] The step 2 is completed using guided filtering, which can use differentiable guided filtering to remove textures and details to extract a smooth surface. The filter consists of 2 1*1 convolutions and a linearly changing matrix to obtain the surface representation of the image; a random color transfer algorithm is used to extract a single channel from the color image to obtain the image texture representation; superpixel segmentation is completed, and then selective search is applied to merge the segmented areas and extract the sparse segmentation map to obtain the image structure representation.
[0015] Among them, step 1, preferably selects a number of cartoon-style pictures as a style data set, and selects a number of real-world pictures as a content data set.
[0016] Among them, the composition of the generator in step 2 is composed of the following points: using ghost convolution (GhostMoudle), replacing the original convolution with the up-dimensioned part of the convolution in downsampling, to alleviate the phenomenon of overfitting or gradient explosion and disappearance caused by too many model parameters. The convolution can also process key feature information well while reducing parameters. Introducing dynamic convolution in the backbone feature extraction network, the convolution is used at the input end of the feature map, which can optimize the style transfer of the picture on the basis of reducing the additional amount of calculation. And adding a multi-spectral channel attention mechanism at the end of the last two parts of downsampling to improve the network's ability to generate cartoon pictures; on the basis of reducing a large amount of information loss, deeper feature transfer and feature fusion are performed, and the generation of cartoon pictures is more realistic. Finally, considering that the optimization bottleneck may be encountered in the lightweight model training process, Mobileone is used in the network process to extract features, further lightweight and optimize the cartoon effect.
[0017] Among them, the discriminator in step 3 has a conventional convolution as an input, followed by a spectral normalization layer and finally a leaky Relu activation function as the end. Six identical convolution blocks are constructed based on this structure, and the discriminator ends with a conventional convolution.
[0018] Among them, the specific calculation formula for pre-training the Vgg19 network introduced in step 4 is:
[0019] L con=[||VGGl(G(Ip))-VGGl(IP)||1]
[0020] Among them, l represents the feature map of VGG at the lth layer. In this method, the lth layer of the VGG network is "conv4_4". 1 means using l1 regularization.
[0021] In step 5, surface loss, structure loss, texture loss, and total variation loss are further cited during the training phase, and the formula is as follows:
[0022] Surface loss:
[0023] L sur (G,Ds)=logDs(Fdgf(Ic,Ic))+log(1-Ds(Fdgf(G(Ip),G(Ip))))
[0024] Where Fdgf(I,I) represents the output after the filter calculation
[0025] Structural loss:
[0026] L str =||VGGl(G(Ip))-VGGl(Fstr(G(Ip)))||
[0027] Where Fstr(I) represents structure extraction, l represents the feature map of VGG at the lth layer, and the lth layer of the VGG network in this method is "conv4_4".
[0028] Texture Loss:
[0029] L tex (G,Dt)=logDt(Frcs(Ic))+log(1-Dt(Frcs(G(Ip))))
[0030] Among them, Frcs(I) is the output calculated by the random color transfer algorithm.
[0031] Total variation loss:
[0032]
[0033] Among them, H, W, and C represent the three dimensions of the image: height, width, and channel.
[0034] The present invention provides a lightweight cartoon style transfer method based on image decoupling, which has the following advantages:
[0035] The present invention provides a lightweight cartoon style transfer method based on image decoupling. The method can further optimize the cartoon effect of the generated image while reducing the number of parameters and floating-point operations by introducing a lightweight convolution module and an attention mechanism, and the training is stable. The model can be well embedded in the device to perform cartoon style transfer on real-world images in real time.
[0036] First, dynamic convolution is used in the downsampling input part of the network model to ensure that different convolution kernels can be used for different images to enhance the flexibility of the network; secondly, in order to reduce the number of parameters and the amount of computation in the dimensionality-enhancing convolution of the downsampling block, ghost convolution is used for feature dimensionality-enhancing; then, considering that a lot of information will be lost during the migration process, a multi-spectral channel attention mechanism is used to alleviate this problem and improve the quality of image generation; finally, traditional convolution and depthwise separable convolution will bring about problems such as large amount of computation and gradient confusion, so mobileone is used to optimize the structure in the construction of content and flow features, further optimize the number of parameters and floating-point operations, and optimize the effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solution of the present invention, a brief introduction is given to the drawings required for use in the present invention.
[0038] Figure 1 Flowchart of the lightweight cartoon style transfer method based on image decoupling
[0038] Figure 2 (a) is the overall framework of the generative model proposed in this invention, Figure 2 (b) The overall framework of the discriminator model proposed in this invention.
[0039] Figure 3 (a) Figure 3 (b) Figure 3 (c), Figure 3 (d) are the structural diagrams of ghost convolution, dynamic convolution, multi-spectral channel attention mechanism and MobileOne used in the present invention.
[0040] Figure 4 (a) Figure 4 (b) Figure 4 (c) are the surface representation, structure representation, and texture representation of the image obtained by the present invention using the image decoupling method.
[0041] Figure 5 This is the image comparison after style transfer DETAILED DESCRIPTION
[0042] The present invention aims to provide an innovative technical solution, and its specific details will be elaborated in detail below. However, it should be clear that the embodiments of the present invention are not limited to the examples described below, but can be modified and modified in various ways according to actual conditions. The presentation of these embodiments is intended to reveal the technical features and advantages of the present invention in more depth, rather than to limit its scope of protection. Therefore, the present invention is not bound by the following specific embodiments, but should be understood and protected based on its technical essence and scope.
[0043] The present invention provides a lightweight cartoon style transfer method based on image decoupling. The network structure diagram of the improved model is as follows: Figure 1 The specific steps are as follows:
[0044] Step 1: Dataset acquisition and processing
[0045] Get the cartoon dataset and the real-world image dataset. The dataset uses the public dataset of 5792 Hayao Miyazaki cartoons, 6656 real-world training sets, and 779 test sets provided by the author of AnimeGan. Create a data folder, a train folder and a val folder in the data folder, a cartoon folder in the train folder to store cartoon images, a photo folder to store real-world images, and a test folder in the val folder to store the test dataset.
[0046] Step 2: Pre-training
[0047] In order to better train the model, the pre-trained Vgg19 network is used for pre-training before formal training. The Vgg19 network only takes the first 4 layers and uses the content loss function for constraints. After the pre-training is completed, the pre-trained model is obtained and imported.
[0048] Step 3: Build a lightweight image generation model.
[0049] This paper refers to the structural basis of whiteBoxGan to build a network architecture. The present invention relates to an optimized network model design, which adopts innovative technical means in multiple key parts of the network model to improve the performance of the model. First, in the downsampling input part of the network model, the present invention adopts a dynamic convolution method, which can dynamically select or generate different convolution kernels according to different pictures, thereby significantly enhancing the flexibility and adaptability of the network. Secondly, in order to reduce the number of parameters and the amount of calculation at the dimension-raising convolution of the downsampling block, the present invention introduces the ghost convolution (GhostMoudle) technology for feature dimension-raising. Through this technology, the present invention can effectively reduce the redundant parameters and the amount of calculation in the network while maintaining the feature representation capability. Further, the present invention takes into account the problem of information loss that may occur during the model migration process, so a multi-spectral channel attention mechanism is adopted. This mechanism can capture the correlation information between different spectral channels, and adjust the weights of the network accordingly, thereby alleviating the problem of information loss and improving the quality of picture generation. Finally, in view of the shortcomings of traditional convolution and depth-separable convolution in terms of calculation amount and gradient confusion, the present invention adopts the MobileOne structure for the construction of content and flow features. The MobileOne structure can optimize the bottleneck problem in training, further reduce the number of parameters and floating-point operations, and optimize the model effect.
[0050] The purpose of using ghost convolution is that in conventional convolution, especially in the process of dimensionality increase, a large number of similar feature maps will appear, so the number of convolution layers needs to be limited, and such redundant images will generate a lot of unnecessary operations. GhostMoudle can use a series of simple linear transformations on one of the feature maps to generate many ghost feature maps, thereby achieving the goal of using fewer parameters to generate more feature maps.
[0051] Since real-world images are different, if the same set of convolution kernels is used for each real-world image during training or testing, the migration effect for some images will be poor. Using dynamic convolution can effectively solve this problem. Figure 2 In (b), we can see that the structure consists of two modules: the attention model and the convolution kernel superposition. Dynamic convolution is not a single convolution, but a combination of multiple parallel convolution kernels in parallel based on attention. Attention dynamically adjusts the weights according to the input parameters, thereby generating adaptive dynamic convolution.
[0052] In order to reduce the information loss during the training process, a multi-spectral channel attention mechanism is used. The attention splits the input image into n parts along the channel, uses 2D-DCT to compress each component, and finally splices these channels.
[0053] In the process of lightweight model training, optimization bottlenecks may be encountered. MobileoneBlock is used as the residual layer. The structure is decomposed into a 3*3 deep convolution layer and a 1*1 point-by-point convolution layer. A reparameterizable jump connection branch is also used, where the jump connection of the deep convolution layer is a 1*1 point-by-point convolution layer containing a batchnorm layer and a regular batchnorm layer, and the jump connection of the point-by-point convolution is a regular batchnorm layer. This can effectively alleviate the optimization bottleneck problem in training, reduce the number of parameters and calculations, and further improve the generation effect.
[0054] Step 4: Image decoupling method
[0055] The surface representation of the image can be accomplished using guided filtering, which can use differentiable guided filtering to remove textures and details to extract a smooth surface. The filter consists of 2 1*1 convolutions and a linearly changing matrix.
[0056] The post-segmentation representation of the image is done by superpixel segmentation (Felzenszwalb), and then selective search is applied to merge the segmented regions and extract the sparse segmentation map. The formula is as follows:
[0057]
[0058]
[0059] Among them, γ1=20, γ2=40, and u=1.2 can effectively enhance the contrast of the image and reduce the blurring effect on the data set after processing.
[0060] The texture representation of the image uses a random color transfer algorithm to extract a single-channel texture representation from a color image. The formula is as follows:
[0061] F rcs (I rgb )=(1-α)(β1*I r +β2*Ig+β3*I b )+α*Y
[0062] I is the input image, r, g, b are the channels of the image, and Y is the standard grayscale image converted from the RGB color image I, where α = 0.8, β1, β2, β3∈(-1,1).
[0063] Step 5: Use of loss function
[0064] The specific calculation formula for pre-training using the Vgg19 network introduced during pre-training is:
[0065] L con =[||VGGl (G(Ip))-VGG l (IP)||1]
[0066] Among them, l represents the feature map of VGG at the lth layer. In this method, the lth layer of the VGG network is "conv4_4". 1 means using l1 regularization.
[0067] In the training phase, surface loss, structure loss, texture loss, and total variation loss are further cited, and the formulas are as follows:
[0068] Surface loss: L sur (G,D s ) = log D s (F dgf (I c ,I c ))+log(1-D s (F dgf (G(I p ),G(I p ))))
[0069] Structural loss: L str =||VGG l (G(I p ))-VGG l (F str (G(I p )))||
[0070] Texture loss: L tex (G,Dt)=logDt(F rcs (Ic))+log(1-Dt(F rcs (G(Ip))))
[0071] Total variation loss:
[0072] Among them, F dgf (I,I) represents the output after the filter calculation; F str (I) represents structure extraction, l represents the feature map of VGG at the lth layer, and the lth layer of the VGG network in this method is "conv4_4"; F rcs (I) is the output calculated by the random color transfer algorithm; H, W, C represent the three dimensions of the image: height, width, and channel, respectively.
[0073] Step 6: Set the weights, ω sur ,=1,ω str =10,ω tex =2*10 3 ,ω con =2*103 ,ω tv =10 4 Since the training method is white-box in nature, the parameter settings can be relatively rough, and the network can also learn adaptively.
[0074] Step 7: Perform training 200 times according to the above steps, and obtain the final model file after training.
[0075] Import the test set data in step 1, val file into the test file for image generation.
[0076] The present invention proposes a lightweight network structure based on an image decoupling training method, which aims to retain the cartoon effect while reducing the number of model parameters and floating-point operations to achieve a lightweight effect.
[0077] It is worth noting that although this specification is described one by one according to different implementation methods, this does not mean that each implementation method is limited to a single technical solution. In fact, the purpose of this segmented description is only to make the description clearer and easier to understand. Those skilled in the art should understand that the various embodiments and technical solutions presented in this specification can be appropriately combined and adjusted according to actual needs to form other implementation methods that are more diverse and more in line with specific application scenarios. Therefore, the scope of protection of this patent is not limited to any single embodiment, but should cover all implementation methods formed by reasonable combination and adjustment based on the technical principles described in this specification.
Claims
1. A lightweight cartoon style transfer method based on image decoupling, Features The following steps are involved: Step 1: Get the original cartoon image and the real-world initial data set. The cartoon data set is the pictures in the animation, and the real-world initial data set is the pictures of the real scene. Step 2: Construct the generator. According to the large number of parameters that appear in the image during the convolution process, GhostModule is used in the downsampling part of the backbone network to reduce parameters and calculations; Dynamic convolution is used to use different convolutions for different images for diversified processing; a multi-spectral channel attention mechanism is added at the end of each downsampling part to enhance the effect of generating images; Mobileone is used in the network process to extract features, further lighten the weight and optimize the cartoon effect, and conventional convolution blocks are used in the upsampling part, and finally an improved generation model is obtained; Step 3: Construct a discriminator, which consists of conventional convolution, spectral normalization and leakyRelu; Step 4: Import the pre-trained Vgg19 network model, cartoon training set and real-world images into the model for pre-training and introduce content. Then set the number of pre-training times, perform training and finally obtain the pre-trained model. Step 5: Import the training model and the trained Vgg19 model into the model at the same time, set the number of training times, hyperparameters, and weight times, and perform image decoupling processing on the initial cartoon dataset and the generated image during the training process, including the surface representation, structure representation, and texture representation of the image, while introducing structure loss, texture loss, surface loss, and total variation loss; Step 6: As the number of training times increases, the loss function curve of the model gradually converges. When the loss function curve converges and stabilizes, the model is trained to the optimal state and the corresponding model file is generated. Import the trained model file into the generated file and input it into the generated file. Import the test real-world image into the generated file to obtain the corresponding cartoonized image.
2. According to the lightweight cartoon style transfer method based on image decoupling according to claim 1, Features: In step 2, a generator is constructed, and GhostMoudle is used to replace the original convolution with the up-dimensional part of the convolution in downsampling, so as to alleviate the phenomenon of overfitting or gradient explosion and disappearance caused by too many model parameters. Dynamic convolution is introduced into the backbone feature extraction network of the model. The convolution is used at the input end of the feature map to optimize the style transfer of the image on the basis of reducing the additional amount of calculation. Then, a multi-spectral channel attention mechanism is added at the end of the last two parts of downsampling to improve the network's ability to generate cartoon images; on the basis of reducing a large amount of information loss, deeper feature transfer and feature fusion are performed, and the generation of cartoon images is more realistic. Considering that optimization bottlenecks may be encountered during the training of lightweight models, Mobileone is used in the network process to extract features, further lightweight and optimize the cartoon effect. Conventional convolution blocks are used in the upsampling part.
3. According to the lightweight cartoon style transfer method based on image decoupling according to claim 1, Features : The step 3 constructs a discriminator, which has a conventional convolution as an input, followed by a spectral normalization layer and finally ends with a leakyRelu activation function. Based on this structure, 6 identical convolution blocks are constructed, and the discriminator ends with a conventional convolution.
4. The lightweight cartoon style transfer method based on image decoupling according to claim 1, Features: The specific calculation formula for pre-training the Vgg19 network introduced in step 4 is: con =[||VGG l (G(Ip))-VGG l (IP)|| 1 ] Among them, l represents the feature map of VGG at the lth layer. In this method, the lth layer of the VGG network is "conv4_4". 1 means using l1 regularization.
5. The lightweight cartoon style transfer method based on image decoupling according to claim 1, Features: The step 5 is completed using guided filtering, which can use differentiable guided filtering to remove textures and details to extract a smooth surface. The filter consists of two 1*1 convolutions and a linearly changing matrix to obtain a surface representation of the image; a random color transfer algorithm is used to extract a single channel from the color image to obtain a texture representation of the image; superpixel segmentation is completed, and then selective search is applied to merge the segmented areas and extract the sparse segmentation map to obtain a structural representation of the image.
6. The lightweight cartoon style transfer method based on image decoupling according to claim 1, Features: In step 5, surface loss, structure loss, texture loss, and total variation loss are further cited during the training phase, and the formulas are as follows: Surface loss: L sur (G,D s )=logD s (F dgf (I c, I c ))+log(1-D s (F dgf (G(I p ),G(I p )))) where F dgf (I,I) represents the output after the filter calculation Structural loss: L str =||VGG l (G(I p ))-VGG l (F str (G(I p )))|| where F str (I) represents structure extraction, l represents the feature map of VGG at the lth layer, and the lth layer of the VGG network in this method is "conv4_4". Texture Loss: L tex (G,Dt)=logDt(Frcs(Ic))+log(1-Dt(Frcs(G(Ip)))) Among them, F rcs (I) is the output calculated by the random color transfer algorithm. Total variation loss: Among them, H, W, and C represent the three dimensions of the image: height, width, and channel.
7. The lightweight cartoon style transfer method based on image decoupling according to claim 1, Features: The detection network of the improved model in step 6 consists of three detection layers, and its input image size and output image size are both 256*256. The real-world image and the final generated model are imported into the test file to finally obtain the generated image.
