Face fusion method, device, equipment and storage medium

Through the fusion of segmented face features and target face attributes, combined with GAN and U2-Net feature extraction, it solves the problems of low definition and long time-consuming in the existing face-changing technology, and achieves high-definition face-changing and rapid generation effects.

CN113486944BActive Publication Date: 2024-09-24BEIJING LINGDONG TIANDI CULTURAL DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110748532.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-01
Publication Date
2024-09-24
Estimated Expiration
2041-07-01

Smart Images

  • Figure CN113486944B
    Figure CN113486944B
Patent Text Reader

Abstract

The present invention belongs to the field of image processing technology, and discloses a face fusion method, device, equipment and storage medium. The method comprises: obtaining source face data; determining source data according to the source face data; segmenting the source data to obtain segmented face images; determining source face features according to the segmented face images; generating fused face images according to the source face features and target face attributes. Through the above-mentioned method, the source face data can be segmented into segmented face images containing only faces, and then face features are determined according to the segmented face images, and finally the face features are fused with the target face attributes, so as to obtain a high-definition face-changing image. It effectively alleviates the problems of face blurring after face-changing, face not looking like the source face, and face shape requiring high similarity to be replaced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to a face fusion method, device, equipment and storage medium. Background Art

[0002] Face swapping refers to replacing a target face with a source face and retaining all features of the target face except facial features, such as hair, lighting, open mouth and open eyes. With the continuous development of deep learning, the technology of face swapping through artificial intelligence has developed rapidly in recent years, and people's demand and requirements for face swapping have also increased dramatically. At present, there are a large number of applications in the fields of personalized customized movies, short video creation, AR virtual anchors, virtual makeup trials, picture and video entertainment, role experience, etc., which are changing the production methods of traditional TV series, movies and short videos. Using advanced face swapping algorithms, pictures or videos can be produced very conveniently at a very low cost and in a very short time. It has played a considerable positive role in the fields of film and television, medical care, travel, etc. The emergence of this new technology has also greatly satisfied the needs of the Internet masses for curiosity, beauty and social interaction, and even played a huge role in promoting the accuracy of face recognition algorithms.

[0003] The current face-changing methods are mainly the following three ways: 1. Use Photoshop to change faces, directly cut out the source face and paste it on the target face, and then assist with some stretching deformation, edge blurring and face liquefaction operations to try to erase the traces of face-changing; 2. Use Opencv's built-in traditional algorithm to change faces, first use face detection and key point detection to identify the source face and target face respectively, then use rotation to align the two faces, and then use triangulation to further align the source face to the target face, and finally use Photoshop to do some edge blurring to try to erase the traces of face-changing; 3. Use deep learning to change faces. Deep learning face-changing algorithms have There are many types, which can be divided into two categories: 1. Using the autoencoder algorithm VAE to change faces, directly extracting facial features through the convolutional network and mapping them to a high-dimensional space, and then regenerating a face with the appearance of the source face and the attributes of the target face based on the mapped features; 2. Using the adversarial model GAN ​​to change faces. The face-changing algorithms of GAN are complex and diverse, and a large number of advanced results have been achieved. They can be mainly divided into: a. Algorithms that replace local parts of the face, such as DeepFake, FaceSwap and DeepFaceLab, etc., b. Algorithms that replace the entire head, such as ZAO, FSGAN, FaceController, etc.

[0004] Although the above three face-changing methods have been applied to a certain extent in the market, they still have many shortcomings: For Photoshop face-changing, using ultra-clear source faces and target faces at the same time can obtain ultra-clear replacement results. If the facial shapes of the two faces are particularly similar, Photoshop can achieve a good face-changing effect, but if the facial shapes are not similar, the face-changing effect is poor. If it is processing videos, first of all, it cannot handle various angles of the face and various lighting effects. Secondly, each frame needs to be replaced, which takes a long time. Finally, the direction of the face in each frame may be different; for OpenCV face-changing, the time problem of computer automatic processing is greatly alleviated compared to Photoshop's manual processing. However, even if ultra-clear faces are used for replacement, only occasionally a frontal face will have a better replacement result, and most of the replacement results are failures. Therefore, the disadvantages of traditional algorithms are quite obvious; for deep learning face-changing, the self-encoding face-changing algorithm is some of the algorithms in the early stage of deep learning. It cannot handle faces in complex backgrounds, and due to the defects of the algorithm itself, The definition of the replaced face becomes worse. GAN is a latecomer in deep learning, and the effect has been greatly improved. The face-changing algorithm of GAN is generally stronger than OpenCV, but the shortcomings of various face-changing algorithms of GAN are still obvious. Among them, DeepFake, FaceSwap and DeepFaceLab belong to the same series. Although they are the open source algorithms with the best face-changing effects, they all replace the internal parts of the face, so the generated results completely lose the face shape of the source face, and the properties of the target face such as the lighting effect are not well utilized. At the same time, before each replacement, many high-definition pictures of the source face and the target face must be taken for training, which takes a long time. In summary, the shortcomings of the existing face-changing methods are different, and none of them can solve the face-changing problem well.

[0005] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention

[0006] The main purpose of the present invention is to provide a face fusion method, device, equipment and storage medium, aiming to solve the technical problem of low clarity and poor effect of video face swapping in the prior art.

[0007] To achieve the above object, the present invention provides a face fusion method, which comprises the following steps:

[0008] Get source face data;

[0009] Determining source data according to the source face data;

[0010] Segmenting the source data to obtain segmented face images;

[0011] Determining source facial features according to the segmented facial image;

[0012] A fused face image is generated according to the source face features and the target face attributes.

[0013] Optionally, the step of generating a fused face image according to the source face features and the target face attributes includes:

[0014] Get input features;

[0015] Normalizing the input features to generate normalized features;

[0016] The normalized features, the source face features and the target face attributes are fused to obtain a fused face image.

[0017] Optionally, the step of fusing the normalized features, the source face features and the target face attributes to obtain a fused face image includes:

[0018] Determine a feature scaling factor and a feature translation factor according to the source face feature;

[0019] Determine attribute scaling factor and attribute translation factor according to target face attributes;

[0020] According to the feature scaling factor and the feature translation factor, the source face feature and the normalized feature are fused to obtain a fused feature;

[0021] According to the attribute scaling factor and the attribute translation factor, the target face attribute is fused with the fusion feature to obtain a fused face image.

[0022] Optionally, before the step of generating a fused face image according to the source face features and the target face attributes, the step further includes:

[0023] Get the target face image;

[0024] Determine the target face attributes according to the target face image.

[0025] Optionally, the step of determining target facial attributes according to the target facial image includes:

[0026] The target face image is downsampled a preset number of times and upsampled a preset number of times to obtain target face attributes of a preset number of layers.

[0027] Optionally, after the step of generating a fused face image according to the source face features and the target face attributes, the method further includes:

[0028] Get the video to be replaced;

[0029] Determining target frame data according to the video to be face-swapped;

[0030] A target face to be fused is determined according to the target frame data.

[0031] Optionally, after the step of determining the face image to be fused according to the target frame data, the method further includes:

[0032] Get the source face to be fused;

[0033] Obtaining a segmented face image to be fused according to the source face to be fused;

[0034] Fusing the segmented face image to be fused with the target face to be fused to obtain a target fused face image;

[0035] The target fused face image is used to replace the corresponding target frame data to obtain the target video.

[0036] In addition, to achieve the above-mentioned purpose, the present invention also proposes a face fusion device, which comprises:

[0037] An acquisition module is used to obtain source face data;

[0038] A determination module, used to determine source data according to the source face data;

[0039] A segmentation module, used for segmenting the source data to obtain a segmented face image;

[0040] A feature determination module, used for determining source facial features according to the segmented facial image;

[0041] The fusion module is used to generate a fused face image according to the source face features and the target face attributes.

[0042] In addition, to achieve the above-mentioned purpose, the present invention also proposes a face fusion device, which includes: a memory, a processor, and a face fusion program stored in the memory and executable on the processor, wherein the face fusion program is configured to implement the steps of the face fusion method described above.

[0043] In addition, to achieve the above-mentioned purpose, the present invention also proposes a storage medium, on which a face fusion program is stored, and when the face fusion program is executed by a processor, the steps of the face fusion method described above are implemented.

[0044] The present invention obtains source face data; determines source data according to the source face data; segments the source data to obtain segmented face images; determines source face features according to the segmented face images; generates fused face images according to the source face features and target face attributes. In the above manner, the source face data can be segmented into segmented face images containing only faces, face features are determined according to the segmented face images, and finally the face features are fused with the target face attributes, so as to obtain a high-definition face-changing image. This effectively alleviates the problems of face blurring after face-changing, face not looking like the source face, and face shape requiring high similarity to be replaced. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 It is a structural schematic diagram of a face fusion device in a hardware operating environment involved in an embodiment of the present invention;

[0046] Figure 2 It is a flowchart of the first embodiment of the face fusion method of the present invention;

[0047] Figure 3 A schematic diagram of source data of an embodiment of a face fusion method of the present invention;

[0048] Figure 4 A segmented face image of an embodiment of a face fusion method of the present invention;

[0049] Figure 5 The ArcFace face recognition principle diagram of an embodiment of the face fusion method of the present invention;

[0050] Figure 6 U is an embodiment of the face fusion method of the present invention. 2 -Net model optimization structure diagram;

[0051] Figure 7 It is a diagram of an IIS generation module of an embodiment of a face fusion method of the present invention;

[0052] Figure 8 This is a face fusion effect diagram of an embodiment of a face fusion method of the present invention;

[0053] Fig. 9 It is a structural block diagram of the first embodiment of the face fusion device of the present invention.

[0054] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0055] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0056] Reference Figure 1 , Figure 1 The figure is a schematic diagram of the structure of a face fusion device in the hardware operating environment involved in the embodiment of the present invention.

[0057] like Figure 1 As shown, the face fusion device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) memory, or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0058] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the face fusion device, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.

[0059] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a face fusion program.

[0060] exist Figure 1 In the face fusion device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the face fusion device of the present invention can be set in the face fusion device, and the face fusion device calls the face fusion program stored in the memory 1005 through the processor 1001, and executes the face fusion method provided by the embodiment of the present invention.

[0061] The embodiment of the present invention provides a face fusion method, referring to Figure 2 , Figure 2 The figure is a flowchart of a first embodiment of a face fusion method of the present invention.

[0062] In this embodiment, the face fusion method includes the following steps:

[0063] Step S10: Obtain source face data.

[0064] It should be noted that the execution subject of this embodiment can be a terminal device with computing functions, such as a computer, a smart phone, etc. The method in this embodiment is based on a generative adversarial network (GAN), and the source face data includes face images that need to be replaced in the video. The ultra-clear face data in the public data sets FFHQ and CelebA-HQ are used to train the algorithm in this embodiment.

[0065] Step S20: determining source data according to the source face data.

[0066] It is understandable that the source face data can be processed using the open source code of the CelebA-HQ dataset to obtain aligned faces with a resolution of 256*256. The face alignment task is to automatically locate the key facial feature points, such as the eyes, nose tip, mouth corners, eyebrows, and contour points of various facial parts, based on the input face image. However, this open source code uses dlib to detect faces and obtain face key points, but dlib's face detection rate is not very high, and the key points obtained are not very accurate. Therefore, this embodiment uses the face_alignment face detection library instead. This not only makes face extraction more accurate in the data preprocessing stage, but also in the model effect testing stage, because the face key points obtained by this algorithm are more stable, the jitter when the replaced face is merged with the background image is smaller. Finally, the source data is obtained. The source data is as follows: Figure 3 shown.

[0067] Step S30: Segment the source data to obtain segmented face images.

[0068] It can be understood that the source data includes a face and a background. In order to more clearly decouple the face feature identify and the background attribute style related to the face, this embodiment uses a pixel-level instance segmentation algorithm to first segment the source face to obtain a pure face (i.e., a segmented face image) without background such as hair. The segmentation algorithm is the pix2pixHD algorithm, and its model structure is based on U-Net. The segmented face image is as follows: Figure 4 shown.

[0069] Step S40: determining source facial features according to the segmented facial image.

[0070] In the specific implementation, this embodiment uses the ArcFace algorithm to extract source face features. ArcFace normalizes face features and weights so that the prediction depends only on the angle between the features and the weights. The angle then corresponds to the arc distance on the hypersphere, rather than directly calculating the straight line distance between two feature points. This makes the extraction of face features more complete and comprehensive. Thus, more complete and comprehensive source face features can be extracted from the segmented face image.

[0071] It can be understood that the segmented face image not only includes the face but also the surrounding hair and a small amount of background. Although the face is segmented, the large black background around the face set by the algorithm will have some impact on the ArcFace extraction of facial features. Therefore, the present invention first crops 20 to 45 pixels around the segmented face image before extracting the face and then inputs it into the ArcFace algorithm. The ArcFace face recognition principle is as follows Figure 5 As shown, W1 and W2 represent weights, Class1 and Class2 represent feature sets, and arc / angle margin represents the arc distance.

[0072] Step S50: generating a fused face image according to the source face features and the target face attributes.

[0073] It should be noted that the target face attributes include age, gender, appearance, expression, emotion, mask, face shape, head posture, whether eyes are closed, whether glasses are worn, face quality information and type, etc. The source face features are fused with the target face attributes to obtain the final fused face image.

[0074] Furthermore, in order to obtain more accurate target facial attributes, before step S50, the method further includes: obtaining a target facial image; and determining the target facial attributes according to the target facial image.

[0075] Furthermore, the step of determining target facial attributes according to the target facial image includes: downsampling the target facial image a preset number of times and upsampling the target facial image a preset number of times to obtain target facial attributes of a preset number of layers.

[0076] In the specific implementation, this embodiment is used in conjunction with the variational auto-encoder (VAE) GAN to give full play to their respective advantages. At present, the results of face-changing using only GAN have the problem of insufficient ultra-clearness and lack of details. The use of deep and wide neural networks can alleviate the clarity problem to a certain extent, but such a model can only be trained and inferred on high-end GPUs, and the cost problem is very large. Both ordinary researchers and ordinary companies cannot afford to buy such expensive GPU equipment. 2-Net is a feature extraction algorithm in the field of deep learning image cutting. It has the characteristics of simple model but strong ability to extract detailed features. Therefore, after modifying the algorithm of the original paper, this paper innovatively applies this feature extraction algorithm in the field of image cutting to the field of face swapping to extract the attribute features of the target face. 2 -Net is used as VAE. This algorithm undergoes five downsamplings and five upsamplings, and is supplemented by residual connections and dilated convolution kernels. Each convolution kernel of U-Net is replaced by a U-Net to form an embedded U-Net. Not only is the shallow feature extraction more sufficient, but the receptive field obtained during deep feature extraction is also larger, and a better extraction effect can be obtained in the end. The face is the part of the human body with the richest details. Such an algorithm is more suitable for extracting facial features. In order to maximize the extraction effect of the original algorithm, this embodiment also modifies the feature output part of the original algorithm, changing the single output to a multi-layer output. Each upsampling outputs a target face attribute. The five upsamplings are from the low-resolution target face image attribute extraction to the high-resolution target face image attribute extraction. The resolution of the target face image of the last upsampling is 256*256. A total of five layers of target face attributes are obtained, that is, the preset number of layers of target face attributes. U 2 -Net model optimized structure is as follows Figure 6 As shown, its top layer is a 11stages( Figure 6 The nested U-shaped structure consists of a large U-shaped structure composed of cubes in the image. Each stage is filled with a well-configured RSU. Therefore, the nested U-structure can more effectively extract multi-scale features within the stage and multi-level features in the aggregation stage. En_1, En_2, En_3, En_4, En_5, En_6 are encoders, De_5, De_4, De_3, De_2 and De_1 are decoders, and S (1) , S (2) , S (3) , S (4) , S (5) is the output during upsampling, Downsample is downsampling, Upsample is upsampling, Concatenation means concatenation, Addition means addition, Conv+BN+RELU means the unit of convolution layer, Sigmoid means activation function.

[0077] Furthermore, in order to generate a clearer fused face image, step S50 includes: obtaining input features; normalizing the input features to generate normalized features; and fusing the normalized features, the source face features, and the target face attributes to obtain a fused face image.

[0078] It should be noted that the SPADE algorithm published by NVIDIA uses a space normalization. This normalization algorithm reduces the loss of synthesized image information and makes the synthesized result more detailed. This embodiment designs a face-changing generation algorithm based on SPADE.

[0079] Furthermore, the normalized features, the source facial features and the target facial attributes are fused to obtain a fused facial image, including the steps of: determining a feature scaling factor and a feature translation factor based on the source facial features; determining an attribute scaling factor and an attribute translation factor based on the target facial attributes; fusing the source facial features with the normalized features based on the feature scaling factor and the feature translation factor to obtain a fused feature; fusing the target facial attributes with the fused feature based on the attribute scaling factor and the attribute translation factor to obtain a fused facial image.

[0080] It can be understood that the face-changing generation algorithm is designed as follows:

[0081] 1. Use InstanceNorm to normalize the input features to obtain normalized features;

[0082] 2. Use two fully connected layers to extract the source face features again as the scaling factor and translation factor of the source face data (i.e., feature scaling factor and feature translation factor);

[0083] 3. Use two convolutional layers to extract the target face attributes as the scaling factor and translation factor of the target face image (i.e., attribute scaling factor and attribute translation factor);

[0084] 4. In a serial manner, first fuse the source face features to the normalized features to obtain the fused features, and then fuse the target face attributes to them;

[0085] 5. The above 4 steps are packaged into a module IIS, and each layer of VAE applies the module IIS once when upsampling the target face attributes;

[0086] 6. The output of the last layer of IIS module is generated through the sigmoid function, that is, the fused face image.

[0087] Among them, IIS generates modules such as Figure 7 As shown, represents the input of the k-th layer synthesis, represents the output of the k-th layer synthesis, z id represents the source face features of the kth layer, represents the feature scaling factor of the kth layer, represents the feature translation factor of the kth layer, The target face attributes at the kth layer, represents the attribute scaling factor of the kth layer, It represents the attribute translation factor of the kth layer, conv represents convolution, and FC represents full connection.

[0088] It should be noted that in this embodiment, the GAN part is composed of Hinge loss to form the adversarial loss, and the loss function is as follows:

[0089] L D =E[max(0,1-D(x))]+E[max(0,1+D(G(z)))] Formula 1;

[0090] L G =-E[D(G(z))] Formula 2;

[0091] Among them, D is the discriminator, G is the generator, and L D is the discriminator loss function, L G is the generator loss function and E is the expectation.

[0092] Furthermore, in order to improve the face-swapping effect of faces with obvious differences in profile and face shape, this embodiment independently designs a loss function that adaptively fuses the source face features and the target face features, which can significantly reduce the problem of leaving artifacts due to large differences in face shape. Among them, the target face features are extracted in the same way as the source face features, and the loss function is as follows:

[0093]

[0094]

[0095]

[0096] L id =ratio×L t +(1-ratio)×L s Formula 6;

[0097] Among them, L s is the source face fusion loss function, L t is the target face fusion loss function, L id is the loss function for adaptively fusing the source face and the target face, X s is the source face, X t is the target face, To fuse faces, z id (X s ) is the source face feature, z id (X t ) is the target face feature, To integrate facial features.

[0098] Furthermore, the Euclidean distance is used for gradient descent for the fusion of the target face attributes, and it is used once after each layer of VAE upsampling, so as to achieve multi-layer attribute embedding to promote the final generation effect. The loss function is as follows:

[0099]

[0100] Among them, L att is the multi-layer attribute loss function, is the attribute embedding of layer k.

[0101] Furthermore, when the source face and the target face of the input model are the same face, the following pixel-level reconstruction function is used for gradient descent:

[0102]

[0103] Among them, L rec is the pixel-level reconstruction loss function.

[0104] Furthermore, when the final generated face and background image are fused, there is often a large color difference, which will seriously affect the fusion effect. This embodiment innovatively adds the histogram contrast loss function in the public paper when training face swapping:

[0105]

[0106] Among them, γ l is an artificially defined control factor, O i is the i-th feature map, R(O i ) is the i-th i The resulting histogram.

[0107] Furthermore, it is generally difficult for GAN training to converge, and even more difficult to reach the global optimum. In order to better solve this problem, this embodiment pioneered the introduction of the zero-center gradient penalty term in the open paper on Hinge loss GAN to quickly achieve Nash equilibrium:

[0108]

[0109] Among them, R 1 is the gradient penalty factor, E is the expected value, D is the discriminator, X is the fused face image, and γ is a manually defined control factor. The penalty factor is placed after the previous loss function to monitor the change of the loss function. The discriminator of this embodiment uses the public algorithm PatchGAN, and the fused face image and the generated face processed by PatchGAN are input into this penalty term.

[0110] Furthermore, after step S50, the method further includes: obtaining a video to be replaced with a face; determining target frame data according to the video to be replaced with a face; and determining a target face to be fused according to the target frame data.

[0111] It should be noted that the above steps are the training part of this embodiment. The trained weights are obtained by training the algorithm of this embodiment, and the weights are used to generate the effect of the actual online service.

[0112] It can be understood that after the algorithm training of this embodiment is completed, it is necessary to conduct actual effect testing. When the face of a person in a face-changing video is to be replaced, it is necessary to first identify the frame containing the person whose face needs to be replaced. When performing face fusion, the image is fused. The video to be replaced includes multiple frames of continuous images, so it is necessary to extract frame images from the video to be replaced, that is, target frame data, and the target frame data includes the target face to be fused. The target face to be fused is the original face in the video to be replaced.

[0113] Furthermore, after the step of determining the facial image to be fused according to the target frame data, it also includes: obtaining a source face to be fused; obtaining a segmented facial image to be fused according to the source face to be fused; fusing the segmented facial image to be fused with the target face to be fused to obtain a target fused facial image; replacing the corresponding target frame data with the target fused facial image to obtain a target video.

[0114] It can be understood that the source face to be fused is the image that needs to replace the face in the video to be replaced. The source face to be fused is the face image provided by the tester, which is selected according to the needs of the tester. First, the source face to be fused is extracted to obtain the aligned face. According to the above-mentioned pixel-level instance segmentation algorithm, the aligned face is segmented into segmented face images to be fused that only contain pure faces. Then, the segmented face images to be fused and the target face to be fused are input into the trained algorithm of this embodiment and the target fused face image is obtained according to the trained weight calculation. Then, the target fused face image replaces the target frame data corresponding to the video to be replaced, and finally the target video with successful face replacement is obtained.

[0115] It should be noted that in this embodiment, the segmented face images to be fused that only contain pure faces are used for fusion. Since the influencing factors around the face are completely removed, a better face-changing effect can be obtained. The face-changing effect diagram is shown in FIG. Figure 8 As shown, the left is the target face to be fused, the middle is the source face to be fused, and the right is the fused face image, that is, the target fused face image.

[0116] This embodiment obtains source face data; determines source data based on the source face data; segments the source data to obtain segmented face images; determines source face features based on the segmented face images; and generates a fused face image based on the source face features and target face attributes. In the above manner, the source face data can be segmented into segmented face images containing only faces, face features are determined based on the segmented face images, and finally the face features are fused with the target face attributes, thereby obtaining a high-definition face-changing image. Based on GAN, a new face-changing algorithm is designed by referring to the algorithms published in international top journals to solve the defects of the three major methods in the field of face-changing. Once the training is completed, the subsequent face-changing operation is simple and the effect is stable. It effectively alleviates the problems of long face-changing time, blurred generated faces, generated faces that are not like the source faces, face shapes that need to be highly similar to be replaced, black circles, easy to leave artifacts, high failure rate, each replacement requires a large amount of high-quality data training, and technical blockades by individual companies. In particular, the optimization effect is obvious in the following aspects: the algorithm of the present invention can be used on a large scale on ordinary GPUs, the single-frame face-changing time is fast, the generated face is ultra-clear, the replacement is more like the source face, the replacement of dissimilar face shapes is less likely to fail, and no retraining is required before each face-changing. Among them, the overall solution of the algorithm is independently designed by the present invention. The introduction of pix2pixHD pixel-level instance segmentation, the introduction of histogram loss function, and the introduction of zero center gradient penalty on Hinge loss GAN are all pioneering designs in the field of GAN face-changing. The introduction and corresponding optimization of the U2-Net feature extraction scheme are original solutions. The IIS generation module and the adaptive fusion loss function are new independently designed algorithms.

[0117] In addition, an embodiment of the present invention further proposes a storage medium, on which a face fusion program is stored. When the face fusion program is executed by a processor, the steps of the face fusion method described above are implemented.

[0118] Reference Fig. 9 , Fig. 9 It is a structural block diagram of the first embodiment of the face fusion device of the present invention.

[0119] like Fig. 9 As shown, the face fusion device proposed in the embodiment of the present invention includes:

[0120] The acquisition module 10 is used to acquire source face data.

[0121] The determination module 20 is used to determine the source data according to the source face data.

[0122] The segmentation module 30 is used to segment the source data to obtain segmented face images.

[0123] The feature determination module 40 is used to determine the source face features according to the segmented face image.

[0124] The fusion module 50 is used to generate a fused face image according to the source face features and the target face attributes.

[0125] In one embodiment, the fusion module 50 is further used to obtain input features; normalize the input features to generate normalized features; and fuse the normalized features, the source face features, and the target face attributes to obtain a fused face image.

[0126] In one embodiment, the fusion module 50 is also used to determine a feature scaling factor and a feature translation factor based on the source facial features; determine an attribute scaling factor and an attribute translation factor based on the target facial attributes; fuse the source facial features with the normalized features according to the feature scaling factor and the feature translation factor to obtain a fused feature; fuse the target facial attributes with the fused feature according to the attribute scaling factor and the attribute translation factor to obtain a fused facial image.

[0127] In one embodiment, the fusion module 50 is further used to obtain a target face image; and determine the target face attributes according to the target face image.

[0128] In one embodiment, the fusion module 50 is further used to perform downsampling and upsampling of the target facial image for a preset number of times to obtain a preset number of layers of target facial attributes.

[0129] In one embodiment, the fusion module 50 is further used to obtain a video to be replaced with a face; determine target frame data based on the video to be replaced with a face; and determine a target face to be fused based on the target frame data.

[0130] In one embodiment, the fusion module 50 is also used to obtain a source face to be fused; obtain a segmented face image to be fused based on the source face to be fused; fuse the segmented face image to be fused with the target face to be fused to obtain a target fused face image; replace the corresponding target frame data with the target fused face image to obtain a target video.

[0131] It should be understood that the above is only an example and does not constitute any limitation on the technical solution of the present invention. In specific applications, technicians in this field can make settings as needed, and the present invention does not limit this.

[0132] This embodiment obtains source face data; determines source data based on the source face data; segments the source data to obtain segmented face images; determines source face features based on the segmented face images; and generates fused face images based on the source face features and target face attributes. In the above manner, the source face data can be segmented into segmented face images containing only faces, face features are determined based on the segmented face images, and finally the face features are fused with the target face attributes, thereby obtaining a high-definition face-changing image. This effectively alleviates the problems of face blurring after face-changing, faces not resembling the source face, and the face shape requiring a high degree of similarity to be replaced.

[0133] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.

[0134] In addition, for technical details not fully described in this embodiment, reference can be made to the face fusion method provided in any embodiment of the present invention, and will not be repeated here.

[0135] In addition, it should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system 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 system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0136] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0137] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0138] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A face fusion method, characterized in that: The face fusion method comprises: Get source face data; Determine source data according to the source face data, and process the source face data through the face_alignment face detection library to obtain the source data; Segmenting the source data to obtain a segmented face image, and using a pix2pixHD algorithm to decouple face features and background attributes in the source data to obtain a face segmentation image, wherein the model structure of the pix2pixHD algorithm is a network structure based on U-Net; Determine source facial features according to the segmented facial image, crop pixels within a preset range around the segmented facial image, and then input the cropped segmented facial image into an ArcFace algorithm, wherein the ArcFace algorithm normalizes facial features and weights to extract source facial features; Generate a fused face image based on the source face features and the target face attributes, wherein the target face attributes include at least one of age, gender, appearance, expression, emotion, mask, face shape, head posture, whether eyes are closed, whether glasses are worn, and face quality information. 2 -Net is used as a variational encoder. After five downsamplings and five upsamplings, it is supplemented by residual connections and dilated convolution kernels. Each convolution kernel of U-Net is replaced by a U-Net to form an embedded U-Net. The target face attributes of the preset number of layers are obtained. Hinge loss constitutes the adversarial loss, and the loss function is L D =E[max(0,1-D(x))]+E[max(0,1+D(G(z)))],L G = -E[D(G(z))], where D is the discriminator, G is the generator, and L D is the discriminator loss function, L G is the generator loss function, E is the expectation, D(x) is the output value of the discriminator, x is the input value of the discriminator, G(z) is the output value of the generator, z is the input value of the generator, and the loss function of adaptively fusing the source face features and the target face features is Lid=ratio×Lt+(1-ratio)×Ls, where L s is the source face fusion loss function, L t is the target face fusion loss function, L id is the loss function for adaptively fusing the source face and the target face, X s is the source face, X t is the target face, To fuse faces, z id (X s ) is the source face feature, z id (X t ) is the target face feature, To integrate facial features.

2. The method according to claim 1, characterized in that The step of generating a fused face image according to the source face features and the target face attributes comprises: Get input features; Normalizing the input features to generate normalized features; The normalized features, the source face features and the target face attributes are fused to obtain a fused face image.

3. The method according to claim 2, characterized in that The step of fusing the normalized features, the source face features and the target face attributes to obtain a fused face image comprises: Determine a feature scaling factor and a feature translation factor according to the source face feature; Determine attribute scaling factor and attribute translation factor according to target face attributes; According to the feature scaling factor and the feature translation factor, the source face feature and the normalized feature are fused to obtain a fused feature; According to the attribute scaling factor and the attribute translation factor, the target face attribute is fused with the fusion feature to obtain a fused face image.

4. The method according to claim 1, characterized in that Before the step of generating a fused face image according to the source face features and the target face attributes, the method further includes: Get the target face image; Determine the target face attributes according to the target face image.

5. The method according to claim 4, characterized in that The step of determining the target face attributes according to the target face image comprises: The target face image is downsampled a preset number of times and upsampled a preset number of times to obtain target face attributes of a preset number of layers.

6. The method according to claim 1, characterized in that After the step of generating a fused face image according to the source face features and the target face attributes, the method further includes: Get the video to be replaced; Determining target frame data according to the video to be face-swapped; A target face to be fused is determined according to the target frame data.

7. The method according to any one of claim 6, characterized in that After the step of determining the face image to be fused according to the target frame data, the method further includes: Get the source face to be fused; Obtaining a segmented face image to be fused according to the source face to be fused; Fusing the segmented face image to be fused with the target face to be fused to obtain a target fused face image; The target fused face image is used to replace the corresponding target frame data to obtain the target video.

8. A face fusion device, characterized in that: The face fusion device comprises: An acquisition module is used to obtain source face data; A determination module, used to determine source data according to the source face data, and process the source face data through the face_alignment face detection library to obtain the source data; A segmentation module is used to segment the source data to obtain a segmented face image, and to decouple the face features and background attributes in the source data using a pix2pixHD algorithm to obtain a face segmentation image. The model structure of the pix2pixHD algorithm is a network structure based on U-Net. a feature determination module, for determining source face features according to the segmented face image, cropping pixels within a preset range around the segmented face image, and then inputting the cropped segmented face image into an ArcFace algorithm, wherein the ArcFace algorithm normalizes the face features and weights to extract source face features; A fusion module is used to generate a fused face image according to the source face features and the target face attributes, wherein the target face attributes include at least one of age, gender, appearance, expression, emotion, mask, face shape, head posture, whether eyes are closed, whether glasses are worn, and face quality information. 2 -Net is used as a variational encoder. After five downsamplings and five upsamplings, it is supplemented by residual connections and dilated convolution kernels. Each convolution kernel of U-Net is replaced by a U-Net to form an embedded U-Net. The target face attributes of the preset number of layers are obtained. Hinge loss constitutes the adversarial loss, and the loss function is L D =E[max(0,1-D(x))]+E[max(0,1+D(G(z)))],L G = -E[D(G(z))], where D is the discriminator, G is the generator, and L D is the discriminator loss function, L G is the generator loss function, E is the expectation, D(x) is the output value of the discriminator, x is the input value of the discriminator, G(z) is the output value of the generator, z is the input value of the generator, and the loss function of adaptively fusing the source face features and the target face features is Lid=ratio×Lt+(1-ratio)×Ls, where L s is the source face fusion loss function, L t is the target face fusion loss function, L id is the loss function for adaptively fusing the source face and the target face, X s is the source face, X t is the target face, To fuse faces, z id (X s ) is the source face feature, z id (X t ) is the target face feature, To integrate facial features.

9. A face fusion device, characterized in that: The device comprises: a memory, a processor, and a face fusion program stored in the memory and executable on the processor, wherein the face fusion program is configured to implement the face fusion method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium stores a face fusion program, and when the face fusion program is executed by the processor, the face fusion method according to any one of claims 1 to 7 is implemented.