Image processing method, device, electronic device and computer readable storage medium

Through feature extraction and reconstruction of facial image sample pairs, a triplet data set is constructed to converge the image processing model, which solves the problem of unstable face replacement model training in the existing technology and improves the accuracy and stability of image processing. .

CN116630138BActive Publication Date: 2024-10-18TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210121870.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-09
Publication Date
2024-10-18
Estimated Expiration
2042-02-09

AI Technical Summary

Technical Problem

Existing image processing methods lack supervision information during the face replacement process, resulting in unstable model training, low accuracy, and prone to bad cases.

Method used

By obtaining facial image sample pairs, using a preset image processing model for feature extraction, facial replacement and reconstruction, a triplet data set is constructed, the model is converged, and training stability and accuracy are improved.

Benefits of technology

It improves the accuracy and stability of image processing, reduces the occurrence of bad cases, and improves the accuracy of face replacement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116630138B_ABST
    Figure CN116630138B_ABST
Patent Text Reader

Abstract

The embodiments of the present invention disclose an image processing method, device, electronic device and computer-readable storage medium. After acquiring at least one facial image sample pair, the embodiments of the present invention use a preset image processing model to extract features of the facial image samples to obtain sample facial features, perform facial replacement on facial template image samples based on the sample facial features to obtain a replaced facial image, then reconstruct the facial image samples based on the sample facial features to obtain a reconstructed facial image, then converge the preset image processing model based on the facial image samples, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and use the trained image processing model to perform facial replacement on the facial image to be processed. This scheme can improve the accuracy of image processing, and the embodiments of the present invention can be applied to various scenarios such as cloud technology, artificial intelligence, smart transportation, and assisted driving.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to an image processing method, device, electronic device and computer-readable storage medium. Background Art

[0002] In recent years, with the development of technology, in applications such as movie special effects and Internet social networking, there is a demand to replace the face of an object with the face of another object while maintaining the style of the object in the facial image. To meet this demand, the facial image needs to be processed. Existing image processing methods mainly use a many-to-many image processing model for facial replacement processing.

[0003] In the process of research and practice of the prior art, the inventors of the present invention found that when training a many-to-many image processing model, a large number of unlabeled facial images are usually used for training. Due to the lack of supervised information, the image processing model is unstable during training and bad cases are prone to occur, resulting in low image processing accuracy. Summary of the invention

[0004] Embodiments of the present invention provide an image processing method, an apparatus, an electronic device, and a computer-readable storage medium, which can improve the accuracy of image processing.

[0005] An image processing method, comprising:

[0006] Acquire at least one facial image sample pair, wherein the facial image sample pair comprises a facial image sample and a facial template image sample;

[0007] Using a preset image processing model to extract features from the facial image sample to obtain sample facial features;

[0008] Performing facial replacement on the facial template image sample according to the sample facial features to obtain a replaced facial image;

[0009] Reconstructing the facial image sample based on the sample facial features to obtain a reconstructed facial image;

[0010] The preset image processing model is converged according to the facial image samples, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and the trained image processing model is used to perform facial replacement on the facial image to be processed.

[0011] Accordingly, an embodiment of the present invention provides an image processing device, including:

[0012] An acquisition unit, configured to acquire at least one facial image sample pair, wherein the facial image sample pair comprises a facial image sample and a facial template image sample;

[0013] An extraction unit, configured to extract features from the facial image sample using a preset image processing model to obtain facial features of the sample;

[0014] A first replacement unit, configured to perform face replacement on the facial image sample according to the sample facial features and the facial template image sample to obtain a replaced facial image;

[0015] A reconstruction unit, configured to reconstruct the facial image sample based on the sample facial features to obtain a reconstructed facial image;

[0016] The second replacement unit is used to converge the preset image processing model according to the facial image sample, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and use the trained image processing model to perform facial replacement on the facial image to be processed.

[0017] Optionally, in some embodiments, the second replacement unit includes:

[0018] An acquisition subunit, used for acquiring a facial image to be processed and a facial template image corresponding to the facial image to be processed;

[0019] An extraction subunit, used to use the trained image processing model to perform feature extraction on the facial image to be processed and the facial template image respectively, to obtain facial features of the facial image to be processed and facial template features of the facial template image;

[0020] A construction subunit, used for fusing the facial features with the facial template features, and constructing a fused facial image based on the fused facial features;

[0021] A segmentation subunit, used for performing facial region segmentation on the facial template image and the fused facial image to obtain a facial region;

[0022] The fusion subunit is used to perform facial fusion on the fused facial image and the facial template image based on the facial area to obtain a target facial image.

[0023] Optionally, in some embodiments, the first replacement unit can be specifically used to use the preset image processing model to extract features from the facial template image sample to obtain facial style features; perform multi-size fusion of the facial style features and sample facial features to obtain first fused sample facial features at each size; and perform facial replacement on the facial template image sample based on the first fused sample facial features to obtain a replaced facial image.

[0024] Optionally, in some embodiments, the first replacement unit can be specifically used to extract basic facial style features at each size from the facial style features, and extract basic sample facial features at each size from the sample facial features; calculate style feature parameters of the basic facial style features and facial feature parameters of the basic sample facial features; and based on the style feature parameters and facial feature parameters, fuse the basic facial style features and the basic sample facial features to obtain a first fused sample facial feature at each size.

[0025] Optionally, in some embodiments, the first replacement unit can be specifically used to fuse the basic facial style features and basic sample facial features at the same size based on the style feature parameters and the facial feature parameters to obtain initial fused sample facial features at each size; determine the facial area mask corresponding to the facial image sample at each size based on the initial fused sample facial features, and the facial area mask is used to indicate the attention weights between the initial fused facial features; fuse the facial area mask with the initial fused sample facial features to obtain the first fused sample facial features at each size.

[0026] Optionally, in some embodiments, the first replacement unit can be specifically used to extract associated features from the initial fused sample facial features; determine an associated weight corresponding to each of the initial fused sample facial features based on the associated features, and the associated weight is used to indicate the association relationship between the initial fused sample facial features; and generate a facial area mask corresponding to the facial image sample at each size based on the associated weight.

[0027] Optionally, in some embodiments, the first replacement unit can be specifically used to calculate the variance ratio of the style feature variance and the facial feature variance; calculate the feature difference between the feature value of the basic facial feature and the facial feature mean; and fuse the variance ratio, feature difference and style feature mean to obtain the initial fused sample facial features at each size.

[0028] Optionally, in some embodiments, the first replacement unit can be specifically used to generate a basic facial image of a size corresponding to each of the first fused facial features according to the first fused sample facial features; sort the basic facial images according to the sizes of the basic facial images to obtain sorting information; and adjust the size of the basic facial images according to the sorting information to obtain a replaced facial image.

[0029] Optionally, in some embodiments, the first replacement unit can be specifically used to filter out the basic facial image with the smallest size from the basic facial images to obtain a current basic facial image; enlarge the size of the current basic facial image to obtain an enlarged basic facial image; according to the sorting information, filter out the next basic facial image of the current basic facial image from the basic facial images to obtain a target basic facial image; and fuse the enlarged basic facial image and the target basic facial image to obtain the replaced facial image.

[0030] Optionally, in some embodiments, the first replacement unit can be specifically used to fuse the enlarged basic facial image and the target basic facial image to obtain a fused basic facial image; enlarge the size of the fused basic facial image to obtain a target enlarged basic facial image; use the target basic facial image as the current basic facial image, and use the target enlarged basic facial image as the enlarged basic facial image; return to execute the step of filtering out the next basic facial image of the current basic facial image from the basic facial images according to the sorting information, until the last basic facial image is filtered out, and fuse the filtered target basic facial image with the enlarged basic facial image to obtain a replaced facial image.

[0031] Optionally, in some embodiments, the second replacement unit can be specifically used to determine the reconstruction perceptual loss information of the facial image sample pair based on the facial image sample and the reconstructed facial image; determine the label perceptual loss information of the facial image sample pair based on the facial image sample and the replaced facial image; fuse the reconstruction perceptual loss information and the label perceptual loss information to obtain the perceptual loss information of the facial image sample pair; determine the adversarial loss information of the facial image sample pair based on the replaced facial image and the facial image sample; fuse the perceptual loss information and the adversarial loss information, and based on the fused loss information, converge the preset image processing model to obtain the trained image processing model.

[0032] Optionally, in some embodiments, the second replacement unit can be specifically used to obtain facial label information in the facial image sample, and identify a facial label area in the facial image sample based on the facial label information; identify a target facial area corresponding to the facial label area in the replaced facial image; perform feature extraction on the facial label area to obtain facial label area features, and perform feature extraction on the target facial area to obtain target facial area features; calculate the feature difference between the target facial area features and the facial label area features to obtain label perception loss information of the facial image sample pair.

[0033] Optionally, in some embodiments, the reconstruction unit can be specifically used to use the preset image processing model to extract features from the facial image samples to obtain sample facial style features; perform multi-size fusion of the sample facial style features and sample facial features to obtain second fused sample facial features at each size; and perform facial replacement on the facial image samples based on the second fused sample facial features to obtain reconstructed facial image samples.

[0034] Optionally, in some embodiments, the second replacement unit can be specifically used to obtain a facial image to be processed and a facial template image corresponding to the facial image to be processed; use the trained image processing model to perform feature extraction on the facial image to be processed and the facial template image respectively to obtain facial features of the facial image to be processed and facial template features of the facial template image; fuse the facial features and the facial template features, and construct a fused facial image based on the fused facial features; perform facial region segmentation on the facial template image and the fused facial image to obtain facial regions; and perform facial fusion on the fused facial image and the facial template image based on the facial regions to obtain a target facial image.

[0035] Optionally, in some embodiments, the second replacement unit can be specifically used to convert the facial features into a preset number of basic facial features, and determine the convolution layer corresponding to each of the basic facial features; convert the facial template features into the preset number of basic facial template features, and determine the convolution layer corresponding to each of the basic facial template features; and fuse the basic facial features and the basic facial template features according to the convolution layer to obtain fused facial features.

[0036] Optionally, in some embodiments, the second replacement unit can be specifically used to filter out basic facial features corresponding to a preset first convolutional layer from the basic facial features to obtain target basic facial features; filter out basic facial template features corresponding to a preset second convolutional layer from the basic facial template features to obtain target basic facial template features; and use the convolutional layer to fuse the target basic facial features and the target basic facial template features to obtain fused facial features.

[0037] Optionally, in some embodiments, the second replacement unit can be specifically used to perform multi-dimensional feature extraction on the fused facial image to obtain facial area features of multiple dimensions; perform multi-dimensional feature extraction on the facial template image to obtain template facial area features of multiple dimensions; segment a fused facial area in the fused facial image based on the facial area features; segment a template facial area in the facial template image based on the template facial area features, and use the fused facial area and the template facial area as the facial area.

[0038] Optionally, in some embodiments, the second replacement unit can be specifically used to perform global pooling on the facial region features to obtain first pooled facial region features; determine a first attention weight of each of the facial region features based on the first pooled facial region features; and segment a fused facial region in the fused facial image according to the first attention weight.

[0039] Optionally, in some embodiments, the second replacement unit can be specifically used to weight the facial region features based on the first attention weight to obtain a first weighted facial region feature; globally pool the first weighted facial region features, and determine the second attention weight of the first weighted facial region features based on the pooled second pooled facial region features; and segment the fused facial region in the fused facial image according to the first weighted facial region features and the second attention weight.

[0040] Optionally, in some embodiments, the second replacement unit is specifically used to weight the first weighted rear facial region feature based on the second attention weight to obtain a second weighted rear facial region feature; segment the current facial mask in the fused facial image according to the first weighted rear facial region feature and the second weighted rear facial region feature; identify the area corresponding to the current facial mask in the fused facial image to obtain a fused facial region.

[0041] Optionally, in some embodiments, the second replacement unit can be specifically used to perform color correction on the fused facial image according to the fused facial area and the template facial area to obtain a corrected fused facial image; detect facial key points in the facial template image to obtain first facial key points, and detect facial key points in the corrected fused facial image to obtain second facial key points; and perform facial fusion on the fused facial image and the facial template image according to the first facial key points and the second facial key points to obtain a target facial image.

[0042] Optionally, in some embodiments, the second replacement unit can be specifically used to perform color space conversion on the fused facial area and the template facial area to obtain a target fused facial area and a target template facial area in a target color space; calculate color parameters of the target fused facial area to obtain first color parameters, and calculate color parameters of the target template facial area to obtain second color parameters; correct each color channel of the target fused facial area according to the first color parameters and the second color parameters to obtain a corrected fused facial image.

[0043] Optionally, in some embodiments, the second replacement unit can be specifically used to calculate the variance ratio of the first pixel variance and the second pixel variance under each color channel, and calculate the pixel difference between the current pixel value and the first pixel mean under each color channel; fuse the pixel difference, the variance ratio and the second pixel mean to obtain the target pixel value of each color channel; replace the current pixel value of each color channel of the target fused facial area with the corresponding target pixel value to obtain a corrected fused facial image.

[0044] Optionally, in some embodiments, the second replacement unit can be specifically used to extract features from the facial template image to obtain lightweight facial key point features in multiple dimensions; fuse the lightweight facial key point features to obtain facial key point features; and identify facial key points in the facial template image based on the facial key point features to obtain first facial key points.

[0045] Optionally, in some embodiments, the second replacement unit can be specifically used to compare the first facial key point with the second facial key point to obtain key point deformation information; based on the key point deformation information, adjust the lightweight facial key point features; determine the interpolation information for deforming the first facial key point to the second facial key point according to the adjusted key point facial features; based on the interpolation information, deform the abnormal key points that are different from the first facial key point and the second facial key point to obtain a deformed facial template image; and fuse the fused facial image and the deformed facial template image to obtain a target facial image.

[0046] In addition, an embodiment of the present invention further provides an electronic device, including a processor and a memory, wherein the memory stores an application program, and the processor is used to run the application program in the memory to implement the image processing method provided by the embodiment of the present invention.

[0047] In addition, an embodiment of the present invention further provides a computer-readable storage medium, which stores a plurality of instructions, and the instructions are suitable for a processor to load to execute the steps in any one of the image processing methods provided by the embodiments of the present invention.

[0048] After acquiring at least one facial image sample pair, the embodiment of the present application uses a preset image processing model to perform feature extraction on the facial image samples to obtain sample facial features, performs facial replacement on the facial template image samples based on the sample facial features to obtain a replaced facial image, then reconstructs the facial image samples based on the sample facial features to obtain a reconstructed facial image, then converges the preset image processing model based on the facial image samples, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and uses the trained image processing model to perform facial replacement on the facial image to be processed; since the scheme can reconstruct the facial image samples after extracting features from the facial image samples, thereby forming a triple data set of facial image samples, facial template image samples and reconstructed facial images, and converges the preset image processing model based on the triple data, the stability and processing accuracy of the image processing training are greatly improved, and therefore the accuracy of image processing can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0050] Figure 1 is a scene schematic diagram of the image processing method provided by an embodiment of the present invention;

[0051] Figure 2 is another flowchart of the image processing method provided by an embodiment of the present invention;

[0052] Figure 3 is a schematic diagram of a process of cascading amplification of a basic facial image provided by an embodiment of the present invention;

[0053] Figure 4 It is a schematic diagram of the process of performing face replacement using a face template image provided by an embodiment of the present invention;

[0054] Figure 5 is a schematic diagram of training a preset image processing model provided by an embodiment of the present invention;

[0055] Figure 6 is a schematic diagram of the structure of the attention module provided by an embodiment of the present invention;

[0056] Figure 7 It is a schematic diagram of a process of segmenting a current facial mask from a fused facial image provided by an embodiment of the present invention;

[0057] Figure 8 is a schematic diagram of a process for processing a facial template image provided by an embodiment of the present invention;

[0058] Fig. 9 It is a schematic diagram of a process of fusing a facial image to be processed and a facial template image provided by an embodiment of the present invention;

[0059] Fig.10 is another flowchart of the image processing method provided by an embodiment of the present invention;

[0060] Fig.11 is a structural schematic diagram of an image processing device provided by an embodiment of the present invention;

[0061] Fig.12 is a schematic structural diagram of a second replacement unit in an image processing device provided by an embodiment of the present invention;

[0062] Fig.13 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0063] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0064] The embodiment of the present invention provides an image processing method, device, electronic device and computer-readable storage medium. The image processing device can be integrated in an electronic device, which can be a server or a terminal.

[0065] Among them, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, network acceleration services (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms. Terminals include but are not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, etc. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application. The embodiments of the present invention can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.

[0066] For example, see Figure 1 Taking the image processing device integrated in an electronic device as an example, after obtaining at least one facial image sample pair, the electronic device uses a preset image processing model to extract features of the facial image samples in the facial image sample pair to obtain sample facial features, and performs facial replacement on the facial template image sample based on the sample facial features to obtain a replaced facial image, and then reconstructs the facial image sample based on the sample facial features to obtain a reconstructed facial image, and converges the preset image processing model based on the facial image samples, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and uses the trained image processing model to perform facial replacement on the facial image to be processed, thereby improving the accuracy of image processing.

[0067] Among them, image processing can be understood as facial image processing, which can be understood as replacing the facial object in the facial template image. Taking the face as an example, facial image processing can be face swapping, which means replacing the face in the facial template image with the face in the target image while keeping the posture, expression, makeup, background and other elements of the face in the facial template image unchanged. It can usually be applied in scenes such as film and television production, game entertainment and e-commerce sales.

[0068] The image processing method provided in the embodiment of the present application relates to the computer vision direction in the field of artificial intelligence. The embodiment of the present application can extract features from facial image samples, and perform facial replacement on facial template images and reconstruct facial image samples based on the extracted sample facial features.

[0069] Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science. It attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making. Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level technology and software-level technology. Among them, artificial intelligence software technology mainly includes computer vision technology, machine learning / deep learning and other directions.

[0070] Among them, Computer Vision (CV) is a science that studies how to make machines "see". To put it more specifically, it refers to machine vision that uses computers to replace human eyes to identify and measure targets, and further processes images so that the images are processed by computers to become more suitable for human observation or transmission to instruments for detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multidimensional data. Computer vision technology usually includes technologies such as image processing and image recognition, as well as common biometric recognition technologies such as face recognition and human posture recognition.

[0071] It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.

[0072] This embodiment will be described from the perspective of an image processing device, which can be specifically integrated into an electronic device, which can be a server or a terminal. The terminal can include a tablet computer, a laptop computer, a personal computer (PC), a wearable device, a virtual reality device, or other smart devices that can perform face replacement.

[0073] An image processing method, comprising:

[0074] At least one facial image sample pair is obtained, the facial image sample pair comprising a facial image sample and a facial template image sample, a preset image processing model is used to perform feature extraction on the facial image sample to obtain sample facial features, facial template image samples are used for facial replacement according to the sample facial features to obtain a replaced facial image, facial image samples are reconstructed based on the sample facial features to obtain a reconstructed facial image, a preset image processing model is converged according to the facial image samples, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and the trained image processing model is used to perform facial replacement on the facial image to be processed.

[0075] like Figure 2 As shown, the specific process of the image processing method is as follows:

[0076] 101. Obtain at least one facial image sample pair.

[0077] The facial image sample pair may include a facial image sample and a facial template image sample. The facial image sample may be an image sample that provides a facial source object for replacement, and the facial template image sample may be a template image sample that needs to replace the facial object with the facial source object while keeping the regional elements other than the face unchanged.

[0078] There are many ways to obtain facial image sample pairs, which can be as follows:

[0079] For example, a facial image sample pair sent by a terminal may be received, the facial image sample pair including a facial image sample and a facial template image sample; or, facial image samples may be obtained from a network or an image database, the facial image samples may be sent to a template image server, and facial template image samples corresponding to each facial image sample returned by the simulated image server may be received, and the facial image samples and the facial template image samples may be combined to form a facial image sample pair; or, an original facial image may be obtained from a network or an image database, and facial image samples and facial template image samples corresponding to the facial image samples may be screened out from the original facial image samples, thereby obtaining a facial image sample pair; the screening condition may be that the faces of the objects in the facial image sample and the facial template image are different; or, when the number of facial image sample pairs is large or the memory is large, a facial image processing request may be received, the facial image sample processing request carrying the storage address of the facial image sample pair, and the facial image sample pair may be obtained according to the storage address.

[0080] 102. Use a preset image processing model to extract features from facial image samples to obtain facial features of the samples.

[0081] The sample facial feature may be feature information representing a facial region in a facial image sample, and the sample facial feature may be a multi-dimensional feature vector.

[0082] There are many ways to extract features from facial image samples using a preset image processing model, which can be as follows:

[0083] For example, a feature extraction network of a preset image processing model can be used to perform convolution feature extraction on facial image samples to obtain initial sample facial features. Then, a fully connected layer is used to process the initial sample facial features to obtain a 256-dimensional feature vector, which is used as the sample facial feature.

[0084] 103. Perform facial replacement on the facial template image sample according to the facial features of the sample to obtain a replaced facial image.

[0085] Among them, face replacement can be to replace the face area in the face template image sample with the face area in the face image sample. Taking the face image as a human face as an example, it can be understood as face swapping or face fusion, that is, to replace the face in the face template image sample with the face in the face image sample, while keeping the area except the face area unchanged.

[0086] There are many ways to perform face replacement on the face template image sample according to the sample facial features, which can be as follows:

[0087] For example, a preset image processing model can be used to extract features from a facial template image to obtain facial style features, and the facial style features and sample facial features can be fused at multiple sizes to obtain the first fused sample facial features at each size. Based on the first fused sample facial features, facial replacement can be performed on the facial template image sample to obtain a replaced facial image.

[0088] Among them, the facial style features can be used to indicate the feature information of the style of the facial area in the facial template image sample. There are many ways to fuse the facial style features and the sample facial features at multiple sizes. For example, the basic facial style features at each size can be extracted from the facial style features, and the basic sample facial features at each size can be extracted from the sample facial features, and the style feature parameters of the basic facial style features and the facial feature parameters of the basic sample facial features are calculated. Based on the style feature parameters and the facial feature parameters, the basic facial style features and the basic sample facial features are fused to obtain the first fused sample facial features at each size.

[0089] Among them, the style feature parameters may include the style feature variance and the style feature mean, and the facial feature parameters include the facial feature variance and the facial feature mean. Therefore, there are many ways to calculate the style feature parameters of the basic facial style features and the facial feature parameters of the basic sample facial features. For example, for the style feature parameters, the facial style feature values ​​under each feature channel in the basic facial style features may be obtained, the variance of the facial style feature values ​​may be calculated to obtain the style feature variance, and the mean of the facial style feature values ​​may be calculated to obtain the style feature mean, and the style feature variance and the style feature mean may be used as the style feature parameters. For the facial feature parameters, the facial feature values ​​under each feature channel in the basic sample facial features may be obtained, and then the variance of the facial feature values ​​may be calculated to obtain the facial feature variance, and the mean of the facial feature values ​​may be calculated to obtain the facial feature mean, and the facial feature variance and the facial feature mean may be used as the facial feature parameters.

[0090] After calculating the style feature parameters and the facial feature parameters, the basic facial style features and the basic sample facial features can be fused to obtain the first fused sample facial features at each size. There can be many ways of fusion. For example, based on the style feature parameters and the facial feature parameters, the basic facial style features and the basic sample facial features at the same size are fused to obtain the initial fused sample facial features at each size. According to the initial fused sample facial features, the facial area mask corresponding to the facial image sample at each size is determined. The facial area mask is used to indicate the attention weights between the initial fused facial features. The facial area mask is fused with the initial fused sample facial features to obtain the first fused sample facial features at each size.

[0091] There are many ways to fuse the basic facial style features and the basic sample facial features based on the style feature parameters and the facial feature parameters. For example, the variance ratio of the style feature variance and the facial feature variance is calculated, and the feature difference between the feature value of the basic facial feature and the mean of the facial feature is calculated. The variance ratio, the feature difference and the mean of the style feature are fused to obtain the initial fused sample facial features at each size. Specifically, it can be shown in formula (1):

[0092]

[0093] Among them, AaaIN(x, y) is the sample facial feature after initial fusion, σ(y) is the variance of style feature, σ(x) is the variance of facial feature, μ(x) is the mean of facial feature, μ(y) is the mean of style feature, x is the basic sample facial feature, and y is the basic facial style feature. This feature integration method can be adaptive instance normalization (Adaptive InstanceNormalization, AdaIN). This feature fusion method is mainly aimed at the fusion of basic facial style features and basic sample facial features of the same size, so that the first fused sample facial feature is different from the first fusion or sample facial feature fused at other sizes. The first fused sample facial feature can be the same size as the corresponding basic facial style feature or basic sample facial feature, or it can be different.

[0094] After fusing the basic facial style features and the basic sample facial features at the same size, the facial area mask corresponding to the facial image sample at each size can be determined based on the initial fused sample facial features. There are many ways to determine the facial area mask, for example, extracting associated features from the initial fused sample facial features, and determining the associated weights corresponding to the initial fused sample facial features based on the associated features. The associated weights are used to indicate the association relationship between the initial fused sample facial features, and based on the associated weights, generate facial area masks corresponding to the facial image samples at each size.

[0095] There are multiple ways to generate a facial region mask corresponding to a facial image sample of each size based on the associated weights. For example, the pixel value of each pixel of the facial image sample can be weighted based on the associated weights, thereby segmenting a target facial region from the weighted pixel values ​​and converting the target facial region into a facial region mask. Alternatively, the feature values ​​of each feature channel of the sample facial features of the facial image sample can be weighted based on the associated weights, and the target facial region can be identified in the facial image sample based on the weighted sample facial features, and the target facial region can be converted into a facial region mask.

[0096] After determining the facial region mask corresponding to the facial image sample at each size, the facial region mask can be fused with the initial fused sample facial features. There are many ways to perform the fusion. For example, the initial fused sample facial features can be directly multiplied with the facial region mask to obtain the first fused sample facial features at each size. Alternatively, the feature value corresponding to each pixel in the facial region mask can be multiplied with the feature of the corresponding pixel position in the initial fused sample facial features to obtain the first fused sample facial features at each size.

[0097] Among them, it should be noted that the method of extracting associated features, determining associated weights, generating facial area masks, and fusing the facial area masks with the sample facial features after initial fusion can be an attention mask mechanism. The main purpose is to pay more attention to the features of the facial area of ​​the sample facial features during the fusion process of facial style features and sample facial features, thereby improving the accuracy of facial replacement.

[0098] After obtaining the first fused sample facial features, the facial template image can be replaced to obtain a replaced facial image. There are many ways to replace the facial template image, for example, based on the first fused sample facial features, a basic facial image of a size corresponding to each first fused facial feature is generated, the basic facial images are sorted according to the size of the basic facial images to obtain sorting information, and the size of the basic facial images is adjusted to obtain a replaced facial image.

[0099] Among them, there can be multiple ways to generate a basic facial image of the size corresponding to each first fused facial feature based on the first fused sample facial features. For example, an image operator (ToRGB) can be used to directly convert the first fused sample facial features into a basic facial image of the size corresponding to the first fused facial features. Alternatively, an image operator (ToRGB) can be used to convert the first fused sample facial features into pixel features in the RGB color space, and based on the pixel features, a basic facial image of the size corresponding to the first fused sample facial features is generated.

[0100] Among them, according to the sorting information, the size of the basic facial image is adjusted to obtain the replaced facial image. There are many ways to adjust. For example, the basic facial image with the smallest size can be screened out from the basic facial images to obtain the current basic facial image, the size of the current basic facial image is enlarged to obtain the enlarged basic facial image, according to the sorting information, the basic facial image next to the current basic facial image is screened out from the basic facial images to obtain the target basic facial image, and the enlarged basic facial image and the target basic facial image are fused to obtain the replaced facial image.

[0101] There are many ways to enlarge the size of the current basic facial image. For example, the current basic facial image can be upsampled to enlarge the size of the current basic facial image to obtain an enlarged basic facial image, or the size of the current basic facial image can be compared with a preset target size, and an enlargement parameter is determined based on the comparison result. The current basic facial image is enlarged to a preset target size based on the enlargement parameter to obtain an enlarged basic facial image.

[0102] Among them, the enlarged basic facial image and the target basic facial image are fused, and there are many ways of fusion. For example, the enlarged basic facial image and the target basic facial image can be fused to obtain a fused basic facial image, and the size of the fused basic facial image is enlarged to obtain the target enlarged basic facial image, and the target basic facial image is used as the current basic facial image, and the target enlarged basic facial image is used as the enlarged basic facial image as the enlarged basic facial image, and the step of filtering out the next basic facial image of the current basic facial image in the basic facial images according to the sorting information is returned until the last basic facial image is filtered out, and the filtered target basic facial image is fused with the enlarged basic facial image to obtain a replaced facial image.

[0103] There are many ways to fuse the enlarged basic facial image and the target basic facial image, for example, directly superimposing the enlarged basic facial image on the target basic facial image to obtain a fused basic facial image, or fusing each pixel value of the enlarged basic facial image in the RGB color space with the pixel value of the corresponding position pixel of the target basic facial image to obtain a fused basic facial image. Through the cascade amplification structure, during the upsampling process, the basic facial image is enlarged and added to the basic facial image of the next size until the replaced facial image of the target size is finally obtained. Specifically, it can be as follows Figure 3 shown.

[0104] Among them, taking the facial image as a facial image, the sample facial image as a target facial image, and the facial template image as a facial template image as an example, the process of performing facial replacement on the facial template image can be to use a facial encoder to extract identity features from the target facial image to obtain facial features, use feature fusion to extract style features from the facial template image to obtain style features, fuse the style features with the facial features through the AdaIN network in the feature fuser to obtain initial fused facial features, use an attention mask mechanism to fuse the initial fused facial features with the facial area mask to obtain fused facial features, then generate a basic facial image for the fused facial features, upsample the basic facial image, and use cascade amplification to amplify the basic facial image during the upsampling process to obtain a replaced facial image of the target size, which can be specifically as follows Figure 4 shown.

[0105] 104. Reconstruct the facial image sample based on the sample facial features to obtain a reconstructed facial image.

[0106] For example, a preset image processing model can be used to extract features of facial image samples to obtain sample facial style features, and the sample facial style and sample facial features can be fused at multiple sizes to obtain a second fused sample at each size. Based on the second fused sample facial features, facial replacement can be performed on the facial image samples to obtain a reconstructed facial image sample.

[0107] Among them, the method of multi-scale fusion of the sample facial style features and the sample facial features is the same as the multi-scale fusion method of the facial style features and the sample facial features, which is described above and will not be repeated here. In addition, based on the second fused sample facial features, the method of face replacement for the facial image sample is the same as the method of face replacement for the facial template image sample based on the first fused sample facial features, which is described above and will not be repeated here.

[0108] 105. According to the facial image samples, the replaced facial images and the reconstructed facial images, a preset image processing model is converged to obtain a trained image processing model, and the trained image processing model is used to perform facial replacement on the facial image to be processed.

[0109] The preset image processing model is converged according to the facial image samples, the replaced facial image and the reconstructed facial image. There are many ways to converge, which can be as follows:

[0110] For example, based on facial image samples, replaced facial images and reconstructed facial portraits, the perceptual loss information of facial image sample pairs is determined, based on the replaced facial images and facial image samples, the adversarial loss information of facial image sample pairs is determined, the perceptual loss information and the adversarial loss information are fused, and based on the fused loss information, the preset image processing model is converged to obtain the trained image processing model.

[0111] The perceptual loss information can be understood as the loss information of the perceptual level of the facial region between the facial image sample and the replaced facial image, and between the facial image sample and the reconstructed facial image. There are many ways to determine the perceptual loss information of the facial image sample pair based on the facial image sample, the replaced facial image, and the reconstructed facial image. For example, based on the facial image sample and the reconstructed facial image, the reconstruction perceptual loss information of the facial image sample pair is determined; based on the facial image sample and the replaced facial image, the label perceptual loss information of the facial image sample pair is determined; the reconstruction perceptual loss information and the label perceptual loss information are fused to obtain the perceptual loss information of the facial image sample pair.

[0112] Among them, there are many ways to determine the label-perceived loss information of the facial image sample pair based on the facial image sample and the replaced facial image. For example, the facial label information in the facial image sample can be obtained, and based on the facial label information, the facial label area can be identified in the facial image sample, and the target facial area corresponding to the facial label area can be identified in the replaced facial image, and features of the facial label area can be extracted to obtain facial label area features, and features of the target facial area can be extracted to obtain target facial area features, and the feature difference between the target facial area features and the facial label area features can be calculated to obtain the label-perceived loss information of the facial image sample pair.

[0113] Among them, feature extraction of features of the facial label area and the target facial area, and calculation of feature differences between the extracted target facial area features and the facial label area features can be completed by a VGG (an image recognition network) network pre-trained on facial recognition tasks.

[0114] Among them, the reconstruction perceptual loss information is used to indicate the loss information of the perceptual level of the facial area between the facial image sample and the reconstructed facial image. The VGG network can also be used to extract features of the facial area of ​​the facial image sample and the reconstructed facial image respectively, and calculate the feature difference of the extracted features to obtain the reconstruction perceptual loss information.

[0115] After the reconstruction loss information and the label perception loss information are determined, the reconstruction perception loss information and the label perception loss information can be fused. There are many ways to fuse them. For example, the reconstruction perception loss information and the label perception loss information can be directly added to obtain the perception loss information of the facial image sample pair. Specifically, it can be shown in formula (2):

[0116] L perceptial =||VGG(G(X src , X id ))-VGG(X dst )||+||VGG(G(X id , X id ))-VGG(X id )|| (2)

[0117] Among them, L perceptial is the perceptual loss information, VGG is the VGG network pre-trained on the face recognition task, X src is a facial template image sample, X id is a facial image sample, G is the generator, G(X src , X id ) is the face image after replacement, X dst is the label in the facial image sample, G(X id , X id ) is the reconstructed facial image.

[0118] Optionally, a preset loss weight may be obtained, and based on the preset loss weight, the reconstruction perceptual loss information and the label perceptual loss information are weighted respectively, and the weighted reconstruction perceptual loss information and label perceptual loss information are fused to obtain the perceptual loss information of the facial image sample pair.

[0119] While determining the perceptual loss information, the adversarial loss information of the facial image sample pair can also be determined. There are many ways to determine the adversarial loss information of the facial image sample pair. For example, the discriminator can be trained, and the trained facial discriminator and the facial features auxiliary discriminator can be used to calculate the adversarial loss of the facial image sample and the replaced facial image sample, so as to obtain the adversarial loss information. Specifically, it can be shown in formula (3):

[0120] L adv (G,D s)=∑log D s (X dst )+∑(1-log D s (G(X src , X id ))) (3)

[0121] Among them, L adv (G,D s ) is to counteract the loss of information, D s is the face discriminator and the facial features auxiliary discriminator, G is the generator, X dst Labels in facial image samples, X src is a facial template image sample, X id is a facial image sample, G(X src , X id ) is the facial image after replacement.

[0122] After calculating the perceptual loss information and the adversarial loss information, the perceptual loss information and the adversarial loss information can be fused. There are many ways to fuse them. For example, the perceptual loss information and the adversarial loss information can be directly added to obtain the fused loss information. Alternatively, a preset weighting parameter can be obtained. Based on the preset weighting parameter, the perceptual loss information and the adversarial loss information are weighted respectively, and the weighted perceptual loss information and the weighted adversarial loss information are fused to obtain the fused loss information.

[0123] After the perceptual loss information and the adversarial loss information are fused, the preset image processing model can be converged based on the fused loss information. There are many ways to converge the preset image processing model. For example, a gradient descent algorithm can be used to update the network parameters of the preset image processing model according to the fused loss information until convergence is completed, thereby obtaining a trained image processing model.

[0124] Among them, taking the facial image as an example, the process of training the preset image processing model can be to input the target image into the face encoding network to obtain the target image feature vector, and input the template image and the feature vector into the feature fusion network. The feature fusion network is a network similar to the U-Net structure. Adaptive Instance Normalization is used in the Residual block. The cascade amplification structure and the attention mask mechanism are used in the upsampling stage to obtain the replaced face image. Then, the target image and the feature vector are input into the feature fusion network to obtain the reconstructed target image. When training the preset image processing model, the VGG network pre-trained on the face recognition task is used to calculate the perceptual loss of the result image and label, the target image and the reconstructed target image respectively; when training the discriminator, the face discriminator and the facial feature auxiliary discriminator are used to calculate the adversarial loss. Finally, the loss function is trained by gradient descent to obtain the trained image processing model, which can be specifically as follows Figure 5 shown.

[0125] After training the preset image processing model, the face replacement can be performed on the face image to be processed based on the trained image processing model. There are many ways to replace the face. For example, the face image to be processed and the face template image corresponding to the face image to be processed can be obtained, and the trained image processing model is used to extract features of the face image to be processed and the face template image respectively to obtain the facial features of the face image to be processed and the facial template features of the face template image, and the facial features and the facial template features are fused, and a fused face image is constructed with the fused facial features, and the facial template image and the fused face image are segmented to obtain the facial region, and the fused face image and the face template image are fused based on the facial region to obtain the target face image, which can be specifically as follows:

[0126] S1. Obtain a facial image to be processed and a facial template image corresponding to the facial image to be processed.

[0127] The facial image may be an image containing the facial region of the object, and the facial template image corresponding to the facial image may be a template image for performing facial replacement on the facial region in the facial image. In the facial replacement process, the facial region in the facial template image may be replaced with the facial region in the facial image.

[0128] There are many ways to obtain the facial image to be processed and the facial template image corresponding to the facial image to be processed, which can be specifically as follows:

[0129] For example, the facial image to be processed and the facial template image sent by the terminal can be directly obtained, or the facial image to be processed can be obtained, and the facial template image corresponding to the facial image to be processed can be screened out in the facial simulation image database, or the original facial image can be obtained from the network or image database, and the facial image pair can be screened out from the original facial image, and any facial image in the facial image pair can be used as the facial image to be processed, and the other facial image in the facial image pair can be used as the facial template image, or, when the number of facial images to be processed and the facial template image is large or the memory is large, a facial image processing request can be received, and the facial image processing request carries the storage address of the facial image to be processed and the facial template image, and the facial image to be processed and the facial template image corresponding to the facial image to be processed are obtained according to the storage address.

[0130] S2. Use the trained image processing model to extract features from the facial image to be processed and the facial template image respectively, to obtain facial features of the facial image to be processed and facial template features of the facial template image.

[0131] The facial features are used to indicate the feature information of the style of the facial region of the facial image to be processed, and the facial template features are used to indicate the feature information of the style of the facial region of the facial template image.

[0132] There are many ways to use the trained image processing model to extract features from the facial image to be processed and the facial template image, which can be as follows:

[0133] For example, the facial style feature extraction network of the trained image processing model can be used to extract facial style features from the facial image to be processed to obtain facial features, and the facial style feature extraction network can be used to extract facial style features from the facial template image to obtain facial template features.

[0134] There are many ways to extract facial style features. For example, a facial style (stylegan) encoder can be used to perform facial encoding on the processed facial image to obtain a 512-dimensional facial vector, and the facial vector is used as a facial feature. The stylegan encoder can also be used to perform facial encoding on the facial template image to obtain a 512-dimensional facial template vector, and the facial template vector is used as a facial template feature.

[0135] S3, fusing the facial features and the facial template features, and constructing a fused facial image based on the fused facial features.

[0136] The fused facial image may be a facial image generated by fused facial features after the facial features and the facial template features are fused.

[0137] There are many ways to fuse facial features and facial template features, which can be as follows:

[0138] For example, facial features are converted into a preset number of basic facial features, and the convolution layer corresponding to each basic facial feature is determined; facial template features are converted into a preset number of basic facial template features, and the convolution layer corresponding to each basic facial template feature is determined; according to the convolution layer, the basic facial features and the basic facial template features are fused to obtain fused facial features.

[0139] There are many ways to convert facial features into a preset number of basic facial features. For example, a mapping network (a mapping network) can be used to map a 512-dimensional facial vector into a 14*512-dimensional facial vector (256*256 resolution), thereby obtaining 14 basic facial features. After the basic facial features are converted, the 14 basic facial features can be used as noise inputs for 14 convolutional layers respectively, so that the convolutional layer corresponding to each basic facial feature can be determined.

[0140] Among them, the conversion of facial template features into basic facial template features and the determination of the convolution layer corresponding to each basic facial template feature are the same as the conversion of basic facial features and the determination of the corresponding convolution layer, which are described above and will not be repeated here.

[0141] After converting the basic facial features and the basic facial template features, the basic facial features and the basic facial template features can be fused based on the convolution layers corresponding to the basic facial features and the basic facial template features. There are many ways to fuse them. For example, the basic facial features corresponding to the preset first convolution layer are screened out from the basic facial features to obtain the target basic facial features, the basic facial template features corresponding to the second convolution layer are screened out from the basic facial template features to obtain the target basic facial template features, and the convolution layers are used to fuse the target basic facial features and the target basic facial template features to obtain the fused facial features.

[0142] Among them, the features of each convolution layer are at least different from the features of the facial area, and the noise input of different convolution layers of StyleGAN will have different effects on the results. The bottom layer noise vector mainly affects the face shape, orientation, position and other features of the generated face; the middle layer noise vector mainly affects the contour and shape of the facial features of the generated face; the high layer noise vector mainly affects the color, material and lighting of the generated face. For example, taking the number of convolution layers as 14 as an example, layers 1-3 can indicate the face position and orientation, layers 4-12 can indicate the contour shape of the facial features, and layers 13-14 can indicate color, texture and lighting. In the face fusion process, the face position and orientation of the fused face image can be similar to the face template image, the contour shape of the facial features of the fused face image is similar to the face image to be processed, and the color, texture and lighting of the fused face image are similar to the face template image. Therefore, the preset first convolution layer can be the 4th to 12th layer, and the preset second convolution layer can be the 1st to 3rd layer and the 13th to 14th layer. When the number of convolutional layers is not 14, the preset first convolutional layer and the preset second convolutional layer are determined based on the different types of facial features indicated by each convolutional layer.

[0143] After screening out the target basic facial features and the target basic facial template features, the target basic facial features and the target basic facial template features can be fused. There are many ways to fuse them. For example, the target basic facial features and the target basic facial template features can be fused layer by layer. Taking 14 convolutional layers as an example, starting from the bottom layer, the features of layers 1-3 of the fused facial features are the target basic facial template features of layers 1-3, the features of layers 4-12 of the fused facial features are the target basic facial features of layers 4-12, and the features of layers 13-14 of the fused facial features are the target basic facial template features of layers 13-14, thereby obtaining the fused facial features.

[0144] After fusing the facial features and the facial template features, a fused facial image can be constructed based on the fused facial features. There are many ways to construct the fused facial image. For example, the fused facial features can be input into the stylegan generator to obtain a fused facial image.

[0145] S4. Perform facial region segmentation on the facial template image and the fused facial image to obtain the facial region.

[0146] The facial region may be a region indicating the face in the facial template image and the fused facial image.

[0147] There are many ways to segment the facial template image and the fused facial image, which can be as follows:

[0148] For example, multi-dimensional feature extraction is performed on the fused facial image to obtain multi-dimensional facial region features, and multi-dimensional feature extraction is performed on the facial template image to obtain multi-dimensional template facial region features. Based on the facial region features, the fused facial region is segmented in the fused facial image, and based on the template facial region features, the template facial region is segmented in the facial template image, and the fused facial region and the template facial region are used as facial regions.

[0149] Among them, there are many ways to segment the fused facial area in the fused facial image based on the facial area features. For example, the facial area features are globally pooled to obtain the first pooled facial area features, and based on the first pooled facial area features, the first attention weight of each facial area feature is determined, and the fused facial area is segmented in the fused facial image according to the first attention weight.

[0150] There are many ways to determine the first attention weight of each facial region feature based on the facial region features after the first pooling. For example, the facial region features after the first pooling can be processed by a fully connected layer and an activation function to obtain the first attention weight of each feature channel of each facial region feature. The first attention weight is mainly determined by an attention block, which includes a global pooling layer and a convolution layer (conv1*1), such as Figure 6 shown.

[0151] After determining the first attention weight of each facial region feature, the fused facial region can be segmented in the fused facial image according to the first attention weight. There are many ways to segment the fused facial region. For example, the facial region features can be weighted based on the first attention weight to obtain a first weighted facial region feature, and the second attention weight of the first weighted facial region feature can be determined. The fused facial region can be segmented in the fused facial image according to the first weighted facial region feature and the second attention weight.

[0152] Among them, the method of determining the second attention weight of the first weighted facial area feature is the same as the method of determining the first attention weight, and both are completed using an attention module (Attention block), as described above, which will not be repeated here. After determining the second attention weight, the fused facial area can be segmented out in the fused facial image according to the first weighted facial area feature and the second attention weight. There are many ways to segment the fused facial area. For example, the first weighted facial area feature can be weighted based on the second attention weight to obtain the second weighted facial area feature. According to the first weighted facial area feature and the second weighted facial area feature, the current facial mask can be segmented out in the fused facial image, and the area corresponding to the current mask can be identified in the fused facial image to obtain the fused facial area.

[0153] Among them, there are many ways to segment the current facial mask in the fused facial image according to the first weighted facial region feature and the second weighted facial region feature. For example, the first weighted facial region feature and the second weighted facial region feature are fused to obtain a first fused facial region feature, the first weighted facial region feature and the facial region feature are fused to obtain a second fused facial region feature, the first fused facial region feature and the second fused facial region feature are decoded respectively to obtain a first decoded facial region feature and a second decoded facial region feature, the first decoded facial region feature and the second decoded facial region feature are fused to obtain a third fused facial region feature, the third fused facial region feature is decoded to obtain a third decoded facial region feature, a mask of the facial region is segmented from the fused facial image according to the third decoded facial region feature, and the mask of the facial region is used as the current facial mask. Specifically, the following can be performed: Figure 7 shown.

[0154] After segmenting the current facial mask, the area corresponding to the current facial mask can be identified in the fused facial image. There are many ways to identify it. For example, the current facial mask is superimposed on the fused facial image to identify the area corresponding to the current facial mask, and the area corresponding to the current facial mask is used as the fused facial area. Alternatively, the position information of the current facial mask is obtained, and based on the position information, the area corresponding to the position information is identified in the fused facial image to obtain the fused facial area.

[0155] The process of segmenting the template face region in the face template image according to the template face region feature is the same as the process of segmenting the fused face region in the fused face image, as described above, and will not be repeated here. The fused face region and the template face region are taken as the face region.

[0156] S5. Based on the facial region, the fused facial image and the facial template image are subjected to facial fusion to obtain a target facial image.

[0157] For example, the fused facial image can be color corrected based on the fused facial area and the template facial area to obtain a corrected fused facial image, facial key points can be detected in the facial template image to obtain first facial key points, and facial key points can be detected in the corrected fused facial image to obtain second facial key points, and the fused facial image and the facial template image can be facially fused based on the first facial key points and the second facial key points to obtain a target facial image.

[0158] Among them, there are many ways to perform color correction on the fused facial image based on the fused facial area and the template facial area. For example, the fused facial area and the template facial area can be converted into color space to obtain a target fused facial area and a target template facial area in a target color space, and the color parameters of the target fused facial area are calculated to obtain a first color parameter, and the color parameters of the target template facial area are calculated to obtain a second color parameter. According to the first color parameter and the second color parameter, each color channel of the target fused facial area is corrected to obtain a corrected fused facial image.

[0159] There are many ways to convert the color space of the fused facial area and the template facial area. For example, the three-channel fused facial area and the three-channel template facial area can be converted from the RGB color space to the LAB color space, and the LAB color space is used as the target color space to obtain the target fused facial area and the target template facial area in the LAB color space.

[0160] After converting the fused facial area and the template facial area from the RGB color space to the LAB color space, the first color parameter corresponding to the converted target fused facial area and the second color parameter corresponding to the target template facial area can be calculated. The first color parameter includes a first pixel mean and a first pixel variance, and the second color parameter includes a second pixel mean and a second pixel variance. There are many ways to calculate the first color parameter, for example, obtaining the current pixel value of each color channel of the target fused facial area in the LAB color space, and then calculating the current pixel value and the mean and variance to obtain the first pixel mean and the first pixel variance in each color channel, and taking the first pixel mean and the first pixel variance as the first color parameter. The method for calculating the second color parameter is the same as the method for calculating the first color parameter, and will not be repeated here.

[0161] After calculating the first color parameter and the second color parameter, each color channel of the target fused facial area can be corrected according to the first color parameter and the second color parameter to obtain a corrected fused facial image. There are many ways to correct, for example, calculating the variance ratio of the first pixel variance and the second pixel variance under each color channel, and calculating the pixel difference between the current pixel value and the first pixel mean under each color channel, and fusing the pixel difference, the variance ratio and the second pixel mean to obtain the target pixel mean of each color channel. Taking the color channel including L / A / B as an example, the calculation process of the target pixel mean of each color channel can be shown as formula (4):

[0162]

[0163] Among them, l′ 1 , a′ 1 and b′ 1 are the target pixel values ​​under L / A / B color channels respectively, l 1 、a 1 and b 1 are the current pixel values ​​under L / A / B color channels respectively, and are the first pixel means under L / A / B color channels respectively, and are the second pixel means under L / A / B color channels respectively, and are the first pixel variances under L / A / B color channels, and are the second pixel variances under L / A / B color channels respectively.

[0164] After the target pixel value of each color channel is calculated, the current pixel value of each color channel of the target fused facial region can be replaced with the corresponding target pixel value, thereby obtaining a corrected fused facial image.

[0165] After obtaining the corrected fused facial image, facial key points can be detected in the facial template image to obtain the first facial key points. There are many ways to detect facial key points. For example, the key point detection network of the trained image processing model can be used to extract features from the facial template image to obtain lightweight facial key point features in multiple dimensions. The lightweight facial key point features are fused to obtain facial key point features. Based on the facial key point features, facial key points are identified in the facial template image to obtain the first facial key points.

[0166] Among them, the method of detecting facial key points in the corrected fused facial image is the same as the process of detecting key points in the facial template image, as described above, and will not be repeated here.

[0167] After detecting the first facial key point and the second facial key point, the fused facial image and the facial template image can be fused. There are many ways to perform facial fusion, for example, comparing the first facial key point and the second facial key point to obtain key point deformation information, deforming the first facial key point based on the key point deformation information to obtain a deformed facial template image, and fusing the fused facial image and the deformed facial template image to obtain a target facial image.

[0168] Among them, there are many ways to deform the first facial key point based on the key point deformation information. For example, based on the key point deformation information, the lightweight facial key point features are adjusted, and according to the adjusted key point facial features, the interpolation information for deforming the first facial key point to the second facial key point is determined. Based on the interpolation information, the abnormal key points that are different from the first facial key point and the second facial key point are deformed to obtain the deformed facial template image.

[0169] Among them, based on the difference information, there can be multiple ways to deform the abnormal key points that are different from the first facial key points and the second facial key points. For example, the thin plate spline difference method can be used to deform the abnormal key points based on the difference information to obtain the deformed facial template image.

[0170] The processing of the facial template image can be regarded as a process of continuing to deform the first facial key point after the first facial key point is detected. Figure 8 As shown, the facial template image is subjected to key point feature extraction using Mobilenet-V2Block (a lightweight convolutional neural network), and the Mobilenet-V2 Block can be deployed on a mobile terminal, and then the lightweight facial key point features are extracted, and then the lightweight facial key point features are fused using a convolutional layer to obtain facial key point features, and the facial key point features are normalized using a fully connected layer (FC layer), and based on the normalized facial key point features, the facial key points in the facial template image are determined, thereby obtaining the first facial key point. After the first facial key point is detected, the first facial key point needs to be deformed, and the deformation process is mainly completed by thin plate spline interpolation, thereby obtaining the deformed facial template image.

[0171] After deforming the first facial key point, the fused facial image and the deformed facial template image can be fused. There are many ways to fuse them, for example, the fused facial image and the deformed facial template image are mixed gradient fused (Poisson fusion) to obtain the target facial image.

[0172] Among them, it should be noted that the project of facial fusion of the facial image to be processed and the facial template image can be mainly regarded as two parts. One is to extract features of the facial image to be processed and the facial template image respectively, and fuse the extracted features layer by layer, and reconstruct the fused facial features into a fused facial image based on the stylegan generator. The other is to perform facial fusion on the fused facial image and the facial template image. The main fusion process can be understood as segmenting the facial areas of the fused facial image and the facial template image respectively, and identifying the facial key points of the fused facial image and the facial template image, deforming the facial template image based on the identified facial key points, and finally performing mixed gradient fusion on the deformed facial template image and the fused facial image to obtain the target facial image, such as Fig. 9 shown.

[0173] Where it is necessary to explain, taking the facial image as an example, this solution synthesizes a large number of paired template face-target face-reconstructed face triplet data for training based on StyleGan latent space vector fusion technology. In terms of network structure, a set of end-to-end networks for paired data is designed based on pixel2pixel. The generator consists of a face encoding network and a feature fusion network, and uses adaptive instance normalization for feature fusion, and a cascade amplification structure to increase the generated details. Before training, the facial key point tool is used to mark the positions of the facial features in the image. During training, the facial features auxiliary discriminator is used to train the eyes, nose, and mouth areas respectively to enhance the details of each part. In addition, adaptive data amplification will be used during training to effectively enhance the discriminant ability of the discriminator. Due to the use of paired data, there is strong supervision information, and the training process is stable and bad cases are not easy to occur. In addition, by compressing the number of parameters and calculations of the generator, a lightweight network can be obtained for deployment on mobile devices. In addition, when the face of the object in the facial image to be processed is obstructed by glasses or other objects, a better stylegan model can be used for synthesis, and after more rigorous manual selection, a better ternary data set can be obtained, and by training with this, a better image processing model can be obtained.

[0174] Optionally, in one embodiment, the image processing method further includes storing the replaced facial image, the reconstructed facial image, the fused facial image, the target facial image, etc. in a blockchain.

[0175] From the above, it can be seen that after acquiring at least one facial image sample pair, the embodiment of the present application uses a preset image processing model to extract features from the facial image samples to obtain sample facial features, and based on the sample facial features, performs facial replacement on the facial template image samples to obtain a replaced facial image, and then, reconstructs the facial image samples based on the sample facial features to obtain a reconstructed facial image, and then, based on the facial image samples, the replaced facial image and the reconstructed facial image, converges the preset image processing model to obtain a trained image processing model, and uses the trained image processing model to perform facial replacement on the facial image to be processed; because the scheme can reconstruct facial image samples after extracting features from facial image samples, thereby forming a triple data set of facial image samples, facial template image samples and reconstructed facial images, and converges the preset image processing model based on the triple data, thereby greatly improving the stability and processing accuracy of image processing training, and therefore, the accuracy of image processing can be improved.

[0176] According to the method described in the above embodiment, the following is further described in detail with examples.

[0177] In this embodiment, the image processing device is specifically integrated in an electronic device, the electronic device is a server, and the face is a human face.

[0178] like Fig.10 As shown, an image processing method, the specific process is as follows:

[0179] 201. The server obtains at least one face image sample pair.

[0180] For example, the server can receive a face image sample pair sent by the terminal, and the face image sample pair includes a face image sample and a face template image sample. Alternatively, the face image sample can be obtained from a network or an image database, and the face image sample is sent to a template image server, and a face template image sample corresponding to each face image sample returned by the simulation image server is received, and the face image sample and the face template image sample are combined into a face image sample pair. Alternatively, the original face image can be obtained from a network or an image database, and the face image sample and the face template image sample corresponding to the face image sample can be screened out from the original face image sample to obtain a face image sample pair. The screening condition can be that the object face in the face image sample and the face template image are different. Alternatively, when the number of face image sample pairs is large or the memory is large, a face image processing request can also be received, and the face image sample processing request carries the storage address of the face image sample pair, and the face image sample pair is obtained according to the storage address.

[0181] 202. The server uses a preset image processing model to extract features from the face image sample to obtain sample face features.

[0182] For example, the server can use a feature extraction network of a preset image processing model to perform convolution feature extraction on face image samples to obtain initial sample face features, and then use a fully connected layer to process the initial sample face features to obtain a 256-dimensional feature vector, which is used as the sample face feature.

[0183] 203. The server performs face replacement on the face template image sample according to the sample face features to obtain a replaced face image.

[0184] For example, the server can use a preset image processing model to extract features from the face template image to obtain face style features, extract basic face style features at each size from the face style features, and extract basic sample face features at each size from the sample face features, calculate style feature parameters of the basic face style features and face feature parameters of the basic sample face features, and based on the style feature parameters and face feature parameters, fuse the basic face style features and the basic sample face features to obtain the first fused sample face features at each size.

[0185] For style feature parameters, the server can obtain the face style feature value under each feature channel in the basic face style feature, calculate the variance of the face style feature value, obtain the style feature variance, and calculate the mean of the face style feature value to obtain the style feature mean, and use the style feature variance and the style feature mean as style feature parameters. For facial feature parameters, the face feature value under each feature channel in the basic sample face feature can be obtained, and then the variance of the face feature value is calculated to obtain the face feature variance, and the mean of the face feature value is calculated to obtain the face feature mean, and the face feature variance and the face feature mean are used as facial feature parameters.

[0186] The server calculates the variance ratio of the style feature variance and the face feature variance, and calculates the feature difference between the feature value of the basic face feature and the mean of the face feature, and fuses the variance ratio, feature difference and style feature mean to obtain the initial fused sample face feature at each size, which can be specifically shown in formula (1).

[0187] The server extracts the associated features from the initial fused sample face features, and determines the associated weights corresponding to the initial fused sample face features according to the associated features, the associated weights being used to indicate the association relationship between the initial fused sample face features, and weights the pixel value of each pixel of the face image sample based on the associated weights, thereby segmenting the target face region from the weighted pixel values, and converting the target face region into a face region mask, or, based on the associated weights, weights the feature values ​​under each feature channel of the sample face features of the face image sample, and identifies the target face region in the face image sample based on the weighted sample face features, and converts the target face region into a face region mask. The initial fused sample face features are multiplied by the face region mask, thereby obtaining the first fused sample face features at each size, or, the feature values ​​corresponding to each pixel in the face region mask are multiplied by the features at the corresponding pixel position in the initial fused sample face features, thereby obtaining the first fused sample face features at each size.

[0188] The server may use an image operator (ToRGB) to directly convert the first fused sample facial features into a basic facial image of a size corresponding to the first fused facial features, or may use an image operator (ToRGB) to convert the first fused sample facial features into pixel features in an RGB color space, and generate a basic facial image of a size corresponding to the first fused sample facial features based on the pixel features. According to the size of the basic facial images, the basic facial images are sorted, the basic facial images with the smallest size are selected from the basic facial images to obtain the current basic facial image, and the current basic facial image is upsampled to enlarge the size of the current basic facial image to obtain the enlarged basic facial image, or the size of the current basic facial image is compared with a preset target size, and an enlargement parameter is determined based on the comparison result, and the current basic facial image is enlarged to the preset target size based on the enlargement parameter to obtain the enlarged basic facial image.

[0189] The server selects the next basic face image of the current basic face image from the basic face images according to the sorting information to obtain the target basic face image, fuses the enlarged basic face image and the target basic face image to obtain the fused basic face image, enlarges the size of the fused basic face image to obtain the target enlarged basic face image, uses the target basic face image as the current basic face image, and uses the target enlarged basic face image as the enlarged basic face image, and returns to execute the step of selecting the next basic face image of the current basic face image from the basic face images according to the sorting information until the last basic face image is selected, and directly superimposes the enlarged basic face image on the target basic face image to obtain the fused basic face image, or fuses each pixel value of the enlarged basic face image in the RGB color space with the pixel value of the pixel at the corresponding position of the target basic face image to obtain the fused basic face image. Through the cascade amplification structure, during the upsampling process, the basic face image is amplified and added to the basic face image of the next size until a replaced face image of the target size is finally obtained.

[0190] 204. The server reconstructs the facial image sample based on the sample facial features to obtain a reconstructed facial image.

[0191] For example, the server can use a preset image processing model to extract features from facial image samples to obtain sample facial style features, fuse the sample facial style with the sample facial features at multiple sizes to obtain a second fused sample at each size, and perform face replacement on the facial image samples based on the second fused sample facial features to obtain a reconstructed facial image sample.

[0192] 205. The server converges a preset image processing model according to the face image samples, the replaced face images and the reconstructed face images to obtain a trained image processing model.

[0193] For example, the server obtains face label information from a face image sample, and identifies a face label region in the face image sample based on the face label information, identifies a target face region corresponding to the face label region in the replaced face image, uses a VGG network to extract features from the face label region to obtain features of the face label region, and uses a VGG network to extract features from the target face region to obtain features of the target face region, calculates the feature difference between the target face region features and the face label region features, and obtains label-perceived loss information of the face image sample pair. Use a VGG network to extract features from the face regions of the face image sample and the reconstructed face image, respectively, and calculates the feature difference of the extracted features, thereby obtaining reconstruction-perceived loss information. Add the reconstruction-perceived loss information to the label-perceived loss information, thereby obtaining the perceptual loss information of the face image sample pair, which can be specifically shown in formula (2).

[0194] The server can train the discriminator, and use the trained face discriminator and the facial features auxiliary discriminator to calculate the adversarial loss of the face image sample and the replaced face image sample, thereby obtaining adversarial loss information, which can be specifically shown in formula (3). The perceptual loss information and the adversarial loss information are added to obtain the fused loss information, or a preset weighting parameter can be obtained, and the perceptual loss information and the adversarial loss information are weighted based on the preset weighting parameter, and the weighted perceptual loss information and the weighted adversarial loss information are fused to obtain the fused loss information. The gradient descent algorithm is used to update the network parameters of the preset image processing model according to the fused loss information until convergence is completed, thereby obtaining the trained image processing model.

[0195] 206. The server obtains the face image to be processed and the face template image corresponding to the face image to be processed.

[0196] For example, the server can directly obtain the face image to be processed and the face template image sent by the terminal, or, it can also obtain the face image to be processed, filter out the face template image corresponding to the face image to be processed in the face simulation image database, or, obtain the original face image from the network or image database, filter out face image pairs from the original face image, and use any face image in the face image pair as the face image to be processed, and the other face image in the face image pair as the face template image, or, when the number of face images to be processed and face template images is large or the memory is large, it can also receive a face image processing request, which carries the storage address of the face image to be processed and the face template image, and obtains the face image to be processed and the face template image corresponding to the face image to be processed according to the storage address.

[0197] 207. The server uses the trained image processing model to extract features of the face image to be processed and the face template image respectively, to obtain face features of the face image to be processed and face template features of the face template image.

[0198] For example, the server can use the StyleGAN encoder to perform face encoding on the face image to be processed to obtain a 512-dimensional face vector, use the face vector as the face feature, and use the StyleGAN encoder to perform face encoding on the face template image to obtain a 512-dimensional face template vector, and use the face template vector as the face template feature.

[0199] 208. The server fuses the facial features and the facial template features, and constructs a fused facial image based on the fused facial features.

[0200] For example, the server uses a mapping network to map 512-dimensional face vectors and face template vectors to 14*512-dimensional basic face vectors and basic face template vectors (256*256 resolution), thereby obtaining 14 basic face features and basic face template features. After converting the basic face features and basic face template features, the 14 basic face features and 14 basic face template features can be used as noise inputs for 14 convolutional layers, respectively. Therefore, the convolutional layers corresponding to each basic face feature and basic face template feature can be determined.

[0201] The server selects the basic facial features corresponding to the preset 4th to 12th convolution layers from the basic facial features to obtain the target basic facial features, and selects the basic facial template features corresponding to the 1st to 3rd and 13th to 14th convolution layers from the basic facial template features to obtain the target basic facial template features. Starting from the bottom layer, the features of the 1st to 3rd layers of the fused facial features are the target basic facial template features of the 1st to 3rd layers, the features of the 4th to 12th layers of the fused facial features are the target basic facial features of the 4th to 12th layers, and the features of the 13th to 14th layers of the fused facial features are the target basic facial template features of the 13th to 14th layers, thereby obtaining the fused facial features. The fused facial features are input into the stylegan generator to obtain a fused facial image.

[0202] 209. The server performs face region segmentation on the face template image and the fused face image to obtain the face region.

[0203] For example, the server performs multi-dimensional feature extraction on the fused face image to obtain multi-dimensional face region features, and performs multi-dimensional feature extraction on the face template image to obtain multi-dimensional template face region features. The face region features are globally pooled to obtain the first pooled face region features, and the attention module is used to process the first pooled face region features with a fully connected layer and an activation function, thereby obtaining the first attention weight of each feature channel of each face region feature. Based on the first attention weight, the face region feature is weighted to obtain a first weighted face region feature, and a second attention weight of the first weighted face region feature is determined. Based on the second attention weight, the first weighted face region feature can be weighted to obtain a second weighted face region feature, the first weighted face region feature and the second weighted face region feature are fused to obtain a first fused face region feature, the first weighted face region feature and the face region feature are fused to obtain a second fused face region feature, the first fused face region feature and the second fused face region feature are decoded respectively to obtain a first decoded face region feature and a second decoded face region feature, the first decoded face region feature and the second decoded face region feature are fused to obtain a third fused face region feature, the third fused face region feature is decoded to obtain a third decoded face region feature, a mask of the face region is segmented from the fused face image according to the third decoded face region feature, and the mask of the face region is used as the current face mask.

[0204] The server superimposes the current face mask with the fused face image, so that the area corresponding to the current face mask can be identified, and the area corresponding to the current face mask is used as the fused face area, or the position information of the current face mask is obtained, and based on the position information, the area corresponding to the position information is identified in the fused face image, thereby obtaining the fused face area.

[0205] The process of segmenting the template face region in the face template image according to the template face region feature is the same as the process of segmenting the fused face region in the fused face image, as described above, and will not be repeated here. The fused face region and the template face region are taken as the face region.

[0206] 210. The server performs face fusion on the fused face image and the face template image based on the face area to obtain a target face image.

[0207] For example, the server converts the three-channel fused face area and the three-channel template face area from the RGB color space to the LAB color space, and uses the LAB color space as the target color space, thereby obtaining the target fused face area and the target template face area in the LAB color space. The current pixel value of each color channel of the target fused face area in the LAB color space is obtained, and then the current pixel value, mean and variance are calculated to obtain the first pixel mean and first pixel variance in each color channel, and the first pixel mean and first pixel variance are used as the first color parameter. The method for calculating the second color parameter is the same as the method for calculating the first color parameter, and will not be repeated here.

[0208] The server calculates the variance ratio of the first pixel variance and the second pixel variance under each color channel, and calculates the pixel difference between the current pixel value and the first pixel mean under each color channel, and fuses the pixel difference, the variance ratio and the second pixel mean to obtain the target pixel mean of each color channel. The calculation process of the target pixel mean of each color channel can be shown in formula (4). After calculating the target pixel value of each color channel, the current pixel value of each color channel of the target fused face area can be replaced with the corresponding target pixel value, thereby obtaining a corrected fused face image.

[0209] The server can use the key point detection network of the trained image processing model to extract features from the face template image, obtain lightweight face key point features of multiple dimensions, fuse the lightweight face key point features to obtain face key point features, and identify face key points in the face template image based on the face key point features to obtain the first face key point. In addition, the method of detecting face key points in the corrected fused face image is the same as the process of detecting key points in the face template image, as described above, and will not be repeated here.

[0210] The server compares the first face key point with the second face key point to obtain the key point deformation information, adjusts the lightweight face key point features based on the key point deformation information, determines the interpolation information for deforming the first face key point to the second face key point based on the adjusted key point face features, and deforms the abnormal key points based on the difference information using a thin plate spline interpolation method to obtain a deformed face template image. The fused face image and the deformed face template image are mixed gradient fused (Poisson fusion) to obtain a target face image.

[0211] From the above, it can be seen that after obtaining at least one face image sample pair, the server of this embodiment uses a preset image processing model to extract features from the face image samples to obtain sample face features, and based on the sample face features, performs face replacement on the face template image samples to obtain a replaced face image, and then reconstructs the face image samples based on the sample face features to obtain a reconstructed face image, and then, based on the face image samples, the replaced face image and the reconstructed face image, converges the preset image processing model to obtain a trained image processing model, and uses the trained image processing model to perform face replacement on the face image to be processed; because the scheme can reconstruct the face image samples after extracting features from the face image samples, thereby forming a triple data set of face image samples, face template image samples and reconstructed face images, and converges the preset image processing model based on the triple data, thereby greatly improving the stability and processing accuracy of image processing training, and therefore, the accuracy of image processing can be improved.

[0212] In order to better implement the above method, an embodiment of the present invention further provides an image processing device, which can be integrated into an electronic device, such as a server or a terminal. The terminal may include a tablet computer, a laptop computer and / or a personal computer.

[0213] For example, Fig.11 As shown, the image processing apparatus may include an acquisition unit 301, an extraction unit 302, a first replacement unit 303, a reconstruction unit 304, and a second replacement unit 305, as follows:

[0214] (1) Acquisition unit 301;

[0215] The acquisition unit 301 is configured to acquire at least one facial image sample pair, where the facial image sample pair includes a facial image sample and a facial template image sample.

[0216] For example, the acquisition unit 301 can be specifically used to receive a facial image sample pair sent by a terminal, where the facial image sample pair includes a facial image sample and a facial template image sample. Alternatively, the facial image sample can be obtained from a network or an image database, the facial image sample can be sent to a template image server, and a facial template image sample corresponding to each facial image sample returned by the simulated image server is received, and the facial image sample and the facial template image sample are combined into a facial image sample pair. Alternatively, the original facial image can be obtained from a network or an image database, and the facial image sample and the facial template image sample corresponding to the facial image sample can be screened out from the original facial image sample to obtain a facial image sample pair. The screening condition can be that the face of the object in the facial image sample and the facial template image are different. Alternatively, when the number of facial image sample pairs is large or the memory is large, a facial image processing request can also be received, and the facial image sample processing request carries the storage address of the facial image sample pair. The facial image sample pair is obtained according to the storage address.

[0217] (2) Extraction unit 302;

[0218] The extraction unit 302 is used to extract features from facial image samples using a preset image processing model to obtain sample facial features.

[0219] For example, the extraction unit 302 can be specifically used to perform convolution feature extraction on facial image samples using a feature extraction network of a preset image processing model to obtain initial sample facial features, and then use a fully connected layer to process the initial sample facial features to obtain a 256-dimensional feature vector, which is used as the sample facial feature.

[0220] (3) a first replacement unit 303;

[0221] The first replacement unit 303 is used to perform face replacement on the facial image sample according to the sample facial features and the facial template image sample to obtain a replaced facial image.

[0222] For example, the first replacement unit 303 can be specifically used to use a preset image processing model to extract features from a facial template image to obtain facial style features, fuse the facial style features and sample facial features at multiple sizes to obtain first fused sample facial features at each size, and perform facial replacement on the facial template image sample based on the first fused sample facial features to obtain a replaced facial image.

[0223] (4) reconstruction unit 304;

[0224] The reconstruction unit 304 is used to reconstruct the facial image sample based on the sample facial features to obtain a reconstructed facial image.

[0225] For example, the reconstruction unit 304 can be specifically used to use a preset image processing model to extract features from facial image samples to obtain sample facial style features, perform multi-size fusion of the sample facial style and the sample facial features to obtain a second fused sample at each size, and perform facial replacement on the facial image sample based on the second fused sample facial features to obtain a reconstructed facial image sample.

[0226] (5) second replacement unit 305;

[0227] The second replacement unit 305 is used to converge the preset image processing model according to the facial image sample, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and use the trained image processing model to perform facial replacement on the facial image to be processed.

[0228] For example, the second replacement unit 305 can be specifically used to determine the perceptual loss information of the facial image sample pair according to the facial image sample, the replaced facial image and the reconstructed facial head portrait, determine the adversarial loss information of the facial image sample pair based on the replaced facial image and the facial image sample, fuse the perceptual loss information and the adversarial loss information, and converge the preset image processing model based on the fused loss information to obtain the trained image processing model. The trained image processing model is used to perform facial replacement on the facial image to be processed.

[0229] Optionally, the second replacement unit 305 may further include an acquisition subunit 3051, an extraction subunit 3052, a construction subunit 3053, a segmentation subunit 3054 and a fusion subunit 3055. Fig.12 As shown, the specific details can be as follows:

[0230] (1) Obtain subunit 3051;

[0231] The acquisition subunit 3051 is used to acquire the facial image to be processed and the facial template image corresponding to the facial image to be processed.

[0232] For example, the acquisition subunit 3051 can be specifically used to directly acquire the facial image to be processed and the facial template image sent by the terminal, or, the facial image to be processed can be acquired, and the facial template image corresponding to the facial image to be processed can be screened out in the facial simulation image database, or, the original facial image can be acquired from the network or image database, and the facial image pair can be screened out in the original facial image, and any facial image in the facial image pair can be used as the facial image to be processed, and the other facial image in the facial image pair can be used as the facial template image, or, when the number of facial images to be processed and the facial template image is large or the memory is large, a facial image processing request can be received, and the facial image processing request carries the storage address of the facial image to be processed and the facial template image, and the facial image to be processed and the facial template image corresponding to the facial image to be processed can be acquired according to the storage address.

[0233] (2) extract subunit 3052;

[0234] The extraction subunit 3052 is used to use the trained image processing model to perform feature extraction on the facial image to be processed and the facial template image respectively, so as to obtain facial features of the facial image to be processed and facial template features of the facial template image.

[0235] For example, the extraction subunit 3052 can be specifically used to use the facial style feature extraction network of the trained image processing model to extract facial style features from the facial image to be processed to obtain facial features, and use the facial style feature extraction network to extract facial style features from the facial template image to obtain facial template features.

[0236] (3) construct subunit 3053;

[0237] The construction subunit 3053 is used to fuse the facial features and the facial template features, and construct a fused facial image based on the fused facial features.

[0238] For example, the construction subunit 3053 can be specifically used to convert facial features into a preset number of basic facial features, and determine the convolution layer corresponding to each basic facial feature, convert facial template features into a preset number of basic facial template features, and determine the convolution layer corresponding to each basic facial template feature, and fuse the basic facial features and the basic facial template features according to the convolution layer to obtain fused facial features. The fused facial features are input into the stylegan generator to obtain a fused facial image.

[0239] (4) segmentation subunit 3054;

[0240] The segmentation subunit 3054 is used to perform facial region segmentation on the facial template image and the fused facial image to obtain the facial region.

[0241] For example, the segmentation subunit 3054 can be specifically used to perform multi-dimensional feature extraction on the fused facial image to obtain multi-dimensional facial region features, perform multi-dimensional feature extraction on the facial template image to obtain multi-dimensional template facial region features, segment the fused facial region in the fused facial image based on the facial region features, segment the template facial region in the facial template image based on the template facial region features, and use the fused facial region and the template facial region as the facial region.

[0242] (5) fusion subunit 3055;

[0243] The fusion subunit 3055 is used to perform facial fusion on the fused facial image and the facial template image based on the facial region to obtain a target facial image.

[0244] For example, the fusion subunit 3055 can be specifically used to perform color correction on the fused facial image according to the fused facial area and the template facial area to obtain a corrected fused facial image, detect facial key points in the facial template image to obtain first facial key points, and detect facial key points in the corrected fused facial image to obtain second facial key points, and perform facial fusion on the fused facial image and the facial template image according to the first facial key points and the second facial key points to obtain a target facial image.

[0245] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units can refer to the previous method embodiments, which will not be repeated here.

[0246] As can be seen from the above, in the embodiment of the present application, after the acquisition unit 301 acquires at least one facial image sample pair, the extraction unit 302 uses a preset image processing model to extract features from the facial image samples to obtain sample facial features, and the first replacement unit 303 performs facial replacement on the facial template image samples according to the sample facial features to obtain a replaced facial image, and then the reconstruction unit 304 reconstructs the facial image samples based on the sample facial features to obtain a reconstructed facial image, and then the second replacement unit 305 converges the preset image processing model according to the facial image samples, the replaced facial images and the reconstructed facial images to obtain a trained image processing model, and uses the trained image processing model to perform facial replacement on the facial image to be processed; because the scheme can reconstruct facial image samples after feature extraction of facial image samples, thereby forming a triple data set of facial image samples, facial template image samples and reconstructed facial images, and the preset image processing model is converged based on the triple data, thereby greatly improving the stability and processing accuracy of image processing training, and therefore, the accuracy of image processing can be improved.

[0247] The embodiment of the present invention further provides an electronic device, such as Fig.13 As shown, it shows a schematic diagram of the structure of an electronic device involved in an embodiment of the present invention, specifically:

[0248] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that Fig.13 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0249] The processor 401 is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, the processor 401 performs various functions of the electronic device and processes data. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.

[0250] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.

[0251] The electronic device also includes a power supply 403 for supplying power to each component. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply 403 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.

[0252] The electronic device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0253] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby realizing various functions, as follows:

[0254] At least one facial image sample pair is obtained, the facial image sample pair comprising a facial image sample and a facial template image sample, a preset image processing model is used to perform feature extraction on the facial image sample to obtain sample facial features, facial replacement is performed on the facial image sample according to the sample facial features and the facial template image sample to obtain a replaced facial image, the facial image sample is reconstructed based on the sample facial features to obtain a reconstructed facial image, a preset image processing model is converged according to the facial image sample, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and the trained image processing model is used to perform facial replacement on the facial image to be processed.

[0255] For example, an electronic device obtains a facial image sample pair, which includes a facial image sample and a facial template image sample. A feature extraction network of a preset image processing model is used to perform convolution feature extraction on the facial image sample to obtain an initial sample facial feature, and then a fully connected layer is used to process the initial sample facial feature to obtain a 256-dimensional feature vector, which is used as a sample facial feature. A preset image processing model is used to perform feature extraction on the facial template image to obtain a facial style feature, and the facial style feature and the sample facial feature are multi-scale fused to obtain a first fused sample facial feature at each size, and based on the first fused sample facial feature, the facial template image sample is face-replaced to obtain a replaced facial image. A preset image processing model is used to perform feature extraction on the facial image sample to obtain a sample facial style feature, and the sample facial style and the sample facial feature are multi-scale fused to obtain a second fused sample at each size, and based on the second fused sample facial feature, the facial image sample is face-replaced to obtain a reconstructed facial image sample. According to the facial image samples, the replaced facial images and the reconstructed facial portraits, the perceptual loss information of the facial image sample pairs is determined. Based on the replaced facial images and the facial image samples, the adversarial loss information of the facial image sample pairs is determined. The perceptual loss information and the adversarial loss information are fused. Based on the fused loss information, the preset image processing model is converged to obtain the trained image processing model.

[0256] The electronic device obtains a facial image to be processed and a facial template image corresponding to the facial image to be processed. The facial style feature extraction network of the trained image processing model is used to extract facial style features from the facial image to be processed to obtain facial features, and the facial style feature extraction network is used to extract facial style features from the facial template image to obtain facial template features. The facial features are converted into a preset number of basic facial features, and the convolution layer corresponding to each basic facial feature is determined. The facial template features are converted into a preset number of basic facial template features, and the convolution layer corresponding to each basic facial template feature is determined. According to the convolution layer, the basic facial features and the basic facial template features are fused to obtain fused facial features. The fused facial features are input into the stylegan generator to obtain a fused facial image. Multi-dimensional feature extraction is performed on the fused facial image to obtain facial region features of multiple dimensions, multi-dimensional feature extraction is performed on the facial template image to obtain template facial region features of multiple dimensions, a fused facial region is segmented in the fused facial image according to the facial region features, a template facial region is segmented in the facial template image according to the template facial region features, and the fused facial region and the template facial region are used as facial regions. According to the fused facial area and the template facial area, the fused facial image is color corrected to obtain a corrected fused facial image, facial key points are detected in the facial template image to obtain first facial key points, and facial key points are detected in the corrected fused facial image to obtain second facial key points, and according to the first facial key points and the second facial key points, the fused facial image and the facial template image are facially fused to obtain a target facial image.

[0257] The specific implementation of the above operations can be found in the previous embodiments and will not be described in detail here.

[0258] From the above, it can be seen that after acquiring at least one facial image sample pair, the embodiment of the present invention uses a preset image processing model to extract features from the facial image samples to obtain sample facial features, and performs facial replacement on the facial template image samples based on the sample facial features to obtain a replaced facial image, and then reconstructs the facial image samples based on the sample facial features to obtain a reconstructed facial image, and then, based on the facial image samples, the replaced facial image and the reconstructed facial image, converges the preset image processing model to obtain a trained image processing model, and uses the trained image processing model to perform facial replacement on the facial image to be processed; because the scheme can reconstruct the facial image samples after extracting features from the facial image samples, thereby forming a triple data set of facial image samples, facial template image samples and reconstructed facial images, and converges the preset image processing model based on the triple data, thereby greatly improving the stability and processing accuracy of image processing training, and therefore, the accuracy of image processing can be improved.

[0259] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0260] To this end, an embodiment of the present invention provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any one of the image processing methods provided in the embodiments of the present invention. For example, the instructions can execute the following steps:

[0261] At least one facial image sample pair is obtained, the facial image sample pair comprising a facial image sample and a facial template image sample, a preset image processing model is used to perform feature extraction on the facial image sample to obtain sample facial features, facial replacement is performed on the facial image sample according to the sample facial features and the facial template image sample to obtain a replaced facial image, the facial image sample is reconstructed based on the sample facial features to obtain a reconstructed facial image, a preset image processing model is converged according to the facial image sample, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and the trained image processing model is used to perform facial replacement on the facial image to be processed.

[0262] For example, a facial image sample pair is obtained, and the facial image sample pair includes a facial image sample and a facial template image sample. The facial image sample is subjected to convolution feature extraction using a feature extraction network of a preset image processing model to obtain initial sample facial features, and then the initial sample facial features are processed using a fully connected layer to obtain a 256-dimensional feature vector, which is used as the sample facial features. The facial template image is subjected to feature extraction using a preset image processing model to obtain facial style features, and the facial style features and the sample facial features are multi-scale fused to obtain the first fused sample facial features at each scale, and the facial template image sample is subjected to facial replacement based on the first fused sample facial features to obtain a replaced facial image. The facial image sample is subjected to feature extraction using a preset image processing model to obtain sample facial style features, and the sample facial style and the sample facial features are multi-scale fused to obtain a second fused sample at each scale, and the facial image sample is subjected to facial replacement based on the second fused sample facial features to obtain a reconstructed facial image sample. According to the facial image samples, the replaced facial images and the reconstructed facial portraits, the perceptual loss information of the facial image sample pairs is determined. Based on the replaced facial images and the facial image samples, the adversarial loss information of the facial image sample pairs is determined. The perceptual loss information and the adversarial loss information are fused. Based on the fused loss information, the preset image processing model is converged to obtain the trained image processing model.

[0263] Obtain a facial image to be processed and a facial template image corresponding to the facial image to be processed. Use the facial style feature extraction network of the trained image processing model to extract facial style features from the facial image to be processed to obtain facial features, and use the facial style feature extraction network to extract facial style features from the facial template image to obtain facial template features. Convert the facial features into a preset number of basic facial features, and determine the convolution layer corresponding to each basic facial feature, convert the facial template features into a preset number of basic facial template features, and determine the convolution layer corresponding to each basic facial template feature, and according to the convolution layer, fuse the basic facial features and the basic facial template features to obtain fused facial features. Input the fused facial features into the stylegan generator to obtain a fused facial image. Perform multi-dimensional feature extraction on the fused facial image to obtain multi-dimensional facial region features, perform multi-dimensional feature extraction on the facial template image to obtain multi-dimensional template facial region features, segment the fused facial region in the fused facial image according to the facial region features, segment the template facial region in the facial template image according to the template facial region features, and use the fused facial region and the template facial region as facial regions. According to the fused facial area and the template facial area, the fused facial image is color corrected to obtain a corrected fused facial image, facial key points are detected in the facial template image to obtain first facial key points, and facial key points are detected in the corrected fused facial image to obtain second facial key points, and according to the first facial key points and the second facial key points, the fused facial image and the facial template image are facially fused to obtain a target facial image.

[0264] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0265] The computer-readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0266] Since the instructions stored in the computer-readable storage medium can execute the steps in any image processing method provided in the embodiments of the present invention, the beneficial effects that can be achieved by any image processing method provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0267] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method provided in the above-mentioned facial image processing aspect or various optional implementations of the face image processing aspect.

[0268] The above is a detailed introduction to an image processing method, device, electronic device and computer-readable storage medium provided by an embodiment of the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. An image processing method, characterized in that: include: Acquire at least one facial image sample pair, wherein the facial image sample pair comprises a facial image sample and a facial template image sample; Using a preset image processing model to extract features from the facial image sample to obtain sample facial features; Using the preset image processing model to extract features from the facial template image sample to obtain facial style features; The facial style features and sample facial features are fused at multiple scales to obtain first fused sample facial features at each scale; Based on the facial features of the first fused sample, performing facial replacement on the facial template image sample to obtain a replaced facial image; Reconstructing the facial image sample based on the sample facial features to obtain a reconstructed facial image; The preset image processing model is converged according to the facial image samples, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and the trained image processing model is used to perform facial replacement on the facial image to be processed.

2. The image processing method according to claim 1, characterized in that: The multi-scale fusion of the facial style features and the sample facial features to obtain the first fused sample facial features at each scale includes: Extracting basic facial style features at each size from the facial style features, and extracting basic sample facial features at each size from the sample facial features; Calculating style feature parameters of the basic facial style features and facial feature parameters of the basic sample facial features; Based on the style feature parameters and the facial feature parameters, the basic facial style features and the basic sample facial features are fused to obtain first fused sample facial features at each size.

3. The image processing method according to claim 2, characterized in that: The step of fusing the basic facial style feature with the basic sample facial feature based on the style feature parameter and the facial feature parameter to obtain a first fused sample facial feature at each size includes: Based on the style feature parameters and the facial feature parameters, the basic facial style features and the basic sample facial features at the same size are fused to obtain initial fused sample facial features at each size; Determining a facial region mask corresponding to the facial image sample at each size according to the facial features of the initial fused samples, wherein the facial region mask is used to indicate an attention weight between the facial features after the initial fusion; The facial region mask is fused with the initial fused sample facial features to obtain first fused sample facial features at each size.

4. The image processing method according to claim 1, characterized in that: The step of performing face replacement on the face template image sample based on the first fused face feature to obtain a replaced face image includes: Generating a basic facial image of a size corresponding to each of the first fused facial features according to the first fused sample facial features; sorting the basic facial images according to the sizes of the basic facial images to obtain sorting information; The size of the basic facial image is adjusted according to the sorting information to obtain a replaced facial image.

5. The image processing method according to claim 4, characterized in that: The step of adjusting the size of the basic facial image according to the sorting information to obtain a replaced facial image includes: Screening out a basic facial image with the smallest size from the basic facial images to obtain a current basic facial image; Enlarging the size of the current basic facial image to obtain an enlarged basic facial image; According to the sorting information, a basic facial image next to the current basic facial image is selected from the basic facial images to obtain a target basic facial image; The enlarged basic facial image and the target basic facial image are fused to obtain the replaced facial image.

6. The image processing method according to claim 5, characterized in that: The step of fusing the enlarged basic facial image with the target basic facial image to obtain the replaced facial image comprises: The enlarged basic facial image and the target basic facial image are fused to obtain a fused basic facial image; Enlarging the size of the fused basic facial image to obtain a target enlarged basic facial image; Using the target basic facial image as the current basic facial image, and using the target enlarged basic facial image as the enlarged basic facial image; Return to the step of filtering out the next basic facial image of the current basic facial image from the basic facial images according to the sorting information, until the last basic facial image is filtered out, and fuse the filtered target basic facial image with the enlarged basic facial image to obtain a replaced facial image.

7. The image processing method according to any one of claims 1 to 6, characterized in that: The method of converging the preset image processing model according to the facial image sample, the replaced facial image and the reconstructed facial image to obtain a trained image processing model includes: Determining reconstruction perception loss information of the facial image sample pair according to the facial image sample and the reconstructed facial image; Determining label-perceived loss information of the facial image sample pair according to the facial image sample and the replaced facial image; Fusing the reconstruction perception loss information and the label perception loss information to obtain the perception loss information of the facial image sample pair; Determining adversarial loss information of the facial image sample pair based on the replaced facial image and the facial image sample; The perceptual loss information and the adversarial loss information are fused, and based on the fused loss information, the preset image processing model is converged to obtain a trained image processing model.

8. The image processing method according to claim 1, characterized in that: The step of using the trained image processing model to perform face replacement on the facial image to be processed comprises: Acquire a facial image to be processed and a facial template image corresponding to the facial image to be processed; Using the trained image processing model to extract features from the facial image to be processed and the facial template image, respectively, to obtain facial features of the facial image to be processed and facial template features of the facial template image; Fusing the facial features with the facial template features, and constructing a fused facial image based on the fused facial features; Performing facial region segmentation on the facial template image and the fused facial image to obtain facial regions; Based on the facial region, the fused facial image and the facial template image are subjected to facial fusion to obtain a target facial image.

9. The image processing method according to claim 8, characterized in that: The fusing of the facial features and the facial template features comprises: Convert the facial features into a preset number of basic facial features, and determine a convolution layer corresponding to each of the basic facial features; Converting the facial template features into the preset number of basic facial template features, and determining a convolution layer corresponding to each of the basic facial template features; According to the convolution layer, the basic facial features and the basic facial template features are fused to obtain fused facial features.

10. The image processing method according to claim 9, characterized in that: The step of fusing the basic facial features and the basic facial template features according to the convolution layer to obtain fused facial features includes: Filtering out basic facial features corresponding to a preset first convolutional layer from the basic facial features to obtain target basic facial features; Filtering out the basic facial template features corresponding to the preset second convolutional layer from the basic facial template features to obtain the target basic facial template features; The convolution layer is used to fuse the target basic facial features and the target basic facial template features to obtain fused facial features.

11. The image processing method according to any one of claims 8 to 10, characterized in that: The step of performing facial region segmentation on the facial template image and the fused facial image to obtain the facial region comprises: Performing multi-dimensional feature extraction on the fused facial image to obtain facial region features in multiple dimensions; Performing multi-dimensional feature extraction on the facial template image to obtain template facial region features of multiple dimensions; Segmenting a fused facial region in the fused facial image according to the facial region features; According to the template facial region feature, a template facial region is segmented in the facial template image, and the fused facial region and the template facial region are used as the facial region.

12. The image processing method according to claim 11, characterized in that: The step of performing facial fusion on the fused facial image and the facial template image based on the facial region to obtain a target facial image comprises: According to the fused facial region and the template facial region, color correction is performed on the fused facial image to obtain a corrected fused facial image; Detecting facial key points in the facial template image to obtain first facial key points, and detecting facial key points in the corrected fused facial image to obtain second facial key points; The fused facial image and the facial template image are subjected to facial fusion according to the first facial key points and the second facial key points to obtain a target facial image.

13. The image processing method according to claim 12, characterized in that: The step of detecting facial key points in the facial template image to obtain first facial key points includes: Extracting features from the facial template image to obtain lightweight facial key point features in multiple dimensions; Fusing the lightweight facial key point features to obtain facial key point features; According to the facial key point features, facial key points are identified in the facial template image to obtain first facial key points.

14. The image processing method according to claim 13, characterized in that: The step of performing facial fusion on the fused facial image and the facial template image according to the first facial key point and the second facial key point to obtain a target facial image comprises: Comparing the first facial key point with the second facial key point to obtain key point deformation information; Adjusting the lightweight facial key point features based on the key point deformation information; Determining interpolation information for deforming the first facial key point to a second facial key point according to the adjusted facial features of the key points; Based on the interpolation information, deforming abnormal key points that are different from the first facial key points and the second facial key points to obtain a deformed facial template image; The fused facial image and the deformed facial template image are fused to obtain a target facial image.

15. An image processing device, characterized in that: include: An acquisition unit, configured to acquire at least one facial image sample pair, wherein the facial image sample pair comprises a facial image sample and a facial template image sample; An extraction unit, configured to extract features from the facial image sample using a preset image processing model to obtain facial features of the sample; A first replacement unit, configured to extract features from the facial template image sample using the preset image processing model to obtain facial style features; The facial style features and sample facial features are multi-scale fused to obtain first fused sample facial features at each scale; based on the first fused sample facial features, the facial template image sample is subjected to facial replacement to obtain a replaced facial image; A reconstruction unit, configured to reconstruct the facial image sample based on the sample facial features to obtain a reconstructed facial image; The second replacement unit is used to converge the preset image processing model according to the facial image sample, the replaced facial image and the reconstructed facial image to obtain a trained image processing model, and use the trained image processing model to perform facial replacement on the facial image to be processed.

16. The image processing device according to claim 15, characterized in that: The second replacement unit comprises: An acquisition subunit, used for acquiring a facial image to be processed and a facial template image corresponding to the facial image to be processed; An extraction subunit, used to use the trained image processing model to perform feature extraction on the facial image to be processed and the facial template image respectively, to obtain facial features of the facial image to be processed and facial template features of the facial template image; A construction subunit, used for fusing the facial features with the facial template features, and constructing a fused facial image based on the fused facial features; A segmentation subunit, used for performing facial region segmentation on the facial template image and the fused facial image to obtain a facial region; The fusion subunit is used to perform facial fusion on the fused facial image and the facial template image based on the facial area to obtain a target facial image.

17. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores an application program, and the processor is used to run the application program in the memory to execute the steps in the image processing method according to any one of claims 1 to 14.

18. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the image processing method according to any one of claims 1 to 14 are implemented.

19. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the image processing method according to any one of claims 1 to 14.

Citation Information

Patent Citations

  • Image fusion generation type face changing method based on face reconstruction

    CN113240792A

  • Image processing method and device, computer equipment and storage medium

    CN113705290A