WO2020155907A1 - Method and apparatus for generating cartoon style conversion model - Google Patents
Method and apparatus for generating cartoon style conversion model Download PDFInfo
- Publication number
- WO2020155907A1 WO2020155907A1 PCT/CN2019/126379 CN2019126379W WO2020155907A1 WO 2020155907 A1 WO2020155907 A1 WO 2020155907A1 CN 2019126379 W CN2019126379 W CN 2019126379W WO 2020155907 A1 WO2020155907 A1 WO 2020155907A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- image
- network
- sample
- comic style
- comic
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 75
- 238000006243 chemical reaction Methods 0.000 title claims abstract description 68
- 238000010801 machine learning Methods 0.000 claims abstract description 14
- 230000006870 function Effects 0.000 claims description 45
- 238000004590 computer program Methods 0.000 claims description 10
- 230000000694 effects Effects 0.000 abstract description 11
- 238000012545 processing Methods 0.000 description 15
- 230000008569 process Effects 0.000 description 12
- 238000010586 diagram Methods 0.000 description 11
- 238000013527 convolutional neural network Methods 0.000 description 9
- 238000004891 communication Methods 0.000 description 7
- 241000556720 Manga Species 0.000 description 5
- 239000003086 colorant Substances 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 4
- 238000012706 support-vector machine Methods 0.000 description 4
- 230000008859 change Effects 0.000 description 2
- 230000007423 decrease Effects 0.000 description 2
- 239000011159 matrix material Substances 0.000 description 2
- 238000011176 pooling Methods 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 238000012512 characterization method Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000000835 fiber Substances 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/04—Architecture, e.g. interconnection topology
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/08—Learning methods
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T3/00—Geometric image transformations in the plane of the image
Definitions
- the embodiments of the present disclosure relate to the field of computer technology, and in particular to a method and apparatus for generating a comic style conversion model.
- some image processing software can process images and convert them into images of other styles. For example, change the color and shape of certain areas in the image.
- These software usually include models for converting images into other styles of images.
- the training process of the model usually involves inputting an image, comparing the image with its corresponding images of other styles, and optimizing the parameters of the model according to the difference between the two images.
- the embodiments of the present disclosure propose a method and apparatus for generating a comic style conversion model, and a method and apparatus for generating a comic style image.
- an embodiment of the present disclosure provides a method for generating a comic style conversion model.
- the method includes: obtaining a training sample set, wherein the training sample includes a preset sample image and a sample corresponding to the sample image Comic style images; obtain a pre-established generative confrontation network, where the generative confrontation network includes a generation network and a discrimination network.
- the generation network is used to generate comic style images from the input sample images, and the discrimination network is used to distinguish the comic style output of the generation network
- the image and the sample comic style image corresponding to the sample image of the input generation network using machine learning methods, the sample image included in the training sample in the training sample set is used as the input of the generation network, and the sample comic style image corresponding to the input sample image
- the generation network and the discrimination network are trained, and the trained generation network Determined as a manga style conversion model.
- the discriminant network is a multi-scale discriminator, which is used to discriminate the input image and output at least two discriminant results, wherein, for the discriminant result of the at least two discriminant results output, the discriminant result corresponds to The block image included in the image input to the discrimination network and the sample comic style block image included in the sample comic style image are used to determine whether the block image and the corresponding sample comic style block image match.
- training the generation network and the discrimination network includes: using a preset loss function to determine the generation loss value that is used to characterize the difference between the comic style image output by the generation network and the corresponding sample comic style image, and Determine the discriminant loss value corresponding to the discriminant network, which is used to characterize the difference between the comic style image actually output by the generation network of the input discriminant network and the sample comic style image; based on the determined generation loss value and discriminant loss value, the generation network is judged The network is trained.
- the generated loss value is determined by any one of the following loss functions: L1 norm loss function, L2 norm loss function.
- an embodiment of the present disclosure provides a method for generating a comic style image, the method includes: acquiring a target image; inputting the target image into a pre-trained comic style conversion model to generate a comic style image corresponding to the target image And output, wherein the comic style conversion model is generated according to the method described in any one of the embodiments of the first aspect.
- the target image is an image frame extracted from the target video.
- an embodiment of the present disclosure provides an apparatus for generating a comic style conversion model.
- the apparatus includes: a first acquiring unit configured to acquire a training sample set, wherein the training sample includes a preset sample image , And a sample comic style image corresponding to the sample image; the second acquisition unit is configured to acquire a pre-established generative confrontation network, wherein the generative confrontation network includes a generation network and a discriminant network, and the generation network is used to use the input sample image Generate comic style images, and the discrimination network is used to distinguish between the comic style images output by the generation network and the sample comic style images corresponding to the sample images of the input generation network; the training unit is configured to use machine learning methods to combine the training samples in the training sample set
- the included sample image is used as the input of the generation network, the sample comic style image corresponding to the input sample image is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style corresponding to the input sample image
- the image is used as the input of the discrimin
- the discriminant network is a multi-scale discriminator, which is used to discriminate the input image and output at least two discriminant results, wherein, for the discriminant result of the at least two discriminant results output, the discriminant result corresponds to The block image included in the image input to the discrimination network and the sample comic style block image included in the sample comic style image are used to determine whether the block image and the corresponding sample comic style block image match.
- the training unit includes: a determination module configured to use a preset loss function to determine a generation loss value that is used to characterize the difference between the comic style image output by the generation network and the corresponding sample comic style image, and determine The discriminant loss value corresponding to the discriminant network and used to characterize the difference between the comic style image actually output by the generation network of the input discriminant network and the sample comic style image; the training module is configured to be based on the determined generation loss value and discriminant loss value, Train the generation network and the discriminant network.
- the generated loss value is determined by any one of the following loss functions: L1 norm loss function, L2 norm loss function.
- an embodiment of the present disclosure provides an apparatus for generating a comic style image.
- the apparatus includes: an image acquisition unit configured to acquire a target image; an image generation unit configured to input the target image into pre-training
- the comic style conversion model generates and outputs a comic style image corresponding to the target image, where the comic style conversion model is generated according to the method described in any one of the embodiments of the first aspect.
- the target image is an image frame extracted from the target video.
- the embodiments of the present disclosure provide an electronic device that includes: one or more processors; a storage device on which one or more programs are stored; when one or more programs are Multiple processors execute, so that one or more processors implement the method described in any one of the first aspect or the second aspect.
- the embodiments of the present disclosure provide a computer-readable medium on which a computer program is stored, and when the computer program is executed by a processor, the method described in any one of the first aspect or the second aspect is implemented .
- the method and device for generating a comic style conversion model provided by the embodiments of the present disclosure are obtained by acquiring a training sample set and a pre-established generating confrontation network, and using a machine learning method, the sample image included in the training sample in the training sample set is taken as The input of the generation network, the sample comic style image corresponding to the input sample image is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the judgment network Input, train the generation network and the discriminant network, and determine the trained generation network as the comic style conversion model.
- the training of the generative adversarial network including the generative network and the discriminant network is added, which helps to reduce the generation of the model trained by the supervised training method.
- Over-fitting problem improve the generalization ability of the model, and improve the detailed processing ability of image style conversion.
- Using the cartoon style conversion model obtained by training can reduce the image edge jagged and image contour generated by the generated comic style image relative to the original image Deformation and other issues, thereby improving the display effect of the generated comic style image.
- Fig. 1 is an exemplary system architecture diagram in which an embodiment of the present disclosure can be applied;
- FIG. 2 is a flowchart of an embodiment of a method for generating a comic style conversion model according to an embodiment of the present disclosure
- FIG. 3 is a schematic diagram of an application scene of the method for generating a comic style conversion model according to an embodiment of the present disclosure
- FIG. 4 is a flowchart of an embodiment of a method for generating a comic style image according to an embodiment of the present disclosure
- Fig. 5 is a schematic structural diagram of an embodiment of an apparatus for generating a comic style conversion model according to an embodiment of the present disclosure
- FIG. 6 is a schematic structural diagram of an embodiment of an apparatus for generating comic style images according to an embodiment of the present disclosure
- FIG. 7 is a schematic structural diagram of an electronic device suitable for implementing embodiments of the present disclosure.
- FIG. 1 shows a method for generating a comic style conversion model or an apparatus for generating a comic style conversion model to which an embodiment of the present disclosure can be applied, and a method for generating a comic style image or a method for generating a comic style image
- the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105.
- the network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105.
- the network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables.
- the user can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, and so on.
- Various communication client applications such as image processing applications, web browser applications, instant messaging tools, and social platform software, may be installed on the terminal devices 101, 102, and 103.
- the terminal devices 101, 102, and 103 may be hardware or software. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices. When the terminal devices 101, 102, and 103 are software, they can be installed in the aforementioned electronic devices. It can be implemented as multiple software or software modules (for example, software or software modules used to provide distributed services), or as a single software or software module. No specific restrictions are made here.
- the server 105 may be a server that provides various services, for example, a back-end server that processes a collection of training samples uploaded by the terminal devices 101, 102, and 103.
- the background server can use the acquired training sample set to train the generative adversarial network to obtain a comic style conversion model.
- the background server can also use the comic style conversion model to process the input image to obtain the comic style image and output.
- the method for generating a comic style conversion model provided by the embodiments of the present disclosure can be executed by the server 105, or can be executed by the terminal devices 101, 102, 103, and accordingly, used to generate the comic style conversion model
- the device of can be set in the server 105 or in the terminal equipment 101, 102, 103.
- the method for generating comic style images provided by the embodiments of the present disclosure can be executed by the server 105, and can also be executed by the terminal devices 101, 102, 103.
- the device for generating comic style images can be set in The server 105 may also be provided in the terminal devices 101, 102, 103.
- the server can be hardware or software.
- the server can be implemented as a distributed server cluster composed of multiple servers, or as a single server.
- the server is software, it can be implemented as multiple software or software modules (for example, software or software modules for providing distributed services), or as a single software or software module. No specific restrictions are made here.
- terminal devices, networks, and servers in FIG. 1 are merely illustrative. According to implementation needs, there can be any number of terminal devices, networks and servers.
- the foregoing system architecture may not include a network, but only a server or terminal device.
- the method for generating a comic style conversion model includes the following steps:
- Step 201 Obtain a training sample set.
- the executor of the method for generating a comic style conversion model can obtain the training sample collection remotely or locally through a wired connection or a wireless connection.
- the training samples include preset sample images and sample comic style images corresponding to the sample images.
- the sample image may be an image obtained by photographing a real person, object, scene, etc.
- the sample comic style image may be an image obtained by performing various processings on its corresponding sample image (for example, changing colors, shapes, and adding special effects to certain areas in the image), and the resulting image usually has a comic style.
- the character image, background image, etc. in the sample image are processed such as changing colors and adding lines to make them have a comic style.
- the corresponding relationship between the sample image and the sample comic style image is established in advance.
- the technician may process the sample image in advance for each sample image in the plurality of sample images, so as to determine the image obtained after the processing as the sample comic style image corresponding to the image.
- Step 202 Obtain a pre-established generative confrontation network.
- the above-mentioned execution subject may obtain a pre-established generational confrontation network locally or remotely.
- the generative confrontation network includes the generative network and the discriminant network.
- the generation network is used to generate a comic style image using the input sample image
- the discrimination network is used to distinguish the comic style image output by the generation network and the sample comic style image corresponding to the sample image input to the generation network.
- the above-mentioned generative confrontation network may be a generative confrontation network of various structures.
- the generative confrontation network may be a deep convolutional generation confrontation network (Deep Convolutional Generative Adversarial Network, DCGAN). It should be understood that the above-mentioned generative confrontation network may be an untrained generative confrontation network after initializing parameters, or a trained generative confrontation network.
- the generating network may be a convolutional neural network used for image processing (for example, a convolutional neural network with various structures including a convolution layer, a pooling layer, a depooling layer, and a deconvolution layer).
- the above-mentioned discriminant network may be a convolutional neural network (for example, a convolutional neural network of various structures including a fully connected layer, where the above-mentioned fully connected layer can implement a classification function).
- the discriminant network may also be other models for implementing classification functions, such as Support Vector Machine (SVM).
- SVM Support Vector Machine
- the discrimination network determines that the image is the image output by the generation network, it can output the label 1 (or 0) corresponding to the image; if it is determined that the image is not output by the generation network , You can output the label 0 (or 1) corresponding to the image. It should be noted that the discrimination network can also output other preset information, which is not limited to the values 1 and 0.
- Step 203 Using a machine learning method, the sample images included in the training samples in the training sample set are used as the input of the generation network, the sample comic style images corresponding to the input sample images are used as the expected output of the generation network, and the actual network is generated.
- the output comic style image and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, the generation network and the discrimination network are trained, and the trained generation network is determined as the comic style conversion model.
- the above-mentioned execution subject can use a machine learning method to use the sample images included in the training samples in the training sample set as the input of the generation network, and use the sample comic style images corresponding to the input sample images as the expectations of the generation network.
- the output, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, the generation network and the discrimination network are trained, and the trained generation network is determined as a comic style conversion model.
- the above-mentioned executive body may first fix the parameters of any one of the generation network and the discrimination network (may be called the first network), and optimize the network with no fixed parameters (may be called the second network); then fix it The parameters of the second network are optimized for the first network. Continuously carry out the above iterations, so that the judgment network cannot distinguish whether the input image is generated by the generation network.
- the comic style image generated by the generation network is close to the sample comic style image, and the discrimination network cannot accurately distinguish the comic style image generated by the generation network from the sample comic style image (that is, the discrimination accuracy rate is 50%).
- the generation network is determined to be a comic style conversion model.
- the above-mentioned executive body can use the existing back propagation algorithm and gradient descent algorithm to train the generation network and the discriminant network.
- the parameters of the generative network and the discriminant network after each training will be adjusted, and the generative network and the discriminant network obtained after each parameter adjustment are used as the generative confrontation network used in the next training.
- the loss value can be determined by using the loss function, and the generation network and the discriminant network are iteratively trained according to the loss value to minimize the loss value determined during each iteration.
- the method adopted in this embodiment is to use the sample images included in the training samples in the training sample set as the input of the generation network, and use the sample comic style image corresponding to the input sample image As the expected output, the generation network is trained, and the actual output can be obtained for the sample image input for each training. Among them, the actual output is the comic style image actually output by the generated network. Then, the above-mentioned execution body can adopt the back propagation algorithm and the gradient descent algorithm to adjust the parameters of the generation network based on the actual output and the expected output, and use the generation network after each adjustment of the parameters as the generation network used for the next training.
- the above-mentioned execution subject may train the generation network and the discrimination network according to the following steps:
- the generation loss value used to characterize the difference between the comic style image output by the generation network and the corresponding sample comic style image ie, the sample comic style image corresponding to the input sample image
- the generated loss value can be the loss value determined according to the regression loss function.
- the regression loss function is generally expressed as L(y, y′), and the loss value obtained by it is used to represent the true value (that is, the loss value in this embodiment) The degree of inconsistency between the sample image) y and the predicted value (that is, the comic style image output by the generation network in this embodiment) y′.
- the generation loss value is minimized.
- a loss function for two classification for example, a cross-entropy loss function
- the generated loss value may be determined by any one of the following loss functions: L1 norm loss function, L2 norm loss function.
- the L1 norm loss function and the L2 norm loss function are the existing pixel-level loss functions, that is, the pixel is the basic unit to determine the difference between the pixels included in the two images, which can improve the use of the generated loss value characterization The accuracy of the differences between the images.
- the generation network and the discrimination network are trained. Specifically, the preset weights corresponding to the generated loss value and the discriminated loss value can be used to perform a weighted summation on the determined loss values to obtain the total loss value.
- the preset condition for example, less than or equal to the preset loss value threshold, or the total loss value no longer decreases
- the discrimination network may be a multi-scale discriminator, which is used to discriminate the input image and output at least two discrimination results.
- the discrimination result corresponds to the block image included in the comic style image input to the discrimination network and the sample comic style block image included in the sample comic style image, the discrimination result Used to determine whether the block image matches the corresponding sample comic style block image.
- the comic style image input to the judgment network is the comic style image output by the generated network, and the divided image included is obtained by dividing it.
- the sample comic style segmented image included in the sample comic style image is obtained by dividing the sample comic style image.
- each discrimination result corresponds to a block image and a sample comic style block image, and the corresponding relationship between the discrimination result and the block image and the sample comic block image is preset.
- the aforementioned at least two discrimination results may be a matrix with N rows and N columns, where N is a preset positive integer. Each element in the matrix is the result of discrimination.
- Each discrimination result corresponds to a block image and a sample comic block image.
- the discrimination network separately divides the input comic style image and the sample comic style image to obtain N ⁇ N block images and N ⁇ N comic style block images. There is a one-to-one correspondence between the block image and the comic style block image.
- the discriminant network sequentially discriminates the corresponding block image and the comic style block image, and obtains the corresponding discrimination result.
- the discrimination result can be the number 0 or 1. 0 can indicate that the corresponding block image does not match the comic style block image, and 1 can indicate that the corresponding block image matches the comic style block image.
- the discrimination accuracy rate is 50%).
- the above-mentioned multi-scale discriminator may be a convolutional neural network with a PatchGAN structure.
- PatchGAN can effectively identify high-frequency components in an image and improve the accuracy of discriminating details in the image. This helps to improve the accuracy of judging the comic style image and the sample comic style image generated by the generation network.
- FIG. 3 is a schematic diagram of an application scenario of the method for generating a comic style conversion model according to the present embodiment.
- the electronic device 301 first obtains the training sample set 302 locally.
- each training sample in the training sample set 302 includes a preset sample image and a sample comic style image corresponding to the sample image.
- the sample comic image is the image obtained by the technicians who change the color, shape, and add special effects of the sample image in advance.
- the electronic device 301 obtains the pre-established generation confrontation network 303 locally.
- the generation confrontation network 303 includes a generation network 3031 and a discrimination network 3032.
- the generation network 3031 is used to generate a comic style image using input sample images, and the discrimination network 3032 is used to determine whether the image input to the discrimination network is an image output by the generation network. Then, using a machine learning method, the sample images included in the training samples in the training sample set 302 are used as the input of the generation network, the sample comic style image corresponding to the input sample image is used as the expected output of the generation network, and the generation network The actual output comic style image and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, and the generation network and the discrimination network are trained.
- the comic style image output by the generation network is compared with the corresponding sample comic style image, and the judgment result of the comic style image output by the generation network and the corresponding sample comic style image through the discrimination network , Adjust the parameters of the generated network.
- the discrimination network cannot accurately distinguish the comic style image output by the generation network and the sample comic style image (that is, the discrimination accuracy rate is 50%)
- the generation network at this time is determined as the comic style conversion model 304.
- the method provided by the above-mentioned embodiments of the present disclosure obtains a training sample set and a pre-established generative confrontation network, and uses a machine learning method to use the sample image included in the training sample in the training sample set as the input of the generative network, which will be compared with the input
- the sample comic style image corresponding to the sample image is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, and the generation network and the discrimination network are processed Training, the generated network after training is determined as a comic style conversion model.
- the training of the generative adversarial network including the generative network and the discriminant network is added, which helps to reduce the generation of the model trained by the supervised training method.
- Over-fitting problem improve the generalization ability of the model, and improve the detail processing ability of image style conversion.
- Using the manga style conversion model obtained by training can reduce the jagged edges of the generated manga style image relative to the original image and reduce the image Contour distortion and other issues, thereby improving the display effect of the generated comic style image.
- FIG. 4 shows a process 400 of an embodiment of a method for generating a comic style image according to the present disclosure.
- the process 400 of the method for generating comic style images includes the following steps:
- Step 401 Obtain a target image.
- the execution subject of the method for generating comic style images may obtain the target image remotely or locally through a wired connection or a wireless connection.
- the target image is an image to be used to generate a comic style image.
- the target image may be an image obtained by photographing a target object by a camera included in the above-mentioned execution subject or a camera included in an electronic device communicatively connected with the above-mentioned execution subject, and the target object may be a person, thing, or scene within the shooting range of the camera. Wait.
- the foregoing target image is an image frame extracted from the target video.
- the target video may be a video whose image frames are to be converted into comic style images.
- the target video may be a video currently played on the execution subject, or a video currently being shot by a camera included in the execution subject or an electronic device communicatively connected with the execution subject.
- the above-mentioned execution master may extract an image frame from the target image as the target image.
- the target image may be an image frame included in the target video and currently displayed on the display screen included in the execution subject.
- Step 402 Input the target image into a pre-trained comic style conversion model to generate and output a comic style image corresponding to the target image.
- the above-mentioned execution subject may input the target image into a pre-trained comic style conversion model to generate and output a comic style image corresponding to the target image.
- the comic style conversion model is generated according to the method described in the embodiment corresponding to FIG. 2 above.
- the above-mentioned execution subject can output the generated comic style image in various ways.
- the generated comic style image may be displayed on a display screen included with the execution subject, or the generated comic style image may be sent to other electronic devices communicatively connected with the execution subject.
- the method provided in the above-mentioned embodiment of the present disclosure obtains a target image, inputs the target image into a comic style conversion model trained in advance according to the method described in the above-mentioned embodiment corresponding to FIG. 2 to generate a comic-style image corresponding to the target image and output it, using this
- the comic style conversion model can reduce the over-fitting problem of generating comic style images, and improve the effect of comic style conversion on the details in the image, and can reduce the image edge jagged of the generated comic style image relative to the original image. Image contour distortion and other issues, thereby improving the display effect of the generated comic style image.
- the present disclosure provides an embodiment of a device for generating a comic style conversion model, which is similar to the method embodiment shown in FIG.
- the device can be specifically applied to various electronic devices.
- the apparatus 500 for generating a comic style conversion model of this embodiment includes: a first obtaining unit 501 configured to obtain a set of training samples, where the training samples include preset sample images and A sample comic style image corresponding to the image; the second acquisition unit 502 is configured to acquire a pre-established generative confrontation network, wherein the generation of the confrontation network includes a generation network and a discrimination network, and the generation network is used to generate a comic style using the input sample image
- the discriminant network is used to distinguish the comic style image output by the generation network and the sample comic style image corresponding to the sample image of the input generation network;
- the training unit 503 is configured to use a machine learning method to include the training samples in the training sample set
- the sample image is used as the input of the generation network, the sample comic style image corresponding to the input sample image is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as The input of the discriminant network is trained, the generative
- the first obtaining unit 501 may obtain the training sample set remotely or locally through a wired connection or a wireless connection.
- the training samples include preset sample images and sample comic style images corresponding to the sample images.
- the sample image may be an image obtained by photographing a real person, object, scene, etc.
- the sample comic style image may be an image obtained by performing various processings on its corresponding sample image (for example, changing colors, shapes, and adding special effects to certain areas in the image), and the resulting image usually has a comic style.
- the character image, background image, etc. in the sample image are processed such as changing colors and adding lines to make them have a comic style.
- the corresponding relationship between the sample image and the sample comic style image is established in advance.
- the technician may process the sample image in advance for each sample image in the plurality of sample images, so as to determine the image obtained after the processing as the sample comic style image corresponding to the image.
- the second acquiring unit 502 may acquire a pre-established generative confrontation network locally or remotely.
- the generative confrontation network includes the generative network and the discriminant network.
- the generation network is used to generate a comic style image using the input sample image
- the discrimination network is used to distinguish the comic style image output by the generation network and the sample comic style image corresponding to the sample image input to the generation network.
- the above-mentioned generative confrontation network may be a generative confrontation network of various structures.
- the generative confrontation network may be a deep convolutional generation confrontation network (Deep Convolutional Generative Adversarial Network, DCGAN). It should be understood that the above-mentioned generative confrontation network may be an untrained generative confrontation network after initializing parameters, or a trained generative confrontation network.
- the generating network may be a convolutional neural network used for image processing (for example, a convolutional neural network with various structures including a convolution layer, a pooling layer, a depooling layer, and a deconvolution layer).
- the above-mentioned discriminant network may be a convolutional neural network (for example, a convolutional neural network of various structures including a fully connected layer, where the above-mentioned fully connected layer can implement a classification function).
- the discriminant network may also be other models for implementing classification functions, such as Support Vector Machine (SVM).
- SVM Support Vector Machine
- the discrimination network determines that the image is the image output by the generation network, it can output the label 1 (or 0) corresponding to the image; if it is determined that the image is not output by the generation network , You can output the label 0 (or 1) corresponding to the image. It should be noted that the discrimination network can also output other preset information, which is not limited to the values 1 and 0.
- the training unit 503 can use a machine learning method to use the sample images included in the training samples in the training sample set as the input to the generation network, and use the sample comic style images corresponding to the input sample images as the expectations of the generation network. Output, and use the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image as the input of the discrimination network, train the generation network and the discrimination network, and determine the generated network after training as the comic style conversion model.
- the above-mentioned training unit 503 may first fix the parameters of any one of the generation network and the discrimination network (may be called the first network), and optimize the network without fixed parameters (may be called the second network); and then Fix the parameters of the second network and optimize the first network. Continuously carry out the above iterations, so that the judgment network cannot distinguish whether the input image is generated by the generation network.
- the comic style image generated by the generation network is close to the sample comic style image, and the discrimination network cannot accurately distinguish the comic style image generated by the generation network from the sample comic style image (that is, the discrimination accuracy rate is 50%).
- the generation network is determined to be a comic style conversion model.
- the above-mentioned training unit 503 can use the existing back propagation algorithm and gradient descent algorithm to train the generation network and the discrimination network.
- the parameters of the generative network and the discriminant network after each training will be adjusted, and the generative network and the discriminant network obtained after each parameter adjustment are used as the generative confrontation network used in the next training.
- the loss value can be determined by using the loss function, and the generation network and the discriminant network are iteratively trained according to the loss value to minimize the loss value determined during each iteration.
- the method adopted in this embodiment is to use the sample images included in the training samples in the training sample set as the input of the generation network, and use the sample comic style image corresponding to the input sample image As the expected output, the generation network is trained, and the actual output can be obtained for the sample image input for each training. Among them, the actual output is the comic style image actually output by the generated network.
- the above-mentioned training unit 503 may adopt a back propagation algorithm and a gradient descent algorithm to adjust the parameters of the generation network based on the actual output and the expected output, and use the generation network after each adjustment of the parameters as the generation network used for the next training.
- the discriminant network is a multi-scale discriminator, used to discriminate the input image, and output at least two discriminating results, wherein, for the at least two discriminating results output
- the discrimination result which corresponds to the block image included in the image input to the discrimination network and the sample comic style block image included in the sample comic style image, is used to determine whether the block image matches the corresponding sample comic style block image.
- the training unit 503 may include: a determining module (not shown in the figure), configured to use a preset loss function to determine the comic style image and the corresponding sample comic style image used to characterize the network output The generation loss value of the difference of the discriminant network, and the discriminant loss value that determines the difference between the comic style image and the sample comic style image corresponding to the discriminant network and used to represent the actual output of the generation network of the input discriminant network; training module (not shown in the figure) , Is configured to train the generation network and the discrimination network based on the determined generation loss value and the discrimination loss value.
- the generated loss value is determined by any one of the following loss functions: L1 norm loss function, L2 norm loss function.
- the apparatus 500 acquires a training sample set and a pre-established generative confrontation network, and uses a machine learning method to use a sample image included in the training sample in the training sample set as the input of the generative network, and will be compared with the input
- the sample comic style image corresponding to the sample image of the generation network is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, and the generation network and the discrimination network Perform training and determine the trained generation network as a comic style conversion model.
- the training of the generative adversarial network including the generative network and the discriminant network is added, which helps to reduce the generation of the model trained by the supervised training method.
- Over-fitting problem improve the generalization ability of the model, and improve the detail processing ability of image style conversion.
- Using the manga style conversion model obtained by training can reduce the jagged edges of the generated manga style image relative to the original image and reduce the image Contour distortion and other issues, thereby improving the display effect of the generated comic style image.
- the present disclosure provides an embodiment of a device for generating comic style images, and the device embodiment corresponds to the method embodiment shown in FIG. 4 ,
- the device can be applied to various electronic equipment.
- the apparatus 600 for generating a comic style image of this embodiment includes: an image acquisition unit 601 configured to acquire a target image; an image generation unit 602 configured to input the target image into a pre-trained comic style
- the conversion model generates and outputs a comic style image corresponding to the target image.
- the comic style conversion model is generated according to the method described in the embodiment corresponding to FIG. 2 above.
- the image acquisition unit 601 can acquire the target image remotely or locally through a wired connection or a wireless connection.
- the target image is an image to be used to generate a comic style image.
- the target image may be an image obtained by photographing a target object by a camera included in the foregoing apparatus 600 or an electronic device included in an electronic device communicatively connected with the foregoing apparatus 600, and the target object may be a person, thing, or scene within the shooting range of the camera. Wait.
- the image generating unit 602 may input the target image into a pre-trained comic style conversion model to generate and output a comic style image corresponding to the target image.
- the comic style conversion model is generated according to the method described in the embodiment corresponding to FIG. 2 above.
- the above-mentioned image generating unit 602 can output the generated comic style image in various ways.
- the generated comic style image may be displayed on a display screen included with the execution subject, or the generated comic style image may be sent to other electronic devices communicatively connected with the execution subject.
- the target image is an image frame extracted from the target video.
- the apparatus 600 provided in the above-mentioned embodiment of the present disclosure acquires a target image, inputs the target image into the comic style conversion model trained in advance according to the method described in the above-mentioned embodiment corresponding to FIG. 2, and generates and outputs the comic style image corresponding to the target image.
- the comic style conversion model can reduce the over-fitting problem of generating comic style images, improve the effect of comic style conversion on details in the image, and reduce the jagged edges of the generated comic style image relative to the original image. Reduce the problem of image contour distortion, thereby improving the display effect of the generated comic style image.
- FIG. 7 shows a schematic structural diagram of an electronic device (such as the server or terminal device in FIG. 1) 700 suitable for implementing the embodiments of the present disclosure.
- Terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablets), PMPs (portable multimedia players), vehicle-mounted terminals ( For example, mobile terminals such as car navigation terminals and fixed terminals such as digital TVs and desktop computers.
- the electronic device shown in FIG. 7 is only an example, and should not bring any limitation to the function and scope of use of the embodiments of the present disclosure.
- the electronic device 700 may include a processing device (such as a central processing unit, a graphics processor, etc.) 701, which may be loaded into a random access device according to a program stored in a read-only memory (ROM) 702 or from a storage device 708.
- the program in the memory (RAM) 703 executes various appropriate actions and processing.
- various programs and data required for the operation of the electronic device 700 are also stored.
- the processing device 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704.
- An input/output (I/O) interface 705 is also connected to the bus 704.
- the following devices can be connected to the I/O interface 705: including input devices 706 such as touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; including, for example, liquid crystal display (LCD), speakers, vibration An output device 707 such as a device; a storage device 708 such as a magnetic tape and a hard disk; and a communication device 709.
- the communication device 709 may allow the electronic device 700 to perform wireless or wired communication with other devices to exchange data.
- FIG. 7 shows an electronic device 700 having various devices, it should be understood that it is not required to implement or have all the illustrated devices. It may alternatively be implemented or provided with more or fewer devices. Each block shown in FIG. 7 may represent one device, or may represent multiple devices as needed.
- the process described above with reference to the flowchart can be implemented as a computer software program.
- the embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart.
- the computer program may be downloaded and installed from the network through the communication device 709, or installed from the storage device 708, or installed from the ROM 702.
- the processing device 701 the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
- the computer-readable medium described in the embodiment of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two.
- the computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), optical fiber, portable compact disk read only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.
- the computer-readable storage medium may be any tangible medium that contains or stores a program, and the program may be used by or in combination with an instruction execution system, apparatus, or device.
- the computer-readable signal medium may include a data signal propagated in a baseband or as a part of a carrier wave, and a computer-readable program code is carried therein. This propagated data signal can take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing.
- the computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium.
- the computer-readable signal medium may send, propagate, or transmit the program for use by or in combination with the instruction execution system, apparatus, or device .
- the program code contained on the computer-readable medium can be transmitted by any suitable medium, including but not limited to: wire, optical cable, RF (Radio Frequency), etc., or any suitable combination of the above.
- the above-mentioned computer-readable medium may be included in the above-mentioned electronic device; or it may exist alone without being assembled into the electronic device.
- the above-mentioned computer-readable medium carries one or more programs.
- the electronic device is caused to: obtain a training sample set, wherein the training sample includes a preset sample image, and The sample comic style image corresponding to the sample image; obtain a pre-established generative confrontation network, where the generative confrontation network includes a generation network and a discriminant network.
- the generation network is used to generate a comic style image using the input sample image
- the discriminant network is used to differentiate The comic style image output by the network and the sample comic style image corresponding to the sample image of the input generation network; using machine learning methods, the sample images included in the training samples in the training sample set are used as the input of the generation network, which will correspond to the input sample image
- the sample comic style image of the generation network is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, and the generation network and the discrimination network are trained.
- the generated network after training is determined to be the comic style conversion model.
- the electronic device when the above-mentioned one or more programs are executed by the electronic device, the electronic device is caused to: acquire the target image; input the target image into the pre-trained comic style conversion model to generate and output the comic style image corresponding to the target image.
- the computer program code used to perform the operations of the embodiments of the present disclosure can be written in one or more programming languages or a combination thereof, the programming languages including object-oriented programming languages such as Java, Smalltalk, C++, It also includes conventional procedural programming languages-such as "C" language or similar programming languages.
- the program code can be executed entirely on the user's computer, partly on the user's computer, executed as an independent software package, partly on the user's computer and partly executed on a remote computer, or entirely executed on the remote computer or server.
- the remote computer can be connected to the user's computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to pass Internet connection).
- LAN local area network
- WAN wide area network
- each block in the flowchart or block diagram can represent a module, program segment, or part of code, and the module, program segment, or part of code contains one or more for realizing the specified logic function Executable instructions.
- the functions marked in the block may also occur in a different order from the order marked in the drawings. For example, two blocks shown in succession can actually be executed substantially in parallel, or they can sometimes be executed in the reverse order, depending on the functions involved.
- each block in the block diagram and/or flowchart, and the combination of the blocks in the block diagram and/or flowchart can be implemented by a dedicated hardware-based system that performs the specified functions or operations Or it can be realized by a combination of dedicated hardware and computer instructions.
- the units involved in the embodiments described in the present disclosure may be implemented in a software manner, and may also be implemented in a hardware manner.
- the described unit may also be provided in the processor, for example, it may be described as: a processor includes a first acquiring unit, a second acquiring unit, and a training unit. Wherein, the names of these units do not constitute a limitation on the unit itself under certain circumstances.
- the first obtaining unit can also be described as "a unit for obtaining a training sample set.”
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- General Physics & Mathematics (AREA)
- General Health & Medical Sciences (AREA)
- Molecular Biology (AREA)
- Biophysics (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Evolutionary Computation (AREA)
- Artificial Intelligence (AREA)
- Biomedical Technology (AREA)
- Computing Systems (AREA)
- General Engineering & Computer Science (AREA)
- Life Sciences & Earth Sciences (AREA)
- Mathematical Physics (AREA)
- Software Systems (AREA)
- Health & Medical Sciences (AREA)
- Image Analysis (AREA)
- Image Processing (AREA)
Abstract
Disclosed are a method and apparatus for generating a cartoon style conversion model. A particular embodiment of the method comprises: acquiring a training sample set; acquiring a pre-established generative adversarial network; and utilizing a machine learning method to take sample images comprised in training samples in the training sample set as inputs of a generation network, take sample cartoon style images corresponding to the input sample images as expected outputs of the generation network and take cartoon style images actually output by the generation network and the sample cartoon style images corresponding to the input sample images as inputs of a judgment network, training the generation network and the judgment network, and determining the trained generation network to be a cartoon style conversion model. According to the embodiment, the problems such as image edge sawteeth and image contour deformation, generated relative to original images, of the generated cartoon style images can be reduced, such that the display effect of the generated cartoon style images is improved.
Description
相关申请的交叉引用Cross references to related applications
本申请基于申请号为201910090075.6、申请日为2019年01月30日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。This application is filed based on a Chinese patent application with an application number of 201910090075.6 and an application date of January 30, 2019, and claims the priority of the Chinese patent application. The entire content of the Chinese patent application is hereby incorporated by reference into this application.
本公开的实施例涉及计算机技术领域,具体涉及用于生成漫画风格转换模型的方法和装置。The embodiments of the present disclosure relate to the field of computer technology, and in particular to a method and apparatus for generating a comic style conversion model.
目前,一些图像处理软件可以对图像进行处理,将图像转换为其他风格的图像。例如对图像中的某些区域进行改色、改形状等。这些软件通常包括用于将图像转换为其他风格的图像的模型。模型的训练过程通常是输入一幅图像,将该图像与其对应的其他风格的图像进行比较,根据这两个图像的差异,优化模型的参数。At present, some image processing software can process images and convert them into images of other styles. For example, change the color and shape of certain areas in the image. These software usually include models for converting images into other styles of images. The training process of the model usually involves inputting an image, comparing the image with its corresponding images of other styles, and optimizing the parameters of the model according to the difference between the two images.
发明内容Summary of the invention
本公开的实施例提出了用于生成漫画风格转换模型的方法和装置,以及用于生成漫画风格图像的方法和装置。The embodiments of the present disclosure propose a method and apparatus for generating a comic style conversion model, and a method and apparatus for generating a comic style image.
第一方面,本公开的实施例提供了一种用于生成漫画风格转换模型的方法,该方法包括:获取训练样本集合,其中,训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像;获取预先建立的生成对抗网络,其中,生成对抗网络包括生成网络和判别网络,生成网络用于利用所输入的样本图像生成漫画风格图像,判别网络用于区分生成网络输出的漫画风格图像和输入生成网络的样本图像对应的样本漫画风格图像;利用机器学习方法,将训练样本集合中的训练 样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。In a first aspect, an embodiment of the present disclosure provides a method for generating a comic style conversion model. The method includes: obtaining a training sample set, wherein the training sample includes a preset sample image and a sample corresponding to the sample image Comic style images; obtain a pre-established generative confrontation network, where the generative confrontation network includes a generation network and a discrimination network. The generation network is used to generate comic style images from the input sample images, and the discrimination network is used to distinguish the comic style output of the generation network The image and the sample comic style image corresponding to the sample image of the input generation network; using machine learning methods, the sample image included in the training sample in the training sample set is used as the input of the generation network, and the sample comic style image corresponding to the input sample image As the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, the generation network and the discrimination network are trained, and the trained generation network Determined as a manga style conversion model.
在一些实施例中,判别网络为多尺度判别器,用于对输入的图像进行判别,输出至少两个判别结果,其中,对于所输出的至少两个判别结果中的判别结果,该判别结果对应于输入判别网络的图像包括的分块图像和样本漫画风格图像包括的样本漫画风格分块图像,用于确定分块图像和对应的样本漫画风格分块图像是否匹配。In some embodiments, the discriminant network is a multi-scale discriminator, which is used to discriminate the input image and output at least two discriminant results, wherein, for the discriminant result of the at least two discriminant results output, the discriminant result corresponds to The block image included in the image input to the discrimination network and the sample comic style block image included in the sample comic style image are used to determine whether the block image and the corresponding sample comic style block image match.
在一些实施例中,对生成网络和判别网络进行训练,包括:利用预设的损失函数,确定用于表征生成网络输出的漫画风格图像与对应的样本漫画风格图像的差异的生成损失值,以及确定判别网络对应的、用于表征输入判别网络的生成网络实际输出的漫画风格图像与样本漫画风格图像的差异的判别损失值;基于所确定的生成损失值和判别损失值,对生成网络和判别网络进行训练。In some embodiments, training the generation network and the discrimination network includes: using a preset loss function to determine the generation loss value that is used to characterize the difference between the comic style image output by the generation network and the corresponding sample comic style image, and Determine the discriminant loss value corresponding to the discriminant network, which is used to characterize the difference between the comic style image actually output by the generation network of the input discriminant network and the sample comic style image; based on the determined generation loss value and discriminant loss value, the generation network is judged The network is trained.
在一些实施例中,生成损失值由以下任一种损失函数确定得到:L1范数损失函数、L2范数损失函数。In some embodiments, the generated loss value is determined by any one of the following loss functions: L1 norm loss function, L2 norm loss function.
第二方面,本公开的实施例提供了一种用于生成漫画风格图像的方法,该方法包括:获取目标图像;将目标图像输入预先训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出,其中,漫画风格转换模型是根据上述第一方面中任一实施例描述的方法生成的。In a second aspect, an embodiment of the present disclosure provides a method for generating a comic style image, the method includes: acquiring a target image; inputting the target image into a pre-trained comic style conversion model to generate a comic style image corresponding to the target image And output, wherein the comic style conversion model is generated according to the method described in any one of the embodiments of the first aspect.
在一些实施例中,目标图像是从目标视频中提取的图像帧。In some embodiments, the target image is an image frame extracted from the target video.
第三方面,本公开的实施例提供了一种用于生成漫画风格转换模型的装置,该装置包括:第一获取单元,被配置成获取训练样本集合,其中,训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像;第二获取单元,被配置成获取预先建立的生成对抗网络,其中,生成对抗网络包括生成网络和判别网络,生成网络用于利用所输入的样本图像生成漫画风格图像,判别网络用于区分生成网络输出 的漫画风格图像和输入生成网络的样本图像对应的样本漫画风格图像;训练单元,被配置成利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。In a third aspect, an embodiment of the present disclosure provides an apparatus for generating a comic style conversion model. The apparatus includes: a first acquiring unit configured to acquire a training sample set, wherein the training sample includes a preset sample image , And a sample comic style image corresponding to the sample image; the second acquisition unit is configured to acquire a pre-established generative confrontation network, wherein the generative confrontation network includes a generation network and a discriminant network, and the generation network is used to use the input sample image Generate comic style images, and the discrimination network is used to distinguish between the comic style images output by the generation network and the sample comic style images corresponding to the sample images of the input generation network; the training unit is configured to use machine learning methods to combine the training samples in the training sample set The included sample image is used as the input of the generation network, the sample comic style image corresponding to the input sample image is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style corresponding to the input sample image The image is used as the input of the discriminant network, the generation network and the discriminant network are trained, and the trained generation network is determined as the comic style conversion model.
在一些实施例中,判别网络为多尺度判别器,用于对输入的图像进行判别,输出至少两个判别结果,其中,对于所输出的至少两个判别结果中的判别结果,该判别结果对应于输入判别网络的图像包括的分块图像和样本漫画风格图像包括的样本漫画风格分块图像,用于确定分块图像和对应的样本漫画风格分块图像是否匹配。In some embodiments, the discriminant network is a multi-scale discriminator, which is used to discriminate the input image and output at least two discriminant results, wherein, for the discriminant result of the at least two discriminant results output, the discriminant result corresponds to The block image included in the image input to the discrimination network and the sample comic style block image included in the sample comic style image are used to determine whether the block image and the corresponding sample comic style block image match.
在一些实施例中,训练单元包括:确定模块,被配置成利用预设的损失函数,确定用于表征生成网络输出的漫画风格图像与对应的样本漫画风格图像的差异的生成损失值,以及确定判别网络对应的、用于表征输入判别网络的生成网络实际输出的漫画风格图像与样本漫画风格图像的差异的判别损失值;训练模块,被配置成基于所确定的生成损失值和判别损失值,对生成网络和判别网络进行训练。In some embodiments, the training unit includes: a determination module configured to use a preset loss function to determine a generation loss value that is used to characterize the difference between the comic style image output by the generation network and the corresponding sample comic style image, and determine The discriminant loss value corresponding to the discriminant network and used to characterize the difference between the comic style image actually output by the generation network of the input discriminant network and the sample comic style image; the training module is configured to be based on the determined generation loss value and discriminant loss value, Train the generation network and the discriminant network.
在一些实施例中,生成损失值由以下任一种损失函数确定得到:L1范数损失函数、L2范数损失函数。In some embodiments, the generated loss value is determined by any one of the following loss functions: L1 norm loss function, L2 norm loss function.
第四方面,本公开的实施例提供了一种用于生成漫画风格图像的装置,该装置包括:图像获取单元,被配置成获取目标图像;图像生成单元,被配置成将目标图像输入预先训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出,其中,漫画风格转换模型是根据上述第一方面中任一实施例描述的方法生成的。In a fourth aspect, an embodiment of the present disclosure provides an apparatus for generating a comic style image. The apparatus includes: an image acquisition unit configured to acquire a target image; an image generation unit configured to input the target image into pre-training The comic style conversion model generates and outputs a comic style image corresponding to the target image, where the comic style conversion model is generated according to the method described in any one of the embodiments of the first aspect.
在一些实施例中,目标图像是从目标视频中提取的图像帧。In some embodiments, the target image is an image frame extracted from the target video.
第五方面,本公开的实施例提供了一种电子设备,该电子设备包括:一个或多个处理器;存储装置,其上存储有一个或多个程序;当一个或多个程序被一个或多个处理器执行,使得一个或多个处理器实现如第一方面或第二方面中任一实现方式描述的方法。In a fifth aspect, the embodiments of the present disclosure provide an electronic device that includes: one or more processors; a storage device on which one or more programs are stored; when one or more programs are Multiple processors execute, so that one or more processors implement the method described in any one of the first aspect or the second aspect.
第六方面,本公开的实施例提供了一种计算机可读介质,其上存储有计算机程序,该计算机程序被处理器执行时实现如第一方面或第二方面中任一实现方式描述的方法。In a sixth aspect, the embodiments of the present disclosure provide a computer-readable medium on which a computer program is stored, and when the computer program is executed by a processor, the method described in any one of the first aspect or the second aspect is implemented .
本公开的实施例提供的用于生成漫画风格转换模型的方法和装置,通过获取训练样本集合和预先建立的生成对抗网络,利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。从而实现了利用有监督的训练方式对生成网络进行训练的基础上,增加了对包括生成网络和判别网络的生成对抗网络的训练,有助于减少利用有监督的训练方式训练得到的模型产生的过拟合问题,提高模型的泛化能力,以及提高图像风格转换的细节处理能力,使用训练得到的漫画风格转换模型,可以减少生成的漫画风格图像相对于原始图像产生的图像边缘锯齿、图像轮廓变形等问题,从而改善生成的漫画风格图像的显示效果。The method and device for generating a comic style conversion model provided by the embodiments of the present disclosure are obtained by acquiring a training sample set and a pre-established generating confrontation network, and using a machine learning method, the sample image included in the training sample in the training sample set is taken as The input of the generation network, the sample comic style image corresponding to the input sample image is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the judgment network Input, train the generation network and the discriminant network, and determine the trained generation network as the comic style conversion model. In this way, on the basis of training the generative network using the supervised training method, the training of the generative adversarial network including the generative network and the discriminant network is added, which helps to reduce the generation of the model trained by the supervised training method. Over-fitting problem, improve the generalization ability of the model, and improve the detailed processing ability of image style conversion. Using the cartoon style conversion model obtained by training can reduce the image edge jagged and image contour generated by the generated comic style image relative to the original image Deformation and other issues, thereby improving the display effect of the generated comic style image.
通过阅读参照以下附图所作的对非限制性实施例所作的详细描述,本公开的其它特征、目的和优点将会变得更明显:By reading the detailed description of the non-limiting embodiments with reference to the following drawings, other features, purposes and advantages of the present disclosure will become more apparent:
图1是本公开的一个实施例可以应用于其中的示例性系统架构图;Fig. 1 is an exemplary system architecture diagram in which an embodiment of the present disclosure can be applied;
图2是根据本公开的实施例的用于生成漫画风格转换模型的方法的一个实施例的流程图;2 is a flowchart of an embodiment of a method for generating a comic style conversion model according to an embodiment of the present disclosure;
图3是根据本公开的实施例的用于生成漫画风格转换模型的方法的一个应用场景的示意图;3 is a schematic diagram of an application scene of the method for generating a comic style conversion model according to an embodiment of the present disclosure;
图4是根据本公开的实施例的用于生成漫画风格图像的方法的一个实施例的流程图;4 is a flowchart of an embodiment of a method for generating a comic style image according to an embodiment of the present disclosure;
图5是根据本公开的实施例的用于生成漫画风格转换模型的装置 的一个实施例的结构示意图;Fig. 5 is a schematic structural diagram of an embodiment of an apparatus for generating a comic style conversion model according to an embodiment of the present disclosure;
图6是根据本公开的实施例的用于生成漫画风格图像的装置的一个实施例的结构示意图;FIG. 6 is a schematic structural diagram of an embodiment of an apparatus for generating comic style images according to an embodiment of the present disclosure;
图7是适于用来实现本公开的实施例的电子设备的结构示意图。FIG. 7 is a schematic structural diagram of an electronic device suitable for implementing embodiments of the present disclosure.
下面结合附图和实施例对本公开作进一步的详细说明。可以理解的是,此处所描述的具体实施例仅仅用于解释相关公开,而非对该公开的限定。另外还需要说明的是,为了便于描述,附图中仅示出了与有关公开相关的部分。The present disclosure will be further described in detail below in conjunction with the drawings and embodiments. It can be understood that the specific embodiments described here are only used to explain the relevant disclosure, but not to limit the disclosure. In addition, it should be noted that, for ease of description, only the parts related to the relevant disclosure are shown in the drawings.
需要说明的是,在不冲突的情况下,本公开中的实施例及实施例中的特征可以相互组合。下面将参考附图并结合实施例来详细说明本公开。It should be noted that the embodiments in the present disclosure and the features in the embodiments can be combined with each other if there is no conflict. Hereinafter, the present disclosure will be described in detail with reference to the drawings and in conjunction with embodiments.
图1示出了可以应用本公开的实施例的用于生成漫画风格转换模型的方法或用于生成漫画风格转换模型的装置,以及用于生成漫画风格图像的方法或用于生成漫画风格图像的装置的示例性系统架构100。FIG. 1 shows a method for generating a comic style conversion model or an apparatus for generating a comic style conversion model to which an embodiment of the present disclosure can be applied, and a method for generating a comic style image or a method for generating a comic style image An exemplary system architecture 100 of the device.
如图1所示,系统架构100可以包括终端设备101、102、103,网络104和服务器105。网络104用以在终端设备101、102、103和服务器105之间提供通信链路的介质。网络104可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables.
用户可以使用终端设备101、102、103通过网络104与服务器105交互,以接收或发送消息等。终端设备101、102、103上可以安装有各种通讯客户端应用,例如图像处理类应用、网页浏览器应用、即时通信工具、社交平台软件等。The user can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, and so on. Various communication client applications, such as image processing applications, web browser applications, instant messaging tools, and social platform software, may be installed on the terminal devices 101, 102, and 103.
终端设备101、102、103可以是硬件,也可以是软件。当终端设备101、102、103为硬件时,可以是各种电子设备。当终端设备101、102、103为软件时,可以安装在上述电子设备中。其可以实现成多个软件或软件模块(例如用来提供分布式服务的软件或软件模块),也可以实现成单个软件或软件模块。在此不做具体限定。The terminal devices 101, 102, and 103 may be hardware or software. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices. When the terminal devices 101, 102, and 103 are software, they can be installed in the aforementioned electronic devices. It can be implemented as multiple software or software modules (for example, software or software modules used to provide distributed services), or as a single software or software module. No specific restrictions are made here.
服务器105可以是提供各种服务的服务器,例如对终端设备101、102、103上传的训练样本集合进行处理的后台服务器。后台服务器可以使用获取到的训练样本集合对生成对抗网络进行训练,从而得到漫画风格转换模型。此外,后台服务器还可以使用漫画风格转换模型对输入的图像进行处理,得到漫画风格图像及输出。The server 105 may be a server that provides various services, for example, a back-end server that processes a collection of training samples uploaded by the terminal devices 101, 102, and 103. The background server can use the acquired training sample set to train the generative adversarial network to obtain a comic style conversion model. In addition, the background server can also use the comic style conversion model to process the input image to obtain the comic style image and output.
需要说明的是,本公开的实施例所提供的用于生成漫画风格转换模型的方法可以由服务器105执行,也可以由终端设备101、102、103执行,相应地,用于生成漫画风格转换模型的装置可以设置于服务器105中,也可以设置于终端设备101、102、103中。此外,本公开的实施例所提供的用于生成漫画风格图像的方法可以由服务器105执行,也可以由终端设备101、102、103执行,相应地,用于生成漫画风格图像的装置可以设置于服务器105中,也可以设置于终端设备101、102、103中。It should be noted that the method for generating a comic style conversion model provided by the embodiments of the present disclosure can be executed by the server 105, or can be executed by the terminal devices 101, 102, 103, and accordingly, used to generate the comic style conversion model The device of can be set in the server 105 or in the terminal equipment 101, 102, 103. In addition, the method for generating comic style images provided by the embodiments of the present disclosure can be executed by the server 105, and can also be executed by the terminal devices 101, 102, 103. Accordingly, the device for generating comic style images can be set in The server 105 may also be provided in the terminal devices 101, 102, 103.
需要说明的是,服务器可以是硬件,也可以是软件。当服务器为硬件时,可以实现成多个服务器组成的分布式服务器集群,也可以实现成单个服务器。当服务器为软件时,可以实现成多个软件或软件模块(例如用来提供分布式服务的软件或软件模块),也可以实现成单个软件或软件模块。在此不做具体限定。It should be noted that the server can be hardware or software. When the server is hardware, it can be implemented as a distributed server cluster composed of multiple servers, or as a single server. When the server is software, it can be implemented as multiple software or software modules (for example, software or software modules for providing distributed services), or as a single software or software module. No specific restrictions are made here.
应该理解,图1中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。在训练模型所需的训练样本集合或待将其转换为漫画风格图像的目标图像不需要从远程获取的情况下,上述系统架构可以不包括网络,而只包括服务器或终端设备。It should be understood that the numbers of terminal devices, networks, and servers in FIG. 1 are merely illustrative. According to implementation needs, there can be any number of terminal devices, networks and servers. In the case that the training sample set required for training the model or the target image to be converted into a comic-style image does not need to be obtained remotely, the foregoing system architecture may not include a network, but only a server or terminal device.
继续参考图2,示出了根据本公开的用于生成漫画风格转换模型的方法的一个实施例的流程200。该用于生成漫画风格转换模型的方法,包括以下步骤:Continuing to refer to FIG. 2, a process 200 of an embodiment of the method for generating a comic style conversion model according to the present disclosure is shown. The method for generating a comic style conversion model includes the following steps:
步骤201,获取训练样本集合。Step 201: Obtain a training sample set.
在本实施例中,用于生成漫画风格转换模型的方法的执行主体(例如图1所示的服务器或终端设备)可以通过有线连接方式或者无线连 接方式从远程,或从本地获取训练样本集合。其中,训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像。通常,样本图像可以是对真实的人物、物品、景物等进行拍摄得到的图像。样本漫画风格图像可以是对其对应的样本图像进行各种处理(例如对图像中的某些区域进行改色、改形状、添加特效等处理)后得到的图像,所得到的图像通常具有漫画风格。例如将样本图像中的人物图像、背景图像等进行改色、添加线条等处理,使其具有漫画风格。样本图像和样本漫画风格图像的对应关系是预先建立的。例如,技术人员可以预先针对多个样本图像中的每个样本图像,对该样本图像进行处理,从而将处理后所得到的图像确定为与该图像对应的样本漫画风格图像。In this embodiment, the executor of the method for generating a comic style conversion model (for example, the server or terminal device shown in FIG. 1) can obtain the training sample collection remotely or locally through a wired connection or a wireless connection. The training samples include preset sample images and sample comic style images corresponding to the sample images. Generally, the sample image may be an image obtained by photographing a real person, object, scene, etc. The sample comic style image may be an image obtained by performing various processings on its corresponding sample image (for example, changing colors, shapes, and adding special effects to certain areas in the image), and the resulting image usually has a comic style. For example, the character image, background image, etc. in the sample image are processed such as changing colors and adding lines to make them have a comic style. The corresponding relationship between the sample image and the sample comic style image is established in advance. For example, the technician may process the sample image in advance for each sample image in the plurality of sample images, so as to determine the image obtained after the processing as the sample comic style image corresponding to the image.
步骤202,获取预先建立的生成对抗网络。Step 202: Obtain a pre-established generative confrontation network.
在本实施例中,上述执行主体可以从本地或从远程获取预先建立的生成对抗网络。其中,生成对抗网络包括生成网络和判别网络。生成网络用于利用所输入的样本图像生成漫画风格图像,判别网络用于区分生成网络输出的漫画风格图像和输入生成网络的样本图像对应的样本漫画风格图像。上述生成对抗网络可以是各种结构的生成对抗网络。例如,生成式对抗网络可以是深度卷积生成对抗网络(Deep Convolutional Generative Adversarial Network,DCGAN)。应当理解,上述生成对抗网络可以是未经训练的、初始化参数后的生成对抗网络,也可以是已经训练过的生成对抗网络。In this embodiment, the above-mentioned execution subject may obtain a pre-established generational confrontation network locally or remotely. Among them, the generative confrontation network includes the generative network and the discriminant network. The generation network is used to generate a comic style image using the input sample image, and the discrimination network is used to distinguish the comic style image output by the generation network and the sample comic style image corresponding to the sample image input to the generation network. The above-mentioned generative confrontation network may be a generative confrontation network of various structures. For example, the generative confrontation network may be a deep convolutional generation confrontation network (Deep Convolutional Generative Adversarial Network, DCGAN). It should be understood that the above-mentioned generative confrontation network may be an untrained generative confrontation network after initializing parameters, or a trained generative confrontation network.
需要说明的是,生成网络可以是用于进行图像处理的卷积神经网络(例如包含卷积层、池化层、反池化层、反卷积层的各种结构的卷积神经网络)。上述判别网络可以是卷积神经网络(例如包含全连接层的各种结构的卷积神经网络,其中,上述全连接层可以实现分类功能)。此外,判别网络也可以是用于实现分类功能的其他模型,例如支持向量机(Support Vector Machine,SVM)。此处,针对输入判别网络的每个图像,判别网络若判定该图像是生成网络所输出的图像,则可以输出对应于该图像的标签1(或0);若判定该图像不是生成网络所输出的图像,则可以输出对应于该图像的标签0(或1)。需要说明的是, 判别网络也可以输出其他预先设置的信息,不限于数值1和0。It should be noted that the generating network may be a convolutional neural network used for image processing (for example, a convolutional neural network with various structures including a convolution layer, a pooling layer, a depooling layer, and a deconvolution layer). The above-mentioned discriminant network may be a convolutional neural network (for example, a convolutional neural network of various structures including a fully connected layer, where the above-mentioned fully connected layer can implement a classification function). In addition, the discriminant network may also be other models for implementing classification functions, such as Support Vector Machine (SVM). Here, for each image input to the discrimination network, if the discrimination network determines that the image is the image output by the generation network, it can output the label 1 (or 0) corresponding to the image; if it is determined that the image is not output by the generation network , You can output the label 0 (or 1) corresponding to the image. It should be noted that the discrimination network can also output other preset information, which is not limited to the values 1 and 0.
步骤203,利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。Step 203: Using a machine learning method, the sample images included in the training samples in the training sample set are used as the input of the generation network, the sample comic style images corresponding to the input sample images are used as the expected output of the generation network, and the actual network is generated. The output comic style image and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, the generation network and the discrimination network are trained, and the trained generation network is determined as the comic style conversion model.
在本实施例中,上述执行主体可以利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。In this embodiment, the above-mentioned execution subject can use a machine learning method to use the sample images included in the training samples in the training sample set as the input of the generation network, and use the sample comic style images corresponding to the input sample images as the expectations of the generation network. The output, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, the generation network and the discrimination network are trained, and the trained generation network is determined as a comic style conversion model.
具体地,上述执行主体可以首先固定生成网络和判别网络中的任一种网络(可称为第一网络)的参数,对未固定参数的网络(可称为第二网络)进行优化;再固定第二网络的参数,对第一网络进行优化。不断进行上述迭代,使判别网络无法区分输入的图像是否是生成网络所生成的。此时,生成网络所生成的漫画风格图像与样本漫画风格图像接近,判别网络无法准确区分生成网络生成的漫画风格图像和样本漫画风格图像(即判别准确率为50%),可以将此时的生成网络确定为漫画风格转换模型。通常,上述执行主体可以利用现有的反向传播算法和梯度下降算法对生成网络和判别网络进行训练。每次训练后的生成网络和判别网络的参数会被调整,将每次调整参数后得到的生成网络和判别网络作为下次训练所使用的生成对抗网络。训练过程中,可以通过使用损失函数确定损失值,根据损失值迭代地训练生成网络和判别网络,以使每次迭代运算时确定的损失值最小。Specifically, the above-mentioned executive body may first fix the parameters of any one of the generation network and the discrimination network (may be called the first network), and optimize the network with no fixed parameters (may be called the second network); then fix it The parameters of the second network are optimized for the first network. Continuously carry out the above iterations, so that the judgment network cannot distinguish whether the input image is generated by the generation network. At this time, the comic style image generated by the generation network is close to the sample comic style image, and the discrimination network cannot accurately distinguish the comic style image generated by the generation network from the sample comic style image (that is, the discrimination accuracy rate is 50%). The generation network is determined to be a comic style conversion model. Generally, the above-mentioned executive body can use the existing back propagation algorithm and gradient descent algorithm to train the generation network and the discriminant network. The parameters of the generative network and the discriminant network after each training will be adjusted, and the generative network and the discriminant network obtained after each parameter adjustment are used as the generative confrontation network used in the next training. In the training process, the loss value can be determined by using the loss function, and the generation network and the discriminant network are iteratively trained according to the loss value to minimize the loss value determined during each iteration.
需要说明的是,在对生成网络进行训练时,本实施例采用的方式是将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为期望输出,对生成网络进行训练,针对每次训练输入的样本图像,可以得到实际输 出。其中,实际输出是生成网络实际输出的漫画风格图像。然后,上述执行主体可以采用反向传播算法和梯度下降算法,基于实际输出和期望输出,调整生成网络的参数,将每次调整参数后的生成网络作为下次训练所使用的生成网络。It should be noted that when training the generation network, the method adopted in this embodiment is to use the sample images included in the training samples in the training sample set as the input of the generation network, and use the sample comic style image corresponding to the input sample image As the expected output, the generation network is trained, and the actual output can be obtained for the sample image input for each training. Among them, the actual output is the comic style image actually output by the generated network. Then, the above-mentioned execution body can adopt the back propagation algorithm and the gradient descent algorithm to adjust the parameters of the generation network based on the actual output and the expected output, and use the generation network after each adjustment of the parameters as the generation network used for the next training.
在本实施例的一些可选的实现方式中,上述执行主体可以按照如下步骤对生成网络和判别网络进行训练:In some optional implementation manners of this embodiment, the above-mentioned execution subject may train the generation network and the discrimination network according to the following steps:
首先,利用预设的损失函数,确定用于表征生成网络输出的漫画风格图像与对应的样本漫画风格图像(即与输入的样本图像对应的样本漫画风格图像)的差异的生成损失值,以及确定用于表征输入判别网络的、生成网络实际输出的漫画风格图像与样本漫画风格图像的差异的判别损失值。Firstly, using a preset loss function, determine the generation loss value used to characterize the difference between the comic style image output by the generation network and the corresponding sample comic style image (ie, the sample comic style image corresponding to the input sample image), and determine It is used to characterize the discriminant loss value of the difference between the comic style image actually output by the generated network and the sample comic style image input to the discriminant network.
通常,生成损失值可以是根据回归损失函数确定的损失值,回归损失函数的一般表示为L(y,y′),利用其所得到的损失值用于表征真实值(即本实施例中的样本图像)y和预测值(即本实施例中的生成网络输出的漫画风格图像)y′之间不一致的程度。训练时,使生成损失值达到最小。此外,可以使用用于二分类的损失函数(例如交叉熵损失函数)确定判别损失值。Generally, the generated loss value can be the loss value determined according to the regression loss function. The regression loss function is generally expressed as L(y, y′), and the loss value obtained by it is used to represent the true value (that is, the loss value in this embodiment) The degree of inconsistency between the sample image) y and the predicted value (that is, the comic style image output by the generation network in this embodiment) y′. During training, the generation loss value is minimized. In addition, a loss function for two classification (for example, a cross-entropy loss function) can be used to determine the discriminative loss value.
可选的,生成损失值可以由以下任一种损失函数确定得到:L1范数损失函数、L2范数损失函数。其中,L1范数损失函数和L2范数损失函数是现有的像素级的损失函数,即以像素为基本单元,确定两个图像包括的像素之间的差异,从而可以提高利用生成损失值表征图像之间的差异的准确性。Optionally, the generated loss value may be determined by any one of the following loss functions: L1 norm loss function, L2 norm loss function. Among them, the L1 norm loss function and the L2 norm loss function are the existing pixel-level loss functions, that is, the pixel is the basic unit to determine the difference between the pixels included in the two images, which can improve the use of the generated loss value characterization The accuracy of the differences between the images.
然后,基于所确定的生成损失值和判别损失值,对生成网络和判别网络进行训练。具体地,可以利用预设的、生成损失值和判别损失值分别对应的权重,对所确定的各个损失值进行加权求和,得到总损失值。训练时,不断地调整生成网络和判别网络的参数,使得总损失值逐渐减小,当总损失值满足预设条件(例如小于等于预设的损失值阈值,或者总损失值不再减小)时,确定成对抗网络训练完成。Then, based on the determined generation loss value and discrimination loss value, the generation network and the discrimination network are trained. Specifically, the preset weights corresponding to the generated loss value and the discriminated loss value can be used to perform a weighted summation on the determined loss values to obtain the total loss value. During training, constantly adjust the parameters of the generation network and the discrimination network, so that the total loss value gradually decreases, when the total loss value meets the preset condition (for example, less than or equal to the preset loss value threshold, or the total loss value no longer decreases) When it is determined that the training of the confrontation network is completed.
在本实施例的一些可选的实现方式中,判别网络可以为多尺度判别器,用于对输入的图像进行判别,输出至少两个判别结果。其中, 对于所输出的至少两个判别结果中的判别结果,该判别结果对应于输入判别网络的漫画风格图像包括的分块图像和样本漫画风格图像包括的样本漫画风格分块图像,该判别结果用于确定分块图像和对应的样本漫画风格分块图像是否匹配。In some optional implementations of this embodiment, the discrimination network may be a multi-scale discriminator, which is used to discriminate the input image and output at least two discrimination results. Wherein, for the discrimination result in the at least two discrimination results output, the discrimination result corresponds to the block image included in the comic style image input to the discrimination network and the sample comic style block image included in the sample comic style image, the discrimination result Used to determine whether the block image matches the corresponding sample comic style block image.
上述输入判别网络的漫画风格图像即是生成网络输出的漫画风格图像,其包括的分块图像是对其进行划分所得到的。样本漫画风格图像包括的样本漫画风格分块图像是对样本漫画风格图像进行划分所得到的。通常,每个判别结果对应于一个分块图像和一个样本漫画风格分块图像,判别结果与分块图像和样本漫画分块图像的对应关系是预先设置的。作为示例,上述至少两个判别结果可以是N行、N列的矩阵,其中,N为预设的正整数。矩阵中的每个元素即为判别结果。每个判别结果对应于一个分块图像和一个样本漫画分块图像。即判别网络分别对输入的漫画风格图像和样本漫画风格图像进行划分,得到N×N个分块图像和N×N个漫画风格分块图像。分块图像和漫画风格分块图像一一对应。判别网络依次对相对应的分块图像和漫画风格分块图像进行判别,得到对应的判别结果。通常,判别结果可以是数字0或1,0可以表示相对应的分块图像和漫画风格分块图像不匹配,1可以表示相对应的分块图像和漫画风格分块图像匹配。当表征匹配的判别结果的数量大于等于预设的数量时,确定判别网络无法准确区分生成网络生成的漫画风格图像和样本漫画风格图像(即判别准确率为50%)。The comic style image input to the judgment network is the comic style image output by the generated network, and the divided image included is obtained by dividing it. The sample comic style segmented image included in the sample comic style image is obtained by dividing the sample comic style image. Generally, each discrimination result corresponds to a block image and a sample comic style block image, and the corresponding relationship between the discrimination result and the block image and the sample comic block image is preset. As an example, the aforementioned at least two discrimination results may be a matrix with N rows and N columns, where N is a preset positive integer. Each element in the matrix is the result of discrimination. Each discrimination result corresponds to a block image and a sample comic block image. That is, the discrimination network separately divides the input comic style image and the sample comic style image to obtain N×N block images and N×N comic style block images. There is a one-to-one correspondence between the block image and the comic style block image. The discriminant network sequentially discriminates the corresponding block image and the comic style block image, and obtains the corresponding discrimination result. Generally, the discrimination result can be the number 0 or 1. 0 can indicate that the corresponding block image does not match the comic style block image, and 1 can indicate that the corresponding block image matches the comic style block image. When the number of discrimination results that characterize the match is greater than or equal to the preset number, it is determined that the discrimination network cannot accurately distinguish the comic style image generated by the generation network and the sample comic style image (that is, the discrimination accuracy rate is 50%).
实践中,上述多尺度判别器可以是PatchGAN结构的卷积神经网络,PatchGAN可以有效地对图像中的高频成分进行识别,提高对图像中的细节的判别准确性。从而有助于提高对生成网络生成的漫画风格图像和样本漫画风格图像进行判别的准确性。In practice, the above-mentioned multi-scale discriminator may be a convolutional neural network with a PatchGAN structure. PatchGAN can effectively identify high-frequency components in an image and improve the accuracy of discriminating details in the image. This helps to improve the accuracy of judging the comic style image and the sample comic style image generated by the generation network.
继续参见图3,图3是根据本实施例的用于生成漫画风格转换模型的方法的应用场景的一个示意图。在图3的应用场景中,电子设备301首先从本地获取训练样本集合302。其中,训练样本集合302中的每个训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像。样本漫画图像是技术人员预先对样本图像进行改色、改形 状、添加特效等处理后得到的图像。然后,电子设备301从本地获取预先建立的生成对抗网络303。其中,生成对抗网络303包括生成网络3031和判别网络3032,生成网络3031用于利用所输入的样本图像生成漫画风格图像,判别网络3032用于确定输入判别网络的图像是否是生成网络输出的图像。再然后,利用机器学习方法,将训练样本集合302中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练。其中,对生成网络进行训练时,通过对生成网络输出的漫画风格图像和对应的样本漫画风格图像进行比较,以及通过判别网络对生成网络输出的漫画风格图像和对应的样本漫画风格图像的判别结果,调整生成网络的参数。当判别网络无法准确区分生成网络输出的漫画风格图像和样本漫画风格图像(即判别准确率为50%)时,将此时的生成网络确定为漫画风格转换模型304。Continue to refer to FIG. 3, which is a schematic diagram of an application scenario of the method for generating a comic style conversion model according to the present embodiment. In the application scenario of FIG. 3, the electronic device 301 first obtains the training sample set 302 locally. Wherein, each training sample in the training sample set 302 includes a preset sample image and a sample comic style image corresponding to the sample image. The sample comic image is the image obtained by the technicians who change the color, shape, and add special effects of the sample image in advance. Then, the electronic device 301 obtains the pre-established generation confrontation network 303 locally. The generation confrontation network 303 includes a generation network 3031 and a discrimination network 3032. The generation network 3031 is used to generate a comic style image using input sample images, and the discrimination network 3032 is used to determine whether the image input to the discrimination network is an image output by the generation network. Then, using a machine learning method, the sample images included in the training samples in the training sample set 302 are used as the input of the generation network, the sample comic style image corresponding to the input sample image is used as the expected output of the generation network, and the generation network The actual output comic style image and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, and the generation network and the discrimination network are trained. Among them, when training the generation network, the comic style image output by the generation network is compared with the corresponding sample comic style image, and the judgment result of the comic style image output by the generation network and the corresponding sample comic style image through the discrimination network , Adjust the parameters of the generated network. When the discrimination network cannot accurately distinguish the comic style image output by the generation network and the sample comic style image (that is, the discrimination accuracy rate is 50%), the generation network at this time is determined as the comic style conversion model 304.
本公开的上述实施例提供的方法,通过获取训练样本集合和预先建立的生成对抗网络,利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。从而实现了利用有监督的训练方式对生成网络进行训练的基础上,增加了对包括生成网络和判别网络的生成对抗网络的训练,有助于减少利用有监督的训练方式训练得到的模型产生的过拟合问题,提高模型的泛化能力,以及提高图像风格转换的细节处理能力,使用训练得到的漫画风格转换模型,可以减少生成的漫画风格图像相对于原始图像产生的图像边缘锯齿,减少图像轮廓变形等问题,从而改善生成的漫画风格图像的显示效果。The method provided by the above-mentioned embodiments of the present disclosure obtains a training sample set and a pre-established generative confrontation network, and uses a machine learning method to use the sample image included in the training sample in the training sample set as the input of the generative network, which will be compared with the input The sample comic style image corresponding to the sample image is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, and the generation network and the discrimination network are processed Training, the generated network after training is determined as a comic style conversion model. In this way, on the basis of training the generative network using the supervised training method, the training of the generative adversarial network including the generative network and the discriminant network is added, which helps to reduce the generation of the model trained by the supervised training method. Over-fitting problem, improve the generalization ability of the model, and improve the detail processing ability of image style conversion. Using the manga style conversion model obtained by training can reduce the jagged edges of the generated manga style image relative to the original image and reduce the image Contour distortion and other issues, thereby improving the display effect of the generated comic style image.
进一步参考图4,其示出了根据本公开的用于生成漫画风格图像 的方法的一个实施例的流程400。该用于生成漫画风格图像的方法的流程400,包括以下步骤:With further reference to FIG. 4, it shows a process 400 of an embodiment of a method for generating a comic style image according to the present disclosure. The process 400 of the method for generating comic style images includes the following steps:
步骤401,获取目标图像。Step 401: Obtain a target image.
在本实施例中,用于生成漫画风格图像的方法的执行主体(例如图1所示的服务器或终端设备)可以通过有线连接方式或者无线连接方式从远程,或从本地获取目标图像。其中,目标图像是待利用其生成漫画风格图像的图像。例如,目标图像可以是上述执行主体包括的摄像头或与上述执行主体通信连接的电子设备包括的摄像头对目标对象进行拍摄得到的图像,目标对象可以是在摄像头的拍摄范围内的人物、事物、景物等。In this embodiment, the execution subject of the method for generating comic style images (for example, the server or terminal device shown in FIG. 1) may obtain the target image remotely or locally through a wired connection or a wireless connection. Among them, the target image is an image to be used to generate a comic style image. For example, the target image may be an image obtained by photographing a target object by a camera included in the above-mentioned execution subject or a camera included in an electronic device communicatively connected with the above-mentioned execution subject, and the target object may be a person, thing, or scene within the shooting range of the camera. Wait.
在本实施例的一些可选的实现方式中,上述目标图像是从目标视频中提取的图像帧。其中,目标视频可以是待将其包括的图像帧转换为漫画风格图像的视频。例如,目标视频可以是当前在上述执行主体上播放的视频,或者是当前上述执行主体包括的摄像头或与上述执行主体通信连接的电子设备包括的摄像头正在拍摄的视频。上述执行主可以从目标图像中提取图像帧作为目标图像。作为示例,目标图像可以是目标视频包括的、当前在上述执行主体包括的显示屏上显示的图像帧。In some optional implementation manners of this embodiment, the foregoing target image is an image frame extracted from the target video. Wherein, the target video may be a video whose image frames are to be converted into comic style images. For example, the target video may be a video currently played on the execution subject, or a video currently being shot by a camera included in the execution subject or an electronic device communicatively connected with the execution subject. The above-mentioned execution master may extract an image frame from the target image as the target image. As an example, the target image may be an image frame included in the target video and currently displayed on the display screen included in the execution subject.
步骤402,将目标图像输入预先训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出。Step 402: Input the target image into a pre-trained comic style conversion model to generate and output a comic style image corresponding to the target image.
在本实施例中,上述执行主体可以将目标图像输入预先训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出。其中,漫画风格转换模型是根据上述图2对应实施例描述的方法生成的。In this embodiment, the above-mentioned execution subject may input the target image into a pre-trained comic style conversion model to generate and output a comic style image corresponding to the target image. The comic style conversion model is generated according to the method described in the embodiment corresponding to FIG. 2 above.
上述执行主体可以按照各种方式将生成的漫画风格图像输出。例如,可以将生成的漫画风格图像显示在与上述执行主体包括的显示屏上,或者,将生成的漫画风格图像发送到与上述执行主体通信连接的其他电子设备。The above-mentioned execution subject can output the generated comic style image in various ways. For example, the generated comic style image may be displayed on a display screen included with the execution subject, or the generated comic style image may be sent to other electronic devices communicatively connected with the execution subject.
本公开的上述实施例提供的方法,通过获取目标图像,将目标图像输入预先根据上述图2对应实施例描述的方法训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出,采用该漫画风格转 换模型,可以减少生成漫画风格图像的过拟合问题,以及提高对图像中的细节进行漫画风格转换的效果,并且可以减少生成的漫画风格图像相对于原始图像产生的图像边缘锯齿,减少图像轮廓变形等问题,从而改善了生成的漫画风格图像的显示效果。The method provided in the above-mentioned embodiment of the present disclosure obtains a target image, inputs the target image into a comic style conversion model trained in advance according to the method described in the above-mentioned embodiment corresponding to FIG. 2 to generate a comic-style image corresponding to the target image and output it, using this The comic style conversion model can reduce the over-fitting problem of generating comic style images, and improve the effect of comic style conversion on the details in the image, and can reduce the image edge jagged of the generated comic style image relative to the original image. Image contour distortion and other issues, thereby improving the display effect of the generated comic style image.
进一步参考图5,作为对上述图2所示方法的实现,本公开提供了一种用于生成漫画风格转换模型的装置的一个实施例,该装置实施例与图2所示的方法实施例相对应,该装置具体可以应用于各种电子设备中。With further reference to FIG. 5, as an implementation of the method shown in FIG. 2, the present disclosure provides an embodiment of a device for generating a comic style conversion model, which is similar to the method embodiment shown in FIG. Correspondingly, the device can be specifically applied to various electronic devices.
如图5所示,本实施例的用于生成漫画风格转换模型的装置500包括:第一获取单元501,被配置成获取训练样本集合,其中,训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像;第二获取单元502,被配置成获取预先建立的生成对抗网络,其中,生成对抗网络包括生成网络和判别网络,生成网络用于利用所输入的样本图像生成漫画风格图像,判别网络用于区分生成网络输出的漫画风格图像和输入生成网络的样本图像对应的样本漫画风格图像;训练单元503,被配置成利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。As shown in FIG. 5, the apparatus 500 for generating a comic style conversion model of this embodiment includes: a first obtaining unit 501 configured to obtain a set of training samples, where the training samples include preset sample images and A sample comic style image corresponding to the image; the second acquisition unit 502 is configured to acquire a pre-established generative confrontation network, wherein the generation of the confrontation network includes a generation network and a discrimination network, and the generation network is used to generate a comic style using the input sample image The discriminant network is used to distinguish the comic style image output by the generation network and the sample comic style image corresponding to the sample image of the input generation network; the training unit 503 is configured to use a machine learning method to include the training samples in the training sample set The sample image is used as the input of the generation network, the sample comic style image corresponding to the input sample image is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as The input of the discriminant network is trained, the generative network and the discriminant network are trained, and the trained generative network is determined as the comic style conversion model.
在本实施例中,第一获取单元501可以通过有线连接方式或者无线连接方式从远程,或从本地获取训练样本集合。其中,训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像。通常,样本图像可以是对真实的人物、物品、景物等进行拍摄得到的图像。样本漫画风格图像可以是对其对应的样本图像进行各种处理(例如对图像中的某些区域进行改色、改形状、添加特效等处理)后得到的图像,所得到的图像通常具有漫画风格。例如将样本图像中的人物图像、背景图像等进行改色、添加线条等处理,使其具有漫画风格。样本图 像和样本漫画风格图像的对应关系是预先建立的。例如,技术人员可以预先针对多个样本图像中的每个样本图像,对该样本图像进行处理,从而将处理后所得到的图像确定为与该图像对应的样本漫画风格图像。In this embodiment, the first obtaining unit 501 may obtain the training sample set remotely or locally through a wired connection or a wireless connection. The training samples include preset sample images and sample comic style images corresponding to the sample images. Generally, the sample image may be an image obtained by photographing a real person, object, scene, etc. The sample comic style image may be an image obtained by performing various processings on its corresponding sample image (for example, changing colors, shapes, and adding special effects to certain areas in the image), and the resulting image usually has a comic style. For example, the character image, background image, etc. in the sample image are processed such as changing colors and adding lines to make them have a comic style. The corresponding relationship between the sample image and the sample comic style image is established in advance. For example, the technician may process the sample image in advance for each sample image in the plurality of sample images, so as to determine the image obtained after the processing as the sample comic style image corresponding to the image.
在本实施例中,第二获取单元502可以从本地或从远程获取预先建立的生成对抗网络。其中,生成对抗网络包括生成网络和判别网络。生成网络用于利用所输入的样本图像生成漫画风格图像,判别网络用于区分生成网络输出的漫画风格图像和输入生成网络的样本图像对应的样本漫画风格图像。上述生成对抗网络可以是各种结构的生成对抗网络。例如,生成式对抗网络可以是深度卷积生成对抗网络(Deep Convolutional Generative Adversarial Network,DCGAN)。应当理解,上述生成对抗网络可以是未经训练的、初始化参数后的生成对抗网络,也可以是已经训练过的生成对抗网络。In this embodiment, the second acquiring unit 502 may acquire a pre-established generative confrontation network locally or remotely. Among them, the generative confrontation network includes the generative network and the discriminant network. The generation network is used to generate a comic style image using the input sample image, and the discrimination network is used to distinguish the comic style image output by the generation network and the sample comic style image corresponding to the sample image input to the generation network. The above-mentioned generative confrontation network may be a generative confrontation network of various structures. For example, the generative confrontation network may be a deep convolutional generation confrontation network (Deep Convolutional Generative Adversarial Network, DCGAN). It should be understood that the above-mentioned generative confrontation network may be an untrained generative confrontation network after initializing parameters, or a trained generative confrontation network.
需要说明的是,生成网络可以是用于进行图像处理的卷积神经网络(例如包含卷积层、池化层、反池化层、反卷积层的各种结构的卷积神经网络)。上述判别网络可以是卷积神经网络(例如包含全连接层的各种结构的卷积神经网络,其中,上述全连接层可以实现分类功能)。此外,判别网络也可以是用于实现分类功能的其他模型,例如支持向量机(Support Vector Machine,SVM)。此处,针对输入判别网络的每个图像,判别网络若判定该图像是生成网络所输出的图像,则可以输出对应于该图像的标签1(或0);若判定该图像不是生成网络所输出的图像,则可以输出对应于该图像的标签0(或1)。需要说明的是,判别网络也可以输出其他预先设置的信息,不限于数值1和0。It should be noted that the generating network may be a convolutional neural network used for image processing (for example, a convolutional neural network with various structures including a convolution layer, a pooling layer, a depooling layer, and a deconvolution layer). The above-mentioned discriminant network may be a convolutional neural network (for example, a convolutional neural network of various structures including a fully connected layer, where the above-mentioned fully connected layer can implement a classification function). In addition, the discriminant network may also be other models for implementing classification functions, such as Support Vector Machine (SVM). Here, for each image input to the discrimination network, if the discrimination network determines that the image is the image output by the generation network, it can output the label 1 (or 0) corresponding to the image; if it is determined that the image is not output by the generation network , You can output the label 0 (or 1) corresponding to the image. It should be noted that the discrimination network can also output other preset information, which is not limited to the values 1 and 0.
在本实施例中,训练单元503可以利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。In this embodiment, the training unit 503 can use a machine learning method to use the sample images included in the training samples in the training sample set as the input to the generation network, and use the sample comic style images corresponding to the input sample images as the expectations of the generation network. Output, and use the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image as the input of the discrimination network, train the generation network and the discrimination network, and determine the generated network after training as the comic style conversion model.
具体地,上述训练单元503可以首先固定生成网络和判别网络中 的任一种网络(可称为第一网络)的参数,对未固定参数的网络(可称为第二网络)进行优化;再固定第二网络的参数,对第一网络进行优化。不断进行上述迭代,使判别网络无法区分输入的图像是否是生成网络所生成的。此时,生成网络所生成的漫画风格图像与样本漫画风格图像接近,判别网络无法准确区分生成网络生成的漫画风格图像和样本漫画风格图像(即判别准确率为50%),可以将此时的生成网络确定为漫画风格转换模型。通常,上述训练单元503可以利用现有的反向传播算法和梯度下降算法对生成网络和判别网络进行训练。每次训练后的生成网络和判别网络的参数会被调整,将每次调整参数后得到的生成网络和判别网络作为下次训练所使用的生成对抗网络。训练过程中,可以通过使用损失函数确定损失值,根据损失值迭代地训练生成网络和判别网络,以使每次迭代运算时确定的损失值最小。Specifically, the above-mentioned training unit 503 may first fix the parameters of any one of the generation network and the discrimination network (may be called the first network), and optimize the network without fixed parameters (may be called the second network); and then Fix the parameters of the second network and optimize the first network. Continuously carry out the above iterations, so that the judgment network cannot distinguish whether the input image is generated by the generation network. At this time, the comic style image generated by the generation network is close to the sample comic style image, and the discrimination network cannot accurately distinguish the comic style image generated by the generation network from the sample comic style image (that is, the discrimination accuracy rate is 50%). The generation network is determined to be a comic style conversion model. Generally, the above-mentioned training unit 503 can use the existing back propagation algorithm and gradient descent algorithm to train the generation network and the discrimination network. The parameters of the generative network and the discriminant network after each training will be adjusted, and the generative network and the discriminant network obtained after each parameter adjustment are used as the generative confrontation network used in the next training. In the training process, the loss value can be determined by using the loss function, and the generation network and the discriminant network are iteratively trained according to the loss value to minimize the loss value determined during each iteration.
需要说明的是,在对生成网络进行训练时,本实施例采用的方式是将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为期望输出,对生成网络进行训练,针对每次训练输入的样本图像,可以得到实际输出。其中,实际输出是生成网络实际输出的漫画风格图像。然后,上述训练单元503可以采用反向传播算法和梯度下降算法,基于实际输出和期望输出,调整生成网络的参数,将每次调整参数后的生成网络作为下次训练所使用的生成网络。It should be noted that when training the generation network, the method adopted in this embodiment is to use the sample images included in the training samples in the training sample set as the input of the generation network, and use the sample comic style image corresponding to the input sample image As the expected output, the generation network is trained, and the actual output can be obtained for the sample image input for each training. Among them, the actual output is the comic style image actually output by the generated network. Then, the above-mentioned training unit 503 may adopt a back propagation algorithm and a gradient descent algorithm to adjust the parameters of the generation network based on the actual output and the expected output, and use the generation network after each adjustment of the parameters as the generation network used for the next training.
在本实施例的一些可选的实现方式中,判别网络为多尺度判别器,用于对输入的图像进行判别,输出至少两个判别结果,其中,对于所输出的至少两个判别结果中的判别结果,该判别结果对应于输入判别网络的图像包括的分块图像和样本漫画风格图像包括的样本漫画风格分块图像,用于确定分块图像和对应的样本漫画风格分块图像是否匹配。In some optional implementations of this embodiment, the discriminant network is a multi-scale discriminator, used to discriminate the input image, and output at least two discriminating results, wherein, for the at least two discriminating results output The discrimination result, which corresponds to the block image included in the image input to the discrimination network and the sample comic style block image included in the sample comic style image, is used to determine whether the block image matches the corresponding sample comic style block image.
在一些实施例中,训练单元503可以包括:确定模块(图中未示出),被配置成利用预设的损失函数,确定用于表征生成网络输出的漫画风格图像与对应的样本漫画风格图像的差异的生成损失值,以及确定判别网络对应的、用于表征输入判别网络的生成网络实际输出的漫 画风格图像与样本漫画风格图像的差异的判别损失值;训练模块(图中未示出),被配置成基于所确定的生成损失值和判别损失值,对生成网络和判别网络进行训练。In some embodiments, the training unit 503 may include: a determining module (not shown in the figure), configured to use a preset loss function to determine the comic style image and the corresponding sample comic style image used to characterize the network output The generation loss value of the difference of the discriminant network, and the discriminant loss value that determines the difference between the comic style image and the sample comic style image corresponding to the discriminant network and used to represent the actual output of the generation network of the input discriminant network; training module (not shown in the figure) , Is configured to train the generation network and the discrimination network based on the determined generation loss value and the discrimination loss value.
在一些实施例中,生成损失值由以下任一种损失函数确定得到:L1范数损失函数、L2范数损失函数。In some embodiments, the generated loss value is determined by any one of the following loss functions: L1 norm loss function, L2 norm loss function.
本公开的上述实施例提供的装置500,通过获取训练样本集合和预先建立的生成对抗网络,利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。从而实现了利用有监督的训练方式对生成网络进行训练的基础上,增加了对包括生成网络和判别网络的生成对抗网络的训练,有助于减少利用有监督的训练方式训练得到的模型产生的过拟合问题,提高模型的泛化能力,以及提高图像风格转换的细节处理能力,使用训练得到的漫画风格转换模型,可以减少生成的漫画风格图像相对于原始图像产生的图像边缘锯齿,减少图像轮廓变形等问题,从而改善生成的漫画风格图像的显示效果。The apparatus 500 provided by the above-mentioned embodiment of the present disclosure acquires a training sample set and a pre-established generative confrontation network, and uses a machine learning method to use a sample image included in the training sample in the training sample set as the input of the generative network, and will be compared with the input The sample comic style image corresponding to the sample image of the generation network is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, and the generation network and the discrimination network Perform training and determine the trained generation network as a comic style conversion model. In this way, on the basis of training the generative network using the supervised training method, the training of the generative adversarial network including the generative network and the discriminant network is added, which helps to reduce the generation of the model trained by the supervised training method. Over-fitting problem, improve the generalization ability of the model, and improve the detail processing ability of image style conversion. Using the manga style conversion model obtained by training can reduce the jagged edges of the generated manga style image relative to the original image and reduce the image Contour distortion and other issues, thereby improving the display effect of the generated comic style image.
进一步参考图6,作为对上述图4所示方法的实现,本公开提供了一种用于生成漫画风格图像的装置的一个实施例,该装置实施例与图4所示的方法实施例相对应,该装置具体可以应用于各种电子设备中。With further reference to FIG. 6, as an implementation of the method shown in FIG. 4, the present disclosure provides an embodiment of a device for generating comic style images, and the device embodiment corresponds to the method embodiment shown in FIG. 4 , The device can be applied to various electronic equipment.
如图6所示,本实施例的用于生成漫画风格图像的装置600包括:图像获取单元601,被配置成获取目标图像;图像生成单元602,被配置成将目标图像输入预先训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出,其中,漫画风格转换模型是根据上述图2对应实施例描述的方法生成的。As shown in FIG. 6, the apparatus 600 for generating a comic style image of this embodiment includes: an image acquisition unit 601 configured to acquire a target image; an image generation unit 602 configured to input the target image into a pre-trained comic style The conversion model generates and outputs a comic style image corresponding to the target image. The comic style conversion model is generated according to the method described in the embodiment corresponding to FIG. 2 above.
在本实施例中,图像获取单元601可以通过有线连接方式或者无线连接方式从远程,或从本地获取目标图像。其中,目标图像是待利 用其生成漫画风格图像的图像。例如,目标图像可以是上述装置600包括的摄像头或与上述装置600通信连接的电子设备包括的摄像头对目标对象进行拍摄得到的图像,目标对象可以是在摄像头的拍摄范围内的人物、事物、景物等。In this embodiment, the image acquisition unit 601 can acquire the target image remotely or locally through a wired connection or a wireless connection. Among them, the target image is an image to be used to generate a comic style image. For example, the target image may be an image obtained by photographing a target object by a camera included in the foregoing apparatus 600 or an electronic device included in an electronic device communicatively connected with the foregoing apparatus 600, and the target object may be a person, thing, or scene within the shooting range of the camera. Wait.
在本实施例中,图像生成单元602可以将目标图像输入预先训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出。其中,漫画风格转换模型是根据上述图2对应实施例描述的方法生成的。In this embodiment, the image generating unit 602 may input the target image into a pre-trained comic style conversion model to generate and output a comic style image corresponding to the target image. The comic style conversion model is generated according to the method described in the embodiment corresponding to FIG. 2 above.
上述图像生成单元602可以按照各种方式将生成的漫画风格图像输出。例如,可以将生成的漫画风格图像显示在与上述执行主体包括的显示屏上,或者,将生成的漫画风格图像发送到与上述执行主体通信连接的其他电子设备。The above-mentioned image generating unit 602 can output the generated comic style image in various ways. For example, the generated comic style image may be displayed on a display screen included with the execution subject, or the generated comic style image may be sent to other electronic devices communicatively connected with the execution subject.
在本实施例的一些可选的实现方式中,目标图像是从目标视频中提取的图像帧。In some optional implementation manners of this embodiment, the target image is an image frame extracted from the target video.
本公开的上述实施例提供的装置600,通过获取目标图像,将目标图像输入预先根据上述图2对应实施例描述的方法训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出,采用该漫画风格转换模型,可以减少生成漫画风格图像的过拟合问题,以及提高对图像中的细节进行漫画风格转换的效果,并且可以减少生成的漫画风格图像相对于原始图像产生的图像边缘锯齿,减少图像轮廓变形等问题,从而改善了生成的漫画风格图像的显示效果。The apparatus 600 provided in the above-mentioned embodiment of the present disclosure acquires a target image, inputs the target image into the comic style conversion model trained in advance according to the method described in the above-mentioned embodiment corresponding to FIG. 2, and generates and outputs the comic style image corresponding to the target image. The comic style conversion model can reduce the over-fitting problem of generating comic style images, improve the effect of comic style conversion on details in the image, and reduce the jagged edges of the generated comic style image relative to the original image. Reduce the problem of image contour distortion, thereby improving the display effect of the generated comic style image.
下面参考图7,其示出了适于用来实现本公开的实施例的电子设备(例如图1中的服务器或终端设备)700的结构示意图。本公开的实施例中的终端设备可以包括但不限于诸如移动电话、笔记本电脑、数字广播接收器、PDA(个人数字助理)、PAD(平板电脑)、PMP(便携式多媒体播放器)、车载终端(例如车载导航终端)等等的移动终端以及诸如数字TV、台式计算机等等的固定终端。图7示出的电子设备仅仅是一个示例,不应对本公开的实施例的功能和使用范围带来任何限制。Referring now to FIG. 7, it shows a schematic structural diagram of an electronic device (such as the server or terminal device in FIG. 1) 700 suitable for implementing the embodiments of the present disclosure. Terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablets), PMPs (portable multimedia players), vehicle-mounted terminals ( For example, mobile terminals such as car navigation terminals and fixed terminals such as digital TVs and desktop computers. The electronic device shown in FIG. 7 is only an example, and should not bring any limitation to the function and scope of use of the embodiments of the present disclosure.
如图7所示,电子设备700可以包括处理装置(例如中央处理器、 图形处理器等)701,其可以根据存储在只读存储器(ROM)702中的程序或者从存储装置708加载到随机访问存储器(RAM)703中的程序而执行各种适当的动作和处理。在RAM 703中,还存储有电子设备700操作所需的各种程序和数据。处理装置701、ROM 702以及RAM 703通过总线704彼此相连。输入/输出(I/O)接口705也连接至总线704。As shown in FIG. 7, the electronic device 700 may include a processing device (such as a central processing unit, a graphics processor, etc.) 701, which may be loaded into a random access device according to a program stored in a read-only memory (ROM) 702 or from a storage device 708. The program in the memory (RAM) 703 executes various appropriate actions and processing. In the RAM 703, various programs and data required for the operation of the electronic device 700 are also stored. The processing device 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704. An input/output (I/O) interface 705 is also connected to the bus 704.
通常,以下装置可以连接至I/O接口705:包括例如触摸屏、触摸板、键盘、鼠标、摄像头、麦克风、加速度计、陀螺仪等的输入装置706;包括例如液晶显示器(LCD)、扬声器、振动器等的输出装置707;包括例如磁带、硬盘等的存储装置708;以及通信装置709。通信装置709可以允许电子设备700与其他设备进行无线或有线通信以交换数据。虽然图7示出了具有各种装置的电子设备700,但是应理解的是,并不要求实施或具备所有示出的装置。可以替代地实施或具备更多或更少的装置。图7中示出的每个方框可以代表一个装置,也可以根据需要代表多个装置。Generally, the following devices can be connected to the I/O interface 705: including input devices 706 such as touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; including, for example, liquid crystal display (LCD), speakers, vibration An output device 707 such as a device; a storage device 708 such as a magnetic tape and a hard disk; and a communication device 709. The communication device 709 may allow the electronic device 700 to perform wireless or wired communication with other devices to exchange data. Although FIG. 7 shows an electronic device 700 having various devices, it should be understood that it is not required to implement or have all the illustrated devices. It may alternatively be implemented or provided with more or fewer devices. Each block shown in FIG. 7 may represent one device, or may represent multiple devices as needed.
特别地,根据本公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信装置709从网络上被下载和安装,或者从存储装置708被安装,或者从ROM 702被安装。在该计算机程序被处理装置701执行时,执行本公开的实施例的方法中限定的上述功能。需要说明的是,本公开的实施例所述的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储 器件、或者上述的任意合适的组合。在本公开的实施例中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本公开的实施例中,计算机可读信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读信号介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:电线、光缆、RF(射频)等等,或者上述的任意合适的组合。In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program may be downloaded and installed from the network through the communication device 709, or installed from the storage device 708, or installed from the ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed. It should be noted that the computer-readable medium described in the embodiment of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), optical fiber, portable compact disk read only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above. In the embodiments of the present disclosure, the computer-readable storage medium may be any tangible medium that contains or stores a program, and the program may be used by or in combination with an instruction execution system, apparatus, or device. In the embodiments of the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as a part of a carrier wave, and a computer-readable program code is carried therein. This propagated data signal can take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. The computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium. The computer-readable signal medium may send, propagate, or transmit the program for use by or in combination with the instruction execution system, apparatus, or device . The program code contained on the computer-readable medium can be transmitted by any suitable medium, including but not limited to: wire, optical cable, RF (Radio Frequency), etc., or any suitable combination of the above.
上述计算机可读介质可以是上述电子设备中所包含的;也可以是单独存在,而未装配入该电子设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被该电子设备执行时,使得该电子设备:获取训练样本集合,其中,训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像;获取预先建立的生成对抗网络,其中,生成对抗网络包括生成网络和判别网络,生成网络用于利用所输入的样本图像生成漫画风格图像,判别网络用于区分生成网络输出的漫画风格图像和输入生成网络的样本图像对应的样本漫画风格图像;利用机器学习方法,将训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。The above-mentioned computer-readable medium may be included in the above-mentioned electronic device; or it may exist alone without being assembled into the electronic device. The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device is caused to: obtain a training sample set, wherein the training sample includes a preset sample image, and The sample comic style image corresponding to the sample image; obtain a pre-established generative confrontation network, where the generative confrontation network includes a generation network and a discriminant network. The generation network is used to generate a comic style image using the input sample image, and the discriminant network is used to differentiate The comic style image output by the network and the sample comic style image corresponding to the sample image of the input generation network; using machine learning methods, the sample images included in the training samples in the training sample set are used as the input of the generation network, which will correspond to the input sample image The sample comic style image of the generation network is used as the expected output of the generation network, and the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, and the generation network and the discrimination network are trained. The generated network after training is determined to be the comic style conversion model.
此外,当上述一个或者多个程序被该电子设备执行时,使得该电子设备:获取目标图像;将目标图像输入预先训练的漫画风格转换模型,生成目标图像对应的漫画风格图像及输出。In addition, when the above-mentioned one or more programs are executed by the electronic device, the electronic device is caused to: acquire the target image; input the target image into the pre-trained comic style conversion model to generate and output the comic style image corresponding to the target image.
可以以一种或多种程序设计语言或其组合来编写用于执行本公开 的实施例的操作的计算机程序代码,所述程序设计语言包括面向对象的程序设计语言—诸如Java、Smalltalk、C++,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络——包括局域网(LAN)或广域网(WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。The computer program code used to perform the operations of the embodiments of the present disclosure can be written in one or more programming languages or a combination thereof, the programming languages including object-oriented programming languages such as Java, Smalltalk, C++, It also includes conventional procedural programming languages-such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partly on the user's computer, executed as an independent software package, partly on the user's computer and partly executed on a remote computer, or entirely executed on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to pass Internet connection).
附图中的流程图和框图,图示了按照本公开各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,该模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions, and operations of the system, method, and computer program product according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram can represent a module, program segment, or part of code, and the module, program segment, or part of code contains one or more for realizing the specified logic function Executable instructions. It should also be noted that, in some alternative implementations, the functions marked in the block may also occur in a different order from the order marked in the drawings. For example, two blocks shown in succession can actually be executed substantially in parallel, or they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and/or flowchart, and the combination of the blocks in the block diagram and/or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations Or it can be realized by a combination of dedicated hardware and computer instructions.
描述于本公开的实施例中所涉及到的单元可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的单元也可以设置在处理器中,例如,可以描述为:一种处理器包括第一获取单元、第二获取单元、训练单元。其中,这些单元的名称在某种情况下并不构成对该单元本身的限定,例如,第一获取单元还可以被描述为“获取训练样本集合的单元”。The units involved in the embodiments described in the present disclosure may be implemented in a software manner, and may also be implemented in a hardware manner. The described unit may also be provided in the processor, for example, it may be described as: a processor includes a first acquiring unit, a second acquiring unit, and a training unit. Wherein, the names of these units do not constitute a limitation on the unit itself under certain circumstances. For example, the first obtaining unit can also be described as "a unit for obtaining a training sample set."
以上描述仅为本公开的较佳实施例以及对所运用技术原理的说明。本领域技术人员应当理解,本公开的实施例中所涉及的发明范围,并不限于上述技术特征的特定组合而成的技术方案,同时也应涵盖在不脱离上述发明构思的情况下,由上述技术特征或其等同特征进行任 意组合而形成的其它技术方案。例如上述特征与本公开的实施例中公开的(但不限于)具有类似功能的技术特征进行互相替换而形成的技术方案。The above description is only a preferred embodiment of the present disclosure and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solution formed by the specific combination of the above technical features, and should also cover the above-mentioned inventive concept without departing from the above-mentioned inventive concept. Other technical solutions formed by any combination of technical features or equivalent features. For example, the above-mentioned features and the technical features disclosed in the embodiments of the present disclosure (but not limited to) having similar functions are replaced with each other to form a technical solution.
Claims (14)
- 一种用于生成漫画风格转换模型的方法,包括:A method for generating comic style conversion models, including:获取训练样本集合,其中,训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像;Acquiring a set of training samples, where the training samples include preset sample images and sample comic style images corresponding to the sample images;获取预先建立的生成对抗网络,其中,所述生成对抗网络包括生成网络和判别网络,所述生成网络用于利用所输入的样本图像生成漫画风格图像,所述判别网络用于区分所述生成网络输出的漫画风格图像和输入所述生成网络的样本图像对应的样本漫画风格图像;Obtain a pre-established generative confrontation network, wherein the generative confrontation network includes a generation network and a discrimination network, the generation network is used to generate a comic style image using the input sample image, and the discrimination network is used to distinguish the generation network The output comic style image and the sample comic style image corresponding to the sample image input to the generating network;利用机器学习方法,将所述训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。Using machine learning methods, the sample images included in the training samples in the training sample set are used as the input of the generation network, the sample comic style image corresponding to the input sample images is used as the expected output of the generation network, and the actual output of the generation network The comic style image of and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, the generation network and the discrimination network are trained, and the trained generation network is determined as the comic style conversion model.
- 根据权利要求1所述的方法,其中,所述判别网络为多尺度判别器,用于对输入的图像进行判别,输出至少两个判别结果,其中,对于所输出的至少两个判别结果中的判别结果,该判别结果对应于输入判别网络的图像包括的分块图像和样本漫画风格图像包括的样本漫画风格分块图像,用于确定分块图像和对应的样本漫画风格分块图像是否匹配。The method according to claim 1, wherein the discriminant network is a multi-scale discriminator for discriminating the input image and outputting at least two discriminating results, wherein, for the at least two discriminating results output The discrimination result, which corresponds to the block image included in the image input to the discrimination network and the sample comic style block image included in the sample comic style image, is used to determine whether the block image matches the corresponding sample comic style block image.
- 根据权利要求1或2所述的方法,其中,所述对生成网络和判别网络进行训练,包括:The method according to claim 1 or 2, wherein the training of the generating network and the discriminant network comprises:利用预设的损失函数,确定用于表征生成网络输出的漫画风格图像与对应的样本漫画风格图像的差异的生成损失值,以及确定判别网络对应的、用于表征输入判别网络的生成网络实际输出的漫画风格图像与样本漫画风格图像的差异的判别损失值;Using the preset loss function, determine the generation loss value used to characterize the difference between the comic style image output by the generation network and the corresponding sample comic style image, and determine the actual output of the generation network corresponding to the discrimination network and used to characterize the input discrimination network The discriminant loss value of the difference between the comic style image and the sample comic style image;基于所确定的生成损失值和判别损失值,对生成网络和判别网络 进行训练。Based on the determined generation loss value and discrimination loss value, the generation network and the discrimination network are trained.
- 根据权利要求3所述的方法,其中,生成损失值由以下任一种损失函数确定得到:L1范数损失函数、L2范数损失函数。The method according to claim 3, wherein the generated loss value is determined by any one of the following loss functions: L1 norm loss function and L2 norm loss function.
- 一种用于生成漫画风格图像的方法,包括:A method for generating comic style images, including:获取目标图像;Get the target image;将所述目标图像输入预先训练的漫画风格转换模型,生成所述目标图像对应的漫画风格图像及输出,其中,所述漫画风格转换模型是根据权利要求1-4之一所述的方法生成的。The target image is input into a pre-trained comic style conversion model to generate and output a comic style image corresponding to the target image, wherein the comic style conversion model is generated according to the method of any one of claims 1-4 .
- 根据权利要求5所述的方法,其中,所述目标图像是从目标视频中提取的图像帧。The method according to claim 5, wherein the target image is an image frame extracted from a target video.
- 一种用于生成漫画风格转换模型的装置,包括:A device for generating a comic style conversion model, including:第一获取单元,被配置成获取训练样本集合,其中,训练样本包括预设的样本图像,以及与样本图像对应的样本漫画风格图像;The first acquiring unit is configured to acquire a training sample set, where the training sample includes a preset sample image and a sample comic style image corresponding to the sample image;第二获取单元,被配置成获取预先建立的生成对抗网络,其中,所述生成对抗网络包括生成网络和判别网络,所述生成网络用于利用所输入的样本图像生成漫画风格图像,所述判别网络用于区分所述生成网络输出的漫画风格图像和输入所述生成网络的样本图像对应的样本漫画风格图像;The second acquisition unit is configured to acquire a pre-established generative confrontation network, wherein the generative confrontation network includes a generation network and a discrimination network, and the generation network is used to generate a comic style image using the input sample image, and the discrimination The network is used to distinguish the comic style image output by the generation network and the sample comic style image corresponding to the sample image input to the generation network;训练单元,被配置成利用机器学习方法,将所述训练样本集合中的训练样本包括的样本图像作为生成网络的输入,将与输入的样本图像对应的样本漫画风格图像作为生成网络的期望输出,以及将生成网络实际输出的漫画风格图像和与输入的样本图像对应的样本漫画风格图像作为判别网络的输入,对生成网络和判别网络进行训练,将训练后的生成网络确定为漫画风格转换模型。The training unit is configured to use a machine learning method to use the sample images included in the training samples in the training sample set as the input of the generation network, and use the sample comic style image corresponding to the input sample images as the expected output of the generation network, And the comic style image actually output by the generation network and the sample comic style image corresponding to the input sample image are used as the input of the discrimination network, the generation network and the discrimination network are trained, and the trained generation network is determined as the comic style conversion model.
- 根据权利要求7所述的装置,其中,所述判别网络为多尺度判 别器,用于对输入的图像进行判别,输出至少两个判别结果,其中,对于所输出的至少两个判别结果中的判别结果,该判别结果对应于输入判别网络的图像包括的分块图像和样本漫画风格图像包括的样本漫画风格分块图像,用于确定分块图像和对应的样本漫画风格分块图像是否匹配。7. The device according to claim 7, wherein the discriminant network is a multi-scale discriminator for discriminating the input image and outputting at least two discriminating results, wherein, for the at least two discriminating results The discrimination result, which corresponds to the block image included in the image input to the discrimination network and the sample comic style block image included in the sample comic style image, is used to determine whether the block image matches the corresponding sample comic style block image.
- 根据权利要求7或8所述的装置,其中,所述训练单元包括:The device according to claim 7 or 8, wherein the training unit comprises:确定模块,被配置成利用预设的损失函数,确定用于表征生成网络输出的漫画风格图像与对应的样本漫画风格图像的差异的生成损失值,以及确定判别网络对应的、用于表征输入判别网络的生成网络实际输出的漫画风格图像与样本漫画风格图像的差异的判别损失值;The determination module is configured to use a preset loss function to determine the generation loss value that is used to characterize the difference between the comic style image output by the generation network and the corresponding sample comic style image, and to determine the generation loss value corresponding to the discrimination network and used to characterize the input discrimination The generation of the network The judgment loss value of the difference between the comic style image actually output by the network and the sample comic style image;训练模块,被配置成基于所确定的生成损失值和判别损失值,对生成网络和判别网络进行训练。The training module is configured to train the generation network and the discrimination network based on the determined generation loss value and the discrimination loss value.
- 根据权利要求9所述的装置,其中,生成损失值由以下任一种损失函数确定得到:L1范数损失函数、L2范数损失函数。The apparatus according to claim 9, wherein the generated loss value is determined by any one of the following loss functions: L1 norm loss function and L2 norm loss function.
- 一种用于生成漫画风格图像的装置,包括:A device for generating comic style images, including:图像获取单元,被配置成获取目标图像;An image acquisition unit configured to acquire a target image;图像生成单元,被配置成将所述目标图像输入预先训练的漫画风格转换模型,生成所述目标图像对应的漫画风格图像及输出,其中,所述漫画风格转换模型是根据权利要求1-4之一所述的方法生成的。The image generating unit is configured to input the target image into a pre-trained comic style conversion model to generate and output a comic style image corresponding to the target image, wherein the comic style conversion model is according to claims 1-4 Generated by the method described in one.
- 根据权利要求11所述的装置,其中,所述目标图像是从目标视频中提取的图像帧。The apparatus according to claim 11, wherein the target image is an image frame extracted from the target video.
- 一种电子设备,包括:An electronic device including:一个或多个处理器;One or more processors;存储装置,其上存储有一个或多个程序,A storage device on which one or more programs are stored,当所述一个或多个程序被所述一个或多个处理器执行,使得所述 一个或多个处理器实现如权利要求1-6中任一所述的方法。When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1-6.
- 一种计算机可读介质,其上存储有计算机程序,其中,该程序被处理器执行时实现如权利要求1-6中任一所述的方法。A computer-readable medium with a computer program stored thereon, wherein the program is executed by a processor to implement the method according to any one of claims 1-6.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910090075.6A CN109816589B (en) | 2019-01-30 | 2019-01-30 | Method and apparatus for generating cartoon style conversion model |
CN201910090075.6 | 2019-01-30 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2020155907A1 true WO2020155907A1 (en) | 2020-08-06 |
Family
ID=66605948
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2019/126379 WO2020155907A1 (en) | 2019-01-30 | 2019-12-18 | Method and apparatus for generating cartoon style conversion model |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN109816589B (en) |
WO (1) | WO2020155907A1 (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112330534A (en) * | 2020-11-13 | 2021-02-05 | 北京字跳网络技术有限公司 | Animal face style image generation method, model training method, device and equipment |
CN113393544A (en) * | 2020-09-30 | 2021-09-14 | 腾讯科技(深圳)有限公司 | Image processing method, device, equipment and medium |
CN115100334A (en) * | 2022-08-24 | 2022-09-23 | 广州极尚网络技术有限公司 | Image edge drawing and animation method, device and storage medium |
Families Citing this family (28)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109816589B (en) * | 2019-01-30 | 2020-07-17 | 北京字节跳动网络技术有限公司 | Method and apparatus for generating cartoon style conversion model |
CN110458918B (en) * | 2019-08-16 | 2023-05-09 | 北京百度网讯科技有限公司 | Method and device for outputting information |
CN112446190A (en) * | 2019-08-16 | 2021-03-05 | 北京大数医达科技有限公司 | Method and device for generating style conversion text |
CN110516201B (en) * | 2019-08-20 | 2023-03-28 | Oppo广东移动通信有限公司 | Image processing method, image processing device, electronic equipment and storage medium |
CN111047507B (en) * | 2019-11-29 | 2024-03-26 | 北京达佳互联信息技术有限公司 | Training method of image generation model, image generation method and device |
CN111080512B (en) * | 2019-12-13 | 2023-08-15 | 咪咕动漫有限公司 | Cartoon image generation method and device, electronic equipment and storage medium |
CN111242844B (en) * | 2020-01-19 | 2023-09-22 | 腾讯科技(深圳)有限公司 | Image processing method, device, server and storage medium |
CN113139893B (en) * | 2020-01-20 | 2023-10-03 | 北京达佳互联信息技术有限公司 | Image translation model construction method and device and image translation method and device |
CN113259583B (en) * | 2020-02-13 | 2023-05-12 | 北京小米移动软件有限公司 | Image processing method, device, terminal and storage medium |
CN111325786B (en) * | 2020-02-18 | 2022-06-28 | 北京市商汤科技开发有限公司 | Image processing method and device, electronic equipment and storage medium |
CN111369468B (en) * | 2020-03-09 | 2022-02-01 | 北京字节跳动网络技术有限公司 | Image processing method, image processing device, electronic equipment and computer readable medium |
CN111402112B (en) * | 2020-03-09 | 2024-07-26 | 抖音视界有限公司 | Image processing method, device, electronic equipment and computer readable medium |
CN111402151A (en) * | 2020-03-09 | 2020-07-10 | 北京字节跳动网络技术有限公司 | Image processing method, image processing device, electronic equipment and computer readable medium |
CN111553283B (en) * | 2020-04-29 | 2023-08-25 | 北京百度网讯科技有限公司 | Method and device for generating model |
CN111832609B (en) * | 2020-06-01 | 2024-02-13 | 北京百度网讯科技有限公司 | Training method and device for image processing model, electronic equipment and storage medium |
CN111784567B (en) * | 2020-07-03 | 2023-04-28 | 北京字节跳动网络技术有限公司 | Method, apparatus, electronic device, and computer-readable medium for converting image |
CN112991148B (en) * | 2020-10-30 | 2023-08-11 | 抖音视界有限公司 | Style image generation method, model training method, device, equipment and medium |
CN112529058B (en) * | 2020-12-03 | 2024-09-10 | 上海游境网络科技有限公司 | Image generation model training method and device, and image generation method and device |
CN112967174B (en) * | 2021-01-21 | 2024-02-09 | 北京达佳互联信息技术有限公司 | Image generation model training, image generation method, image generation device and storage medium |
CN112862110B (en) * | 2021-02-11 | 2024-01-30 | 脸萌有限公司 | Model generation method and device and electronic equipment |
CN113301268A (en) * | 2021-04-30 | 2021-08-24 | 南京大学 | Method for automatically generating comic book by video based on style migration and voice recognition |
CN113610989B (en) * | 2021-08-04 | 2022-12-27 | 北京百度网讯科技有限公司 | Method and device for training style migration model and method and device for style migration |
CN113610731B (en) * | 2021-08-06 | 2023-08-08 | 北京百度网讯科技有限公司 | Method, apparatus and computer program product for generating image quality improvement model |
CN113901997A (en) * | 2021-09-29 | 2022-01-07 | 北京百度网讯科技有限公司 | Image style conversion method, device, equipment, storage medium and program product |
CN114067052A (en) * | 2021-11-16 | 2022-02-18 | 百果园技术(新加坡)有限公司 | Cartoon model construction method, device, equipment, storage medium and program product |
CN113837933A (en) * | 2021-11-26 | 2021-12-24 | 北京市商汤科技开发有限公司 | Network training and image generation method and device, electronic equipment and storage medium |
CN114610677B (en) * | 2022-03-10 | 2024-07-23 | 腾讯科技(深圳)有限公司 | Determination method and related device of conversion model |
CN117576245B (en) * | 2024-01-15 | 2024-05-07 | 腾讯科技(深圳)有限公司 | Method and device for converting style of image, electronic equipment and storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108550107A (en) * | 2018-04-27 | 2018-09-18 | Oppo广东移动通信有限公司 | A kind of image processing method, picture processing unit and mobile terminal |
CN109255769A (en) * | 2018-10-25 | 2019-01-22 | 厦门美图之家科技有限公司 | The training method and training pattern and image enchancing method of image enhancement network |
CN109816589A (en) * | 2019-01-30 | 2019-05-28 | 北京字节跳动网络技术有限公司 | Method and apparatus for generating cartoon style transformation model |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107730573A (en) * | 2017-09-22 | 2018-02-23 | 西安交通大学 | A kind of personal portrait cartoon style generation method of feature based extraction |
CN108491809B (en) * | 2018-03-28 | 2023-09-22 | 百度在线网络技术(北京)有限公司 | Method and apparatus for generating near infrared image generation model |
CN108491823B (en) * | 2018-03-30 | 2021-12-24 | 百度在线网络技术(北京)有限公司 | Method and device for generating human eye recognition model |
-
2019
- 2019-01-30 CN CN201910090075.6A patent/CN109816589B/en active Active
- 2019-12-18 WO PCT/CN2019/126379 patent/WO2020155907A1/en active Application Filing
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108550107A (en) * | 2018-04-27 | 2018-09-18 | Oppo广东移动通信有限公司 | A kind of image processing method, picture processing unit and mobile terminal |
CN109255769A (en) * | 2018-10-25 | 2019-01-22 | 厦门美图之家科技有限公司 | The training method and training pattern and image enchancing method of image enhancement network |
CN109816589A (en) * | 2019-01-30 | 2019-05-28 | 北京字节跳动网络技术有限公司 | Method and apparatus for generating cartoon style transformation model |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113393544A (en) * | 2020-09-30 | 2021-09-14 | 腾讯科技(深圳)有限公司 | Image processing method, device, equipment and medium |
CN112330534A (en) * | 2020-11-13 | 2021-02-05 | 北京字跳网络技术有限公司 | Animal face style image generation method, model training method, device and equipment |
CN115100334A (en) * | 2022-08-24 | 2022-09-23 | 广州极尚网络技术有限公司 | Image edge drawing and animation method, device and storage medium |
CN115100334B (en) * | 2022-08-24 | 2022-11-25 | 广州极尚网络技术有限公司 | Image edge tracing and image animation method, device and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN109816589B (en) | 2020-07-17 |
CN109816589A (en) | 2019-05-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2020155907A1 (en) | Method and apparatus for generating cartoon style conversion model | |
CN109800732B (en) | Method and device for generating cartoon head portrait generation model | |
CN108520220B (en) | Model generation method and device | |
WO2020006961A1 (en) | Image extraction method and device | |
CN109740018B (en) | Method and device for generating video label model | |
CN108197652B (en) | Method and apparatus for generating information | |
CN110021052B (en) | Method and apparatus for generating fundus image generation model | |
CN109800730B (en) | Method and device for generating head portrait generation model | |
WO2020207174A1 (en) | Method and apparatus for generating quantized neural network | |
CN112149699B (en) | Method and device for generating model and method and device for identifying image | |
WO2023005386A1 (en) | Model training method and apparatus | |
WO2020211573A1 (en) | Method and device for processing image | |
WO2020093724A1 (en) | Method and device for generating information | |
US20240289999A1 (en) | Method, apparatus, device and storage medium for image generation | |
WO2020238321A1 (en) | Method and device for age identification | |
CN113449851A (en) | Data processing method and device | |
CN111311480A (en) | Image fusion method and device | |
CN112241761B (en) | Model training method and device and electronic equipment | |
WO2023185516A1 (en) | Method and apparatus for training image recognition model, and recognition method and apparatus, and medium and device | |
CN111312223B (en) | Training method and device of voice segmentation model and electronic equipment | |
CN111539287B (en) | Method and device for training face image generation model | |
CN114898177B (en) | Defect image generation method, model training method, device, medium and product | |
WO2021012691A1 (en) | Method and device for image retrieval | |
CN117633228A (en) | Model training method and device | |
CN118042246A (en) | Video generation method, device, electronic equipment and readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 19913736 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
32PN | Ep: public notification in the ep bulletin as address of the adressee cannot be established |
Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 01.12.2021) |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 19913736 Country of ref document: EP Kind code of ref document: A1 |