A method and device for coloring line drawings
By introducing the attention screening mechanism and the random cover blur method into the pix2pixGAN model, extracting color cues and combining the upsampling and downsampling modules, the problems of color overflow, boundary line recognition errors and color inconsistency in line drawing coloring are solved, and the problem is improved. Accuracy and detail handling of coloring results.
Patent Information
- Application Number
- CN202111665537.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2041-12-30
AI Technical Summary
Existing line drawing coloring technology has problems such as color overflow, boundary line recognition errors, color inconsistencies, and high randomness in coloring results. It also does not fully utilize the underlying features, resulting in unsatisfactory coloring effects.
Introducing the attention screening mechanism into the generator model of the pix2pixGAN model, extracting color cues through the random masking fuzzy method, and combining the upsampling and downsampling modules, using the Attention mechanism and the residual mechanism to improve feature extraction and gradient transfer, and construct line drawings Color the model.
It improves the accuracy of coloring results and the quality of generated images, reduces color overflow and boundary line recognition errors, enhances the model's sensitivity to line drawing details, and achieves a more ideal line drawing coloring effect.
Smart Images

Figure CN114387365B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a method and device for coloring a line drawing. Background Art
[0002] Image colorization is a hot topic in computer vision. Most colorization tasks are to color grayscale images, aiming to restore a black and white photo to a color image. Nowadays, the animation industry is constantly developing, and line drawing colorization is an important part of it. Good character coloring will attract more viewers. Line drawing coloring is a very complicated task. It may take hours or even days to manually draw a line drawing into a beautiful illustration. Although there are many deep learning methods that can make the colorization results of grayscale images satisfactory, if the grayscale image colorization or image transfer method is simply applied to line drawing coloring, the final colorization result is not ideal. Because the line drawing only contains some sparse edge contour information, unlike the grayscale image, it does not have complete texture, shadow, gradient and other information, which makes coloring much more difficult.
[0003] With the rapid development of deep learning technology, algorithms based on CNN (Convolutional Neural Network) are widely used in various fields, but for some generative tasks, convolutional neural networks are not very good. Until Goodfellow et al. proposed GAN (Generative Adversarial Network), generative tasks such as super-resolution, image coloring, and style transfer have better solutions. Isola et al. proposed a generative adversarial network (Pix2pixGAN) for image-to-image conversion to achieve image translation tasks mapping from the source image domain to the target image domain. Pix2pixGAN can also be used for coloring line drawings, but the overall effect is average because its coloring results are random, resulting in confusion in the overall color matching of the image. To solve this problem, Sangkloy et al. proposed using the same sparse color brush as the line drawing to complete controllable coloring, that is, by adding some continuous color lines as prompts for coloring. Zhang et al. used the pre-trained VGG16 / 19 model to extract a 4096-dimensional global feature of the reference image and added the feature to the middle layer of the generative network. In order to avoid the disappearance of the gradient in the middle layer, two guide decoders were added. Junsoo et al. proposed the SCFT (Spatially Corresponding Feature Transfer) module to fuse the color information of the reference image into the line drawing. In addition, they proposed a triple loss based on similarity, which can better narrow the distance between the coloring result and the reference image. Wang et al. introduced a local feature network to extract semantic feature maps by extracting features from the early stage of the pre-trained network, and used the local feature as one of the inputs of the generator and discriminator. However, since the line drawing is colored, the feature information is much less than that of the grayscale image, and the local feature network is not very effective in extracting semantic features. Guo et al. proposed a two-step coloring method. The first step of the trained model will guess the color area and roughly fill multiple colors on the line drawing; the second step is used to correct the wrong coloring and refine the coloring results. The disadvantage is that a large number of images of the intermediate results of the first and second steps need to be manually produced to train the model.
[0004] In summary, most of the existing line drawing coloring technologies are improved on the basis of GAN. These technologies still have shortcomings such as color overflow (that is, the filled color diffuses into the surrounding area like watercolor), boundary line recognition errors (that is, when the lines are dense, other lines are mistakenly regarded as boundary lines, resulting in adjacent non-related areas being filled with wrong colors), color mismatch (that is, the color of some areas of the coloring result does not correspond to the color prompt), and the coloring result is too random. Summary of the invention
[0005] The present invention provides a line drawing coloring method and device to solve the technical problems that the information transmitted by the jump connection part of the current model is redundant, the underlying features are not fully utilized, and the coloring results are too random.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0007] In one aspect, the present invention provides a method for coloring a line drawing, comprising:
[0008] Collect color images, preprocess the collected color images, generate line drawings based on the preprocessed color images, and use random masking and blurring method to extract corresponding color cues to construct a training data set;
[0009] An attention screening mechanism is introduced into the skip connection part of the generator model of the pix2pixGAN model to improve the pix2pixGAN model and obtain a line drawing coloring model;
[0010] Using the training data set, training the line drawing coloring model;
[0011] Use the trained line drawing coloring model to color the line drawing to be colored.
[0012] Furthermore, the collecting of color images, preprocessing of the collected color images, generating line drawings according to the preprocessed color images, and extracting corresponding color cues using a random masking and blurring method to construct a training data set include:
[0013] Collecting color images and preprocessing the collected color images; wherein the preprocessing of the collected color images includes: rotating and mirroring a portion of the collected color images to achieve data expansion, and cropping all the images; wherein the cropping size is 256×256;
[0014] Generate line drawings based on the preprocessed color images;
[0015] Use 120 white blocks of 20×20 size to randomly mask the color, and then use a mean filter with a kernel size of 100×100 to blur the masked image to obtain the corresponding color hint of the color image;
[0016] Save the color images and their corresponding line drawings and color cues to build a training dataset.
[0017] Furthermore, the generator model of the line drawing coloring model includes an upsampling module, a downsampling module and an attention screening module; wherein the process of the generator model of the line drawing coloring model generating a color image according to the line drawing and the corresponding color prompts includes:
[0018] First, a single-channel line drawing of size 256×256 and a corresponding color hint of 256×256×3 are cascaded and sent to the generator model of the line drawing coloring model, and then the image is reduced in dimension and features of each scale are extracted through a multi-layer downsampling module; the deep information is extracted through an upsampling module, and each upsampling is fused with the corresponding feature extraction part; both the downsampling module and the upsampling module use ReLU (Rectified Linear Unit) activation layer, 3×3 convolution and BN (Batch Normalization) layer as basic units, and introduce a residual mechanism to avoid the gradient disappearance and degradation problems of the deep network; the downsampling and upsampling operations use maximum pooling and anti-maximum pooling to scale; after the upsampling operation, a LeakyRelu activation layer, a 3×3 convolution layer and a Tanh activation layer are passed to finally generate a 256×256 color image;
[0019] The attention screening module takes the current network layer feature x and the next network layer feature g as input, aligns the size and number of channels and adds them after convolution operation, then uses ReLU activation and convolution operation for dimensional compression, then generates the Attention coefficient after Sigmoid activation, and finally upsamples the Attention coefficient to the original dimension of the original vector x, multiplies it with the original vector x and outputs it; the calculation method is as follows:
[0020]
[0021]
[0022] Among them, σ 1 is the ReLU activation function, σ 2 is the Sigmoid activation function; Θ att Includes linear transformation Both are 1×1 convolutions, is the bias term of the corresponding convolution; vector is the i-th feature of the current network layer, vector g i is the i-th feature in the next layer.
[0023] Furthermore, the discriminator model of the line draft coloring model is a fully convolutional network; wherein, the discriminator model of the line draft coloring model takes the line draft image and the generated image output by the generator model of the line draft coloring model or the line draft image and the real image as input, and after passing through multiple layers of convolution blocks, outputs a 30×30 matrix; each value in the matrix is a judgment of a small area in the original image, and these values are averaged as the final output of the discriminator.
[0024] Furthermore, the loss function of the generator model of the line drawing coloring model is:
[0025] L G =λ l1 L l1 +λ adv L adv +λ tv L tv
[0026] in,
[0027]
[0028]
[0029]
[0030] Among them, I s It is a line drawing. h It is a color hint, I r is a real image, G is the generator, D is the discriminator, λ l1 , adv , tv is the weight, x i,j Represents the pixel value at the coordinate (i, j) position in the image, and β is a hyperparameter; Respectively represent the combination distribution I r ,I s The mathematical expectation of the combination distribution I h ,I s The mathematical expectation and the distribution of the combination I s ,I h ,I r The mathematical expectation of .
[0031] Furthermore, the loss function of the discriminator model of the line drawing coloring model is:
[0032] L D =-λ adv L adv
[0033] in,
[0034]
[0035] Furthermore, the method further comprises:
[0036] In the process of training the line drawing coloring model, a learning rate decay mechanism is added to help the training convergence and prevent oscillation; wherein the expression of the learning rate decay mechanism is:
[0037]
[0038] Among them, α is the optimizer learning rate in the current stage, and the learning rate decay operation is performed every 15 rounds.
[0039] On the other hand, the present invention also provides a line drawing coloring device, comprising:
[0040] The training data set construction module is used to collect color images, preprocess the collected color images, generate line drawings based on the preprocessed color images, and use the random masking and blurring method to extract corresponding color cues to construct the training data set;
[0041] The model improvement module is used to introduce an attention screening mechanism into the jump connection part of the generator model of the pix2pixGAN model to improve the pix2pixGAN model and obtain a line drawing coloring model;
[0042] A model training module, used to train the line drawing coloring model using the training data set;
[0043] The coloring module is used to color the line drawings to be colored using the trained line drawing coloring model.
[0044] On the other hand, the present invention further provides an electronic device, comprising a processor and a memory; wherein the memory stores at least one instruction, and the instruction is loaded and executed by the processor to implement the above method.
[0045] In yet another aspect, the present invention further provides a computer-readable storage medium, wherein the storage medium stores at least one instruction, and the instruction is loaded and executed by a processor to implement the above method.
[0046] The beneficial effects brought about by the technical solution provided by the present invention include at least:
[0047] Compared with the pix2pixGAN model, the present invention can automatically extract color cues from color images for training, and the network can correctly color according to the given color cues; the learning rate decay mechanism can help the training converge better and prevent oscillation; adding an attention screening mechanism enables the model to make better use of feature information and be more sensitive to coloring of line drawing details, thereby improving the accuracy of coloring results and the quality of generated images. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. 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 creative work.
[0049] Figure 1 1 is a schematic diagram of the execution flow of the line drawing coloring method provided by an embodiment of the present invention;
[0050] Figure 2 Schematic diagram of the network structure of the line drawing coloring model generator provided by an embodiment of the present invention;
[0051] Figure 3 Schematic diagram of the network structure of the attention screening mechanism provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0052] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0053] First embodiment
[0054] This embodiment provides a method for coloring a line drawing, which can be implemented by an electronic device, which can be a terminal or a server. Figure 1 As shown, the following steps are included:
[0055] S1, collect color images, preprocess the collected color images, generate line drawings based on the preprocessed color images, and use random masking and blurring method to extract corresponding color cues to construct a training data set;
[0056] S2, introduces an attention screening mechanism into the skip connection part of the generator model of the pix2pixGAN model to improve the pix2pixGAN model and obtain a line drawing coloring model;
[0057] S3, using the training data set to train the line drawing coloring model;
[0058] S4, using the trained line drawing coloring model to color the line drawing to be colored.
[0059] Furthermore, in this embodiment, the implementation process of the above S1 is specifically as follows:
[0060] Collect a large number of color images and preprocess the collected color images; wherein the preprocessing process includes: rotating and mirroring a portion of the collected color images to achieve data expansion, and cropping all the images; wherein the cropping size is 256×256;
[0061] Generate line drawings based on the preprocessed color images;
[0062] Use 120 white blocks of 20×20 size to randomly mask the color, and then use a mean filter with a kernel size of 100×100 to blur the masked image to obtain the corresponding color hint of the color image;
[0063] Save the color images and their corresponding line drawings and color cues to build a training dataset.
[0064] Furthermore, in this embodiment, the structure of the generator model of the line drawing coloring model is as follows: Figure 2 As shown in the figure, it is based on the U-Net architecture design and consists of an upsampling module, a downsampling module, and an attention filtering module. The process of the generator model generating a color image based on the line drawing and the corresponding color prompts is as follows:
[0065] First, a single-channel line drawing of size 256×256 and the corresponding 256×256×3 color hint are sent to the network after cascading, and then the image is reduced in dimension and features of each scale are extracted through a multi-layer downsampling module; the deep information is extracted through an upsampling module, and each upsampling is fused with the corresponding feature extraction part; both the downsampling module and the upsampling module use ReLU (Rectified Linear Unit) activation layer, 3×3 convolution and BN (Batch Normalization) layer as basic units, and introduce a residual mechanism to avoid the gradient disappearance and degradation problems of the deep network; the downsampling and upsampling operations use maximum pooling and anti-maximum pooling to scale; after the upsampling operation, a LeakyRelu activation layer, a 3×3 convolution layer and a Tanh activation layer are passed to finally generate a 256×256 color image.
[0066] The attention screening module is as follows Figure 3 As shown in the figure, it takes the current network layer feature x and the next network layer feature g as input, aligns the size and number of channels and adds them after convolution operation, then uses ReLU activation and convolution operation for dimensional compression, then generates the Attention coefficient after Sigmoid activation, and finally upsamples the Attention coefficient to the original dimension of the original vector x, multiplies it with the original vector x and outputs it; the specific calculation method is as follows:
[0067]
[0068]
[0069] Among them, σ 1 is the ReLU activation function, σ 2 is the Sigmoid activation function; Θ att Includes linear transformation Both are 1×1 convolutions, is the bias term of the corresponding convolution; vector is the i-th feature of the current network layer, vector g i is the i-th feature in the next layer.
[0070] Furthermore, in this embodiment, the discriminator model of the line drawing coloring model considers the idea of PatchGAN and is a fully convolutional network; the discriminator of a general GAN maps a 256×256 image to a single scalar output, and uses the value of the scalar to measure the authenticity of the image. The result of such an output is to weight the entire image, which cannot reflect the characteristics of the local image well, and is not very practical for tasks with high precision requirements. In this regard, in order to better judge the local features of the image, the discriminator model of this embodiment takes the line drawing and the generated image or the line drawing and the real image as input after cascading, and after multiple layers of convolution blocks, outputs a 30×30 matrix; each value in the matrix is a judgment of a small area in the original image, and these values are averaged as the final output of the discriminator.
[0071] Furthermore, in this embodiment, the loss function of the generator model of the line drawing coloring model is:
[0072] L G =λ l1 L l1 +λ adv L adv +λ tv L tv
[0073] The loss function of the discriminator model of the line drawing coloring model is:
[0074] L D =-λ adv L adv
[0075] in:
[0076]
[0077]
[0078]
[0079] Among them, I s It is a line drawing. h is the corresponding color prompt, I r is a real image, G is the generator, D is the discriminator, λ l1 , adv , tv is the weight, λ l1 =100,λ adv =1,λ tv =1;x i,j represents the pixel value at the coordinate (i, j) in the image, β is a hyperparameter, and in this embodiment, β=2. Respectively represent the combination distribution I r ,I s The mathematical expectation of the combination distribution I h ,I s The mathematical expectation and the distribution of the combination I s ,I h ,I r The mathematical expectation of .
[0080] Furthermore, in this embodiment, the line drawing coloring method further includes:
[0081] In the process of training the line drawing coloring model, a learning rate decay mechanism is added to help the training convergence and prevent oscillation; wherein the expression of the learning rate decay mechanism is:
[0082]
[0083] Among them, α is the optimizer learning rate in the current stage, and the learning rate decay operation is performed every 15 rounds.
[0084] In summary, this embodiment automatically extracts color cues for training, and adds color cues as additional information to assist coloring during coloring, so as to achieve the purpose of interactive coloring, so that the desired color can be applied to the corresponding part of the line draft. An attention screening mechanism is introduced in the jump connection part of the generator model, so that the network can automatically learn to distinguish the shape and size of the target, and improve the model sensitivity and accuracy by suppressing the activation of features in irrelevant areas. Thereby improving the accuracy of the coloring results and the quality of the generated pictures. In addition, this embodiment adds a learning rate decay mechanism in the training process, which is conducive to training convergence and prevents oscillation.
[0085] Second embodiment
[0086] This embodiment provides a line drawing coloring device, which includes the following modules:
[0087] The training data set construction module is used to collect color images, preprocess the collected color images, generate line drawings based on the preprocessed color images, and use the random masking and blurring method to extract corresponding color cues to construct the training data set;
[0088] The model improvement module is used to introduce an attention screening mechanism into the jump connection part of the generator model of the pix2pixGAN model to improve the pix2pixGAN model and obtain a line drawing coloring model;
[0089] A model training module, used to train the line drawing coloring model using the training data set;
[0090] The coloring module is used to color the line drawings to be colored using the trained line drawing coloring model.
[0091] The line drawing coloring device of this embodiment corresponds to the line drawing coloring method of the first embodiment mentioned above; wherein, the functions implemented by each functional module in the line drawing coloring device of this embodiment correspond one-to-one to each process step in the line drawing coloring method of the first embodiment mentioned above; therefore, they will not be repeated here.
[0092] Third embodiment
[0093] This embodiment provides an electronic device, which includes a processor and a memory; wherein the memory stores at least one instruction, and the instruction is loaded and executed by the processor to implement the method of the first embodiment.
[0094] The electronic device may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) and one or more memories, wherein the memory stores at least one instruction, and the instruction is loaded by the processor to execute the above method.
[0095] Fourth embodiment
[0096] This embodiment provides a computer-readable storage medium, which stores at least one instruction, and the instruction is loaded and executed by a processor to implement the method of the first embodiment. The computer-readable storage medium may be a ROM, a random access memory, a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc. The instructions stored therein may be loaded by a processor in a terminal to execute the above method.
[0097] In addition, it should be noted that the present invention can be provided as a method, an apparatus or a computer program product. Therefore, the embodiments of the present invention can take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the embodiments of the present invention can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.
[0098] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0099] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device, so that a series of operation steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable terminal device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0100] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0101] Finally, it should be noted that the above is a preferred embodiment of the present invention. It should be pointed out that although the preferred embodiment of the present invention has been described, for those skilled in the art, once the basic creative concept of the present invention is known, several improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications should also be regarded as the protection scope of the present invention. Therefore, the attached claims are intended to be interpreted as including the preferred embodiment and all changes and modifications that fall within the scope of the embodiments of the present invention.
Claims
1. A method for coloring a line drawing, characterized in that: include: Collect color images, preprocess the collected color images, generate line drawings based on the preprocessed color images, and use random masking and blurring method to extract corresponding color cues to construct a training data set; An attention screening mechanism is introduced into the skip connection part of the generator model of the pix2pixGAN model to improve the pix2pixGAN model and obtain a line drawing coloring model; Using the training data set, training the line drawing coloring model; Use the trained line drawing coloring model to color the line drawing to be colored; The collecting of color images, preprocessing of the collected color images, generating line drawings according to the preprocessed color images, and extracting corresponding color cues by using a random masking and blurring method to construct a training data set include: Collecting color images and preprocessing the collected color images; wherein the preprocessing of the collected color images includes: rotating and mirroring a portion of the collected color images to achieve data expansion, and cropping all the images; wherein the cropping size is 256×256; Generate line drawings based on the preprocessed color images; Use 120 white blocks of 20×20 size to randomly mask the color, and then use a mean filter with a kernel size of 100×100 to blur the masked image to obtain the corresponding color hint of the color image; Save the color images and their corresponding line drawings and color cues to build a training data set; The generator model of the line drawing coloring model includes an upsampling module, a downsampling module and an attention screening module; wherein the process of the generator model of the line drawing coloring model generating a color image according to the line drawing and the corresponding color prompt includes: First, a single-channel line drawing of size 256×256 and a corresponding color hint of 256×256×3 are cascaded and sent to the generator model of the line drawing coloring model, and then the image is reduced in dimension and features of each scale are extracted through a multi-layer downsampling module; the deep information is extracted through an upsampling module, and each upsampling is fused with the corresponding feature extraction part; both the downsampling module and the upsampling module use ReLU (Rectified Linear Unit) activation layer, 3×3 convolution and BN (Batch Normalization) layer as basic units, and introduce a residual mechanism to avoid the gradient disappearance and degradation problems of the deep network; the downsampling and upsampling operations use maximum pooling and anti-maximum pooling to scale; after the upsampling operation, a LeakyRelu activation layer, a 3×3 convolution layer and a Tanh activation layer are passed to finally generate a 256×256 color image; The attention screening module takes the current network layer feature x and the next network layer feature g as input, aligns the size and number of channels and adds them after convolution operation, then uses ReLU activation and convolution operation for dimensional compression, then generates the Attention coefficient after Sigmoid activation, and finally upsamples the Attention coefficient to the original dimension of the original vector x, multiplies it with the original vector x and outputs it; the calculation method is as follows: Among them, σ1 is the ReLU activation function, σ2 is the Sigmoid activation function; Θ att Includes linear transformation Both are 1×1 convolutions, is the bias term of the corresponding convolution; vector is the i-th feature of the current network layer, vector g i is the i-th feature in the next layer.
2. The line drawing coloring method according to claim 1, characterized in that: The discriminator model of the line drawing coloring model is a fully convolutional network; wherein, the discriminator model of the line drawing coloring model takes the line drawing image and the generated image output by the generator model of the line drawing coloring model or the line drawing image and the real image as input, and after passing through multiple layers of convolution blocks, outputs a 30×30 matrix; each value in the matrix is a judgment of a small area in the original image, and these values are averaged as the final output of the discriminator.
3. The line drawing coloring method according to claim 1, characterized in that: The loss function of the generator model of the line drawing coloring model is: L G =λ l1 L l1 +λ adv L adv +λ tv L tv in, Among them, I s It is a line drawing. h It is a color hint, I r is a real image, G is the generator, D is the discriminator, λ l1 , adv , tv is the weight, x i,j Represents the pixel value at the coordinate (i, j) position in the image, and β is a hyperparameter; Respectively represent the combination distribution I r ,I s The mathematical expectation of the combination distribution I h ,I s The mathematical expectation and the distribution of the combination I s ,I h ,I r The mathematical expectation of .
4. The method for coloring a line drawing according to claim 3, characterized in that: The loss function of the discriminator model of the line drawing coloring model is: L D =-λ adv L adv in, 5. The line drawing coloring method according to claim 1, characterized in that: The method further comprises: In the process of training the line drawing coloring model, a learning rate decay mechanism is added to help the training convergence and prevent oscillation; wherein the expression of the learning rate decay mechanism is: Among them, α is the optimizer learning rate in the current stage, and the learning rate decay operation is performed every 15 rounds.
6. A line drawing coloring device, characterized in that: include: The training data set construction module is used to collect color images, preprocess the collected color images, generate line drawings based on the preprocessed color images, and use the random masking and blurring method to extract corresponding color cues to construct the training data set; The model improvement module is used to introduce an attention screening mechanism into the jump connection part of the generator model of the pix2pixGAN model to improve the pix2pixGAN model and obtain a line drawing coloring model; A model training module, used to train the line drawing coloring model using the training data set; A coloring module is used to color the line drawings to be colored using the trained line drawing coloring model; The collecting of color images, preprocessing of the collected color images, generating line drawings according to the preprocessed color images, and extracting corresponding color cues by using a random masking and blurring method to construct a training data set include: Collecting color images and preprocessing the collected color images; wherein the preprocessing of the collected color images includes: rotating and mirroring a portion of the collected color images to achieve data expansion, and cropping all the images; wherein the cropping size is 256×256; Generate line drawings based on the preprocessed color images; Use 120 white blocks of 20×20 size to randomly mask the color, and then use a mean filter with a kernel size of 100×100 to blur the masked image to obtain the corresponding color hint of the color image; Save the color images and their corresponding line drawings and color cues to build a training data set; The generator model of the line drawing coloring model includes an upsampling module, a downsampling module and an attention screening module; wherein the process of the generator model of the line drawing coloring model generating a color image according to the line drawing and the corresponding color prompt includes: First, a single-channel line drawing of size 256×256 and a corresponding color hint of 256×256×3 are cascaded and sent to the generator model of the line drawing coloring model, and then the image is reduced in dimension and features of each scale are extracted through a multi-layer downsampling module; the deep information is extracted through an upsampling module, and each upsampling is fused with the corresponding feature extraction part; both the downsampling module and the upsampling module use ReLU (Rectified Linear Unit) activation layer, 3×3 convolution and BN (Batch Normalization) layer as basic units, and introduce a residual mechanism to avoid the gradient disappearance and degradation problems of the deep network; the downsampling and upsampling operations use maximum pooling and anti-maximum pooling to scale; after the upsampling operation, a LeakyRelu activation layer, a 3×3 convolution layer and a Tanh activation layer are passed to finally generate a 256×256 color image; The attention screening module takes the current network layer feature x and the next network layer feature g as input, aligns the size and number of channels and adds them after convolution operation, then uses ReLU activation and convolution operation for dimensional compression, then generates the Attention coefficient after Sigmoid activation, and finally upsamples the Attention coefficient to the original dimension of the original vector x, multiplies it with the original vector x and outputs it; the calculation method is as follows: Among them, σ1 is the ReLU activation function, σ2 is the Sigmoid activation function; Θ att Includes linear transformation Both are 1×1 convolutions, is the bias term of the corresponding convolution; vector is the i-th feature of the current network layer, vector g i is the i-th feature in the next layer.
