Face swap model training method, device, equipment and medium
By superimposing the basic face image and the feature image and using CycleGAN and VGG networks to adjust network parameters, the problem of being unable to achieve many-to-many face image replacement in the existing technology is solved, and any face image input can generate the required The effect of replacing images improves the flexibility and accuracy of the model.
Patent Information
- Application Number
- CN201910344261.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-04-26
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2040-03-10
AI Technical Summary
Existing face swapping technology cannot achieve many-to-many face swapping, that is, it cannot convert any person's image into anyone's image at will, and the neural network model needs to be retrained once the input character changes.
By overlaying the basic face image of the first person with the facial feature image of the second person, inputting the preset neural network (including CycleGAN and VGG network), and adjusting the network parameters to meet the preset conditions of the loss function value, we can achieve Any basic face image input can generate a model for the face-changing image of the person to be replaced.
It realizes that when any basic face image is used as input, the face-changing image of the person to be replaced can be generated, which improves the flexibility and accuracy of the face-changing model and avoids the need for retraining.
Smart Images

Figure CN111860043B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence, and in particular to a method, device, equipment and medium for training a face image replacement model. Background Art
[0002] With the rise of artificial intelligence (AI), AI technology has been widely used in the fields of medicine, communications, etc. As one of the specific applications, face replacement technology has received widespread attention.
[0003] At present, most face-swapping technologies are based on the principle of deepfakes, which achieve point-to-point face-swapping by training neural network models. That is, the neural model can only be trained to transform from A to B, where A and B will not change. Once A or B changes, the neural network model needs to be retrained.
[0004] Therefore, the current face swapping technology cannot realize many-to-many face swapping, that is, it cannot realize that the image of any person can be converted into the image of any person at will. Summary of the invention
[0005] The embodiments of the present invention provide a face replacement model training method, device, equipment and medium, which can achieve the goal of obtaining a face replacement image of the person to be replaced when any person's basic face image is used as input image data.
[0006] According to one aspect of an embodiment of the present invention, a method for training a face image swapping model is provided, the method comprising:
[0007] Superimposing the basic face image of the first person and the facial feature image of the second person to obtain a training image;
[0008] Input the training image into a preset neural network to obtain an output image, wherein the preset neural network includes: a cyclic generative adversarial network CycleGAN and a Visual Geometry Group (VGG) network;
[0009] Determining a loss function value according to an output image and a target image, wherein the output image is an image obtained by superimposing a face-swapped image of the first person and an output facial feature image of the first person;
[0010] The network parameters of the preset neural network are adjusted according to the loss function value so that the loss function value meets the preset conditions to obtain the face replacement model.
[0011] Another aspect of an embodiment of the present invention provides a face image swap model training device, the device comprising:
[0012] An image superposition unit, used for superimposing a basic face image of a first person and a facial feature image of a second person to obtain a training image;
[0013] An image training unit, used for inputting a training image into a preset neural network to obtain an output image, wherein the preset neural network includes: a CycleGAN network and a VGG network;
[0014] An image processing unit, used to determine a loss function value according to an output image and a target image, wherein the output image is an image obtained by superimposing a face-swapped image of the first person and an output facial feature image of the first person;
[0015] The parameter adjustment unit is used to adjust the network parameters of the combined preset neural network according to the loss function value so that the loss function value meets the preset conditions and obtains the face replacement model.
[0016] According to another aspect of an embodiment of the present invention, a face image swap model training device is provided, the device comprising:
[0017] a processor and a memory storing computer program instructions;
[0018] When the processor executes the computer program instructions, the face image replacement model training method provided by any aspect of the above-mentioned embodiments of the present invention is implemented.
[0019] According to another aspect of an embodiment of the present invention, a computer storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, a face image replacement model training method as provided in any aspect of the above-mentioned embodiment of the present invention is implemented.
[0020] The face-swapping model training method, device, equipment and medium provided in the embodiments of the present invention trains the face-swapping model for a preset neural network composed of a CycleGAN network and a VGG network, and continuously adjusts the network parameters of the preset neural network based on the loss function value so that the loss function value obtained again satisfies the preset conditions. The face-swapping model thus obtained can achieve the goal of obtaining a face-swapping image of the person to be replaced when the basic face image of any person is used as an input image. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the following briefly introduces the drawings required for use in the embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0022] Figure 1 A flow chart showing a method for training a face image swapping model according to an embodiment of the present invention;
[0023] Figure 2 A specific schematic diagram showing adjustment of network parameters of a preset neural network according to an embodiment of the present invention;
[0024] Figure 3 A schematic diagram showing the structure of a face image swap model training device according to an embodiment of the present invention;
[0025] Figure 4 A structural diagram showing an exemplary hardware architecture of a computing device capable of implementing the face image swapping model training method and apparatus according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and Examples. It should be understood that the specific embodiments described herein are only configured to explain the present invention and are not configured to limit the present invention. For those skilled in the art, the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present invention by illustrating examples of the present invention.
[0027] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0028] The following describes in detail the face swap model training method, device, equipment and medium according to the embodiments of the present invention in conjunction with the accompanying drawings. It should be noted that these embodiments are not intended to limit the scope of the present invention.
[0029] Below through Figure 1 The face swap model training method according to an embodiment of the present invention is introduced in detail.
[0030] In order to better understand the present invention, Figure 1 A face image swap model training method according to an embodiment of the present invention is described in detail. Figure 1 Detailed description of the invention The figure is a flowchart showing a method for training a face swap model according to an embodiment of the present invention.
[0031] like Figure 1 As shown, the face image replacement model training method 100 in the embodiment of the present invention includes the following steps:
[0032] S110, superimposing the basic facial image of the first person and the facial feature image of the second person to obtain a training image.
[0033] In one embodiment of the present invention, the basic face image of the first person and the facial feature image of the second person are superimposed, wherein the facial feature image may include the person's posture (which can be understood as the person's left and right head turning posture, up and down head raising posture, and the person's head tilting posture in a plane), expression and face shape. The basic face image can be understood as a photographed image of the person, such as an ID photo, a daily life photo, etc.
[0034] In one embodiment of the present invention, the first person and the second person may be the same person, that is, the neural network model may be trained using the basic facial image of the same person and different facial feature images of the same person, or the neural network model may be trained using basic facial images of different persons and different facial feature images of different persons.
[0035] At the same time, the basic face image and the facial feature image are a 3-channel image. After superimposing the basic face image and the facial feature image, a 6-channel image can be obtained, and the 6-channel image is used as a training image.
[0036] In an embodiment of the present invention, a 6-channel image obtained by superimposing the basic facial image of the first person and the facial feature image of the second person is used as a training image, so that a more comprehensive training image can be obtained, thereby enabling the entire preset neural network to be trained more accurately and obtaining a better neural network convergence effect.
[0037] S120, inputting the training image into a preset neural network to obtain an output image, the preset neural network comprising: a cyclic generative adversarial network CycleGAN and a visual geometry group (Visual Geometry Group, VGG) network.
[0038] In one embodiment of the present invention, a training image is input into a preset neural network to obtain an output image. The preset neural network is composed of a CycleGAN and a VGG network. That is, the output image is obtained by the CycleGAN network, the VGG network performs training supervision on the CycleGAN network, and the network parameters of the preset neural network are adjusted using the loss function value. At the same time, both the output image and the training image are 6-channel images.
[0039] In an embodiment of the present invention, a preset neural network composed of a CycleGAN network and a VGG network is used to train an unpaired image set and obtain more accurate training results.
[0040] S130, determining a loss function value according to an output image and a target image, wherein the output image is an image obtained by superimposing a face-swapped image of the first person and an output facial feature image of the first person.
[0041] The loss function value may refer to the sum of the cycle consistency loss function value Cycle loss, the VGG loss function value VGG loss, the generation loss function value G loss, and the discrimination loss function value D loss. That is, it may be the weighted sum of Cycle loss, VGG loss, G loss, and D loss at a preset ratio.
[0042] In one embodiment of the present invention, the face-swapped image of the first person in the output image is compared with the basic face image of the second person to obtain a loss function value. That is, the loss function value is obtained by using the face-swapped image of the first person with 3 channels and the basic face image of the second person with 3 channels.
[0043] In another embodiment of the present invention, first, based on the face-changing image (3-channel image) of the first person and the basic face image (3-channel image) of the second person, a first function value can be obtained. Using the output face feature image (3-channel image) of the first person and the face feature image (3-channel image) of the first person, a second function value can be obtained. Wherein, the first function value and the second function value can be the weighted sum of Cycle loss, VGG loss, G loss and D loss at a preset ratio.
[0044] Secondly, the first function value and the second function value are weighted and summed based on the preset weights to obtain the loss function value. For example, if the weight ratio of the first function value and the second function value is set to 2:5, the loss function value may be equal to the sum of the product of the first function value and weight 2 and the product of the second function value and weight 3.
[0045] In another embodiment of the present invention, a 6-channel image obtained by superimposing the basic face image of the second person and the facial feature image of the first person is used as the target image, that is, the loss function value can be obtained by superimposing the 6-channel image (output image) of the first person's face-swapped image and the output facial feature image of the first person and the 6-channel image (target image) obtained by superimposing the basic face image of the second person and the facial feature image of the first person.
[0046] In an embodiment of the present invention, by taking the weighted sum of Cycle loss, VGG loss, G loss and D loss at a preset ratio as the loss function value, a more accurate loss function value can be obtained, which facilitates the subsequent accurate adjustment of the network parameters of the preset neural network based on the loss function value to obtain a more accurate face image replacement model.
[0047] S140, adjusting the network parameters of the preset neural network according to the loss function value so that the loss function value meets the preset conditions, thereby obtaining a face replacement model.
[0048] In one embodiment of the present invention, the preset condition means that when the loss function satisfies the preset condition, it can be considered that the entire preset neural network has been trained and the preset neural network can be used as a face swap model. For example, the preset condition is set to a loss function value of 0, that is, when the loss function value is 0, the preset neural network can be used as a face swap model.
[0049] As an example, the network parameters of the preset neural network are adjusted according to the loss function value, wherein the network parameters may be the weight values corresponding to Cycle loss, VGG loss, G loss and D loss, the number of neural network layers of the CycleGAN network, the number of neural network layers of the VGG network and the receptive field. It should be understood that the receptive field refers to the size of the area affected by the pixel points on the output image of each layer of the convolutional neural network on the input image. By adjusting the network parameters of the above-mentioned neural network, the entire preset neural network can be continuously trained and corrected so that the loss function value obtained again can meet the preset conditions, and finally a face swap model is obtained.
[0050] Figure 2 It is a specific schematic diagram showing that the present invention uses the loss function value to adjust the network parameters of the preset neural network.
[0051] like Figure 2 As shown in the figure, after the training image is input into the CycleGAN network, the output image is obtained. The VGG network can obtain the VGG loss value by using the output image and the target image, and the network parameters of the entire preset neural network are adjusted by the VGG loss value. For example, the number of neural network layers of the CycleGAN network, the number of neural network layers of the VGG network, and the receptive field are adjusted.
[0052] Through the face swap model training method described in the above embodiment, the 6-channel image obtained by superimposing the basic face image of the first person and the facial feature image of the second person is used as a training image, and the preset neural network obtained by combining the CycleGAN network and the VGG network is trained, and the loss function value is obtained by outputting the image and the target image, and the network parameters of the preset neural network are continuously adjusted based on the loss function value so that the loss function value obtained again meets the preset conditions. The face swap model obtained in this way can achieve the goal of obtaining the face swap image of the person to be replaced when the basic face image of any person is used as the input image data.
[0053] Below through Figure 3 A face image swapping model training device according to an embodiment of the present invention is introduced in detail. The face image swapping model training device corresponds to the face image swapping model training method.
[0054] Figure 3 A schematic structural diagram of a face image swapping model training device according to an embodiment of the present invention is shown.
[0055] like Figure 3 As shown, the face image replacement model training device 300 includes:
[0056] The image superposition unit 310 is used to superimpose the basic face image of the first person and the facial feature image of the second person to obtain a training image.
[0057] The image training unit 320 is used to input the training image into a preset neural network to obtain an output image. The preset neural network includes: a cyclic generative adversarial network CycleGAN and a visual geometry group VGG network.
[0058] The image processing unit 330 is used to determine the loss function value according to the output image and the target image, wherein the output image is an image obtained by superimposing the face-swapped image of the first person and the output facial feature image of the first person.
[0059] The parameter adjustment unit 340 is used to adjust the network parameters of the preset neural network according to the loss function value so that the loss function value meets the preset conditions and obtains the face image replacement model.
[0060] In one embodiment of the present invention, the training image and the output image are both 6-channel images, and the face-changing image, the basic face image and the face feature image are all 3-channel images. The face feature image may include: posture information and expression information of the face.
[0061] In one embodiment of the present invention, the image processing unit 330 is specifically used to determine the loss function value based on the face-changed image of the first person and the basic face image of the second person, wherein the face-changed image of the first person and the basic face image of the second person are both three-channel images.
[0062] In another embodiment of the present invention, the image processing unit 330 is further specifically used to obtain a first function value through the face-changing image of the first person and the basic face image of the second person, wherein the face-changing image of the first person and the basic face image of the second person are both 3-channel images; obtain a second function value using the output face feature image of the first person and the face feature image of the first person, wherein the output face feature image of the first person and the face feature image of the first person are both 3-channel images;
[0063] The first function value and the second function value are weightedly summed based on preset weights to obtain a loss function value.
[0064] In another embodiment of the present invention, the image processing unit 330 is further configured to use the image obtained by superimposing the basic face image of the second person and the facial feature image of the first person as the target image, and determine the loss function value according to the output image and the target image. The output image and the target image are both 6-channel images.
[0065] In one embodiment of the present invention, the parameter adjustment unit 340 is specifically used to adjust the network parameters of the preset neural network based on the loss function value so that the loss function value satisfies the preset conditions and obtains the face image replacement model. The network parameters of the preset neural network include at least one of the following: weight values corresponding to Cycle loss, VGG loss, G loss and D loss, the number of neural network layers of the CycleGAN network, the number of neural network layers of the VGG network, and the receptive field.
[0066] Through the face swap model training device described in the above embodiment, a 6-channel training image is obtained through the image superposition unit 310, and the preset neural network composed of the CycleGAN network and the VGG network is trained by the image training unit 320 to obtain output data. The image processing unit 330 determines the loss function value based on the output image and the target image, so that the parameter adjustment unit 340 adjusts the network parameters of the preset neural network so that the loss function value meets the preset conditions. The face swap model thus obtained can achieve that when any person's basic face image is used as input image data, a face-swapped image of the person to be replaced can be obtained.
[0067] Figure 4 A structural diagram showing an exemplary hardware architecture of a computing device capable of implementing the face image swapping model training method and apparatus according to an embodiment of the present invention.
[0068] like Figure 4As shown, the computing device 400 includes an input device 401, an input interface 402, a central processing unit 403, a memory 404, an output interface 405, and an output device 406. The input interface 402, the central processing unit 403, the memory 404, and the output interface 405 are connected to each other via a bus 410, and the input device 401 and the output device 406 are connected to the bus 410 via the input interface 402 and the output interface 405, respectively, and then connected to other components of the computing device 400.
[0069] Specifically, the input device 401 receives input information from the outside and transmits the input information to the central processing unit 403 through the input interface 402; the central processing unit 403 processes the input information based on the computer executable instructions stored in the memory 404 to generate output information, temporarily or permanently stores the output information in the memory 404, and then transmits the output information to the output device 406 through the output interface 405; the output device 406 outputs the output information to the outside of the computing device 400 for user use.
[0070] That is to say, Figure 4 The computing device shown can also be used as a device for implementing face swap model training. The face swap model training device may include: a memory storing computer executable instructions; and a processor, which can implement the combination of the computer executable instructions when executing the computer executable instructions. Figures 1 to 3 The invention describes a method and device for training a face swap model.
[0071] An embodiment of the present invention further provides a computer-readable storage medium having computer program instructions stored thereon; when the computer program instructions are executed by a processor, the face image replacement model training method provided by the embodiment of the present invention is implemented.
[0072] It should be clear that the present invention is not limited to the specific configuration and processing described above and shown in the figure. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiment, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention. The functional blocks shown in the structural block diagram described above can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application-specific integrated circuit (ASIC), appropriate firmware, plug-in, function card, etc. When implemented in software, the elements of the present invention are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or communication link via a data signal carried in a carrier. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROMs, flash memories, erasable ROMs (EROMs), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, and the like. The code segments may be downloaded via a computer network such as the Internet, an intranet, or the like.
[0073] The present invention may be implemented in other specific forms without departing from its spirit and essential features. For example, the algorithms described in a specific embodiment may be modified, and the device architecture does not depart from the basic spirit of the present invention. Therefore, the current embodiments are considered to be illustrative and not restrictive in all aspects, the scope of the present invention is defined by the appended claims rather than the above description, and all changes that fall within the meaning and equivalent scope of the claims are thus included in the scope of the present invention.
Claims
1. A face swap model training method, characterized in that: include: Superimposing the basic face image of the first person and the facial feature image of the second person to obtain a training image; Input the training image into a preset neural network to obtain an output image, wherein the preset neural network includes: a cyclic generative adversarial network CycleGAN and a visual geometry group VGG network, and the training image and the output image are both 6-channel images; Determining a loss function value according to the output image and the target image, wherein the output image is an image obtained by superimposing the face-swapped image of the first person and the output facial feature image of the first person, and the target image is a 6-channel image obtained by superimposing the basic facial image of the second person and the facial feature image of the first person; Adjust the network parameters of the preset neural network according to the loss function value so that the loss function value meets the preset conditions, thereby obtaining a face replacement model; Determining a loss function value according to the output image and the target image includes: Obtaining a first function value through the face-swapped image of the first person and the basic face image of the second person, wherein both the face-swapped image of the first person and the basic face image of the second person are 3-channel images; Obtaining a second function value using the output facial feature image of the first person and the facial feature image of the first person, wherein both the output facial feature image of the first person and the facial feature image of the first person are 3-channel images; The first function value and the second function value are weightedly summed based on preset weights to obtain the loss function value.
2. The face image swapping model training method according to claim 1, characterized in that: The loss function value is the sum of the cycle consistency loss function value Cycle loss, the VGG loss function value VGG loss, the generation loss function value G loss and the discrimination loss function value D loss.
3. The face swap model training method according to claim 1, characterized in that: The network parameters of the preset neural network include at least one of the following: The weight values corresponding to Cycle loss, VGG loss, G loss and D loss, the number of neural network layers of the CycleGAN network, the number of neural network layers of the VGG network and the receptive field.
4. The face swap model training method according to claim 1, characterized in that: The facial feature image includes: facial posture information and facial expression information.
5. A face image replacement model training device, characterized in that: include: An image superposition unit, used for superimposing a basic face image of a first person and a facial feature image of a second person to obtain a training image; An image training unit, used for inputting the training image into a preset neural network to obtain an output image, wherein the preset neural network includes: a cyclic generative adversarial network CycleGAN and a visual geometry group VGG network, and the training image and the output image are both 6-channel images; an image processing unit, configured to determine a loss function value according to the output image and a target image, wherein the output image is an image obtained by superimposing the face-swapped image of the first person and the output facial feature image of the first person, and the target image is a 6-channel image obtained by superimposing the basic facial image of the second person and the facial feature image of the first person; A parameter adjustment unit, used for adjusting the network parameters of the preset neural network according to the loss function value, so that the loss function value satisfies a preset condition, thereby obtaining a face image replacement model; The image processing unit is also specifically used to obtain a first function value through a face-changed image of a first person and a basic face image of a second person, wherein the face-changed image of the first person and the basic face image of the second person are both 3-channel images; obtain a second function value using an output facial feature image of the first person and a facial feature image of the first person, wherein the output facial feature image of the first person and the facial feature image of the first person are both 3-channel images; and perform weighted summation of the first function value and the second function value based on preset weights to obtain a loss function value.
6. A face replacement model training device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the face image replacement model training method as described in any one of claims 1-4 is implemented.
7. A computer storage medium, characterized in that: The computer storage medium stores computer program instructions, which, when executed by a processor, implement the face image replacement model training method as described in any one of claims 1-4.
