Training method of face attribute editing model, face attribute editing method and device

By introducing feature matching loss into the face attribute editing model and combining it with adversarial loss, the problem of feature loss in images generated by the face attribute editing model in the existing technology is solved, and the quality and consistency of face attribute editing are improved.

CN112819689BActive Publication Date: 2024-08-27BIGO TECH PTE LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110143937.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-02
Publication Date
2024-08-27
Estimated Expiration
2041-02-02

AI Technical Summary

Technical Problem

Existing face attribute editing models only focus on the attributes to be edited during the training process, resulting in the loss of features of the generated images and affecting the quality of face attribute editing.

Method used

Using the target loss function, including adversarial loss and feature matching loss, face attribute editing is performed through the first image decoder, face reconstruction is performed using the second image decoder, and the feature matching loss is used as part of the loss function, and the training is The model can ensure the consistency of deep semantic features between the generated image and the original image.

Benefits of technology

It improves the quality of face attribute editing, avoids the loss of important features in the original image in the generated image, and ensures the accuracy and consistency of face attribute editing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112819689B
    Figure CN112819689B
Patent Text Reader

Abstract

The embodiment of the present application discloses a training method, a method and a device for editing face attribute models, and belongs to the field of artificial intelligence. The method includes: inputting a first picture into a picture encoder to obtain the encoding features output by the picture encoder; inputting the encoding features into a first picture decoder and a second picture decoder respectively to obtain a second picture and a third picture; based on the second picture and the third picture, constructing a target loss function for the first picture decoder, the target loss function includes adversarial loss and feature matching loss, and the feature matching loss is used to constrain the similarity of deep semantic features between pictures; training the first picture decoder based on the target loss function, and determining the picture encoder and the trained first picture decoder as a face attribute editing model. The scheme provided by the embodiment of the present application can ensure the consistency of deep features in the generated picture and the original picture, which helps to improve the editing quality of face attributes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of artificial intelligence, and in particular to a training method for a face attribute editing model, a face attribute editing method and a device. Background Art

[0002] Face attribute editing is a technology that changes specific attributes of a face in an image or video. For example, face attribute editing can make the face in the image older or younger, change a male face into a female face, or turn it into a celebrity face.

[0003] In the related art, a face attribute editing model obtained by training an auto-encoder is usually used to edit face attributes. When training the face attribute editing model, adversarial loss is usually used as a loss function for model training.

[0004] However, when using adversarial loss as the loss function for model training, since only the attributes to be edited are focused during the training process, it is easy to cause feature loss of the generated image, affecting the quality of face attribute editing. Summary of the invention

[0005] The embodiment of the present application provides a training method for a face attribute editing model, a face attribute editing method and a device. The technical solution is as follows:

[0006] On the one hand, an embodiment of the present application provides a method for training a face attribute editing model, the method comprising:

[0007] Inputting a first picture into a picture encoder to obtain a coding feature output by the picture encoder, wherein a face in the first picture has a first attribute;

[0008] Inputting the encoded features into a first picture decoder and a second picture decoder respectively, obtaining a second picture output by the first picture decoder and a third picture output by the second decoder, wherein a face in the second picture has a second attribute, and a face in the third picture has a first attribute, and the first attribute is different from the second attribute;

[0009] Based on the second picture and the third picture, construct a target loss function of the first picture decoder, wherein the target loss function includes an adversarial loss and a feature matching loss, and the feature matching loss is used to constrain the similarity of deep semantic features between pictures;

[0010] The first picture decoder is trained based on the target loss function, and the picture encoder and the trained first picture decoder are determined as the face attribute editing model.

[0011] On the other hand, an embodiment of the present application provides a method for editing face attributes, the method comprising:

[0012] Obtaining a picture to be edited and attributes of a target face, wherein the attributes of the face in the picture to be edited are different from the attributes of the target face;

[0013] Determine a target face attribute editing model corresponding to the target face attribute, wherein the target face attribute editing model is composed of an image encoder and an image decoder, and the image decoder is trained based on a target loss function, wherein the target loss function includes an adversarial loss and a feature matching loss, and the feature matching loss is used to constrain the similarity of deep semantic features between images;

[0014] The image to be edited is input into the target face attribute editing model to obtain a target image output by the target face attribute editing model, wherein the face in the target image has the target face attributes.

[0015] On the other hand, an embodiment of the present application provides a training device for a face attribute editing model, the device comprising:

[0016] an encoding module, configured to input a first image into an image encoder to obtain an encoding feature output by the image encoder, wherein a face in the first image has a first attribute;

[0017] a decoding module, configured to input the encoded features into a first picture decoder and a second picture decoder respectively, to obtain a second picture output by the first picture decoder and a third picture output by the second decoder, wherein the face in the second picture has a second attribute, the face in the third picture has a first attribute, and the first attribute is different from the second attribute;

[0018] A loss construction module, used to construct a target loss function of the first picture decoder based on the second picture and the third picture, wherein the target loss function includes an adversarial loss and a feature matching loss, and the feature matching loss is used to constrain the similarity of deep semantic features between pictures;

[0019] A training module is used to train the first image decoder based on the target loss function, and determine the image encoder and the first image decoder obtained by training as the face attribute editing model.

[0020] On the other hand, an embodiment of the present application provides a device for editing face attributes, the device comprising:

[0021] An acquisition module, used to acquire the image to be edited and the attributes of a target face, wherein the attributes of the face in the image to be edited are different from the attributes of the target face;

[0022] A model determination module, used to determine a target face attribute editing model corresponding to the target face attribute, wherein the target face attribute editing model is composed of an image encoder and an image decoder, and the image decoder is trained based on a target loss function, wherein the target loss function includes an adversarial loss and a feature matching loss, and the feature matching loss is used to constrain the similarity of deep semantic features between images;

[0023] The editing module is used to input the image to be edited into the target face attribute editing model to obtain a target image output by the target face attribute editing model, wherein the face in the target image has the target face attributes.

[0024] On the other hand, an embodiment of the present application provides a computer device, comprising a processor and a memory; the memory stores at least one instruction, and the at least one instruction is used to be executed by the processor to implement the training method of the facial attribute editing model as described in the above aspects, or to implement the facial attribute editing method described in the above aspects.

[0025] On the other hand, an embodiment of the present application provides a computer-readable storage medium, which stores at least one instruction, and the at least one instruction is used to be executed by a processor to implement the training method of the facial attribute editing model as described in the above aspects, or to implement the facial attribute editing method described in the above aspects.

[0026] On the other hand, an embodiment of the present application provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the training method of the face attribute editing model provided in the above aspect, or the face attribute editing method provided in the above aspect.

[0027] In an embodiment of the present application, when training a facial attribute editing model, a first image decoder is used to edit facial attributes to obtain a second image, and a second image decoder is used to reconstruct a face to obtain a third image. The feature matching loss that constrains the similarity of deep semantic features between images is used as part of the loss function to train the first image decoder. Since the similarity of deep semantic features between images is considered during the training process, when the trained first image decoder is used to edit facial attributes, the consistency of deep features in the generated image and the original image can be guaranteed, thereby avoiding the loss of important features in the original image in the generated image, which helps to improve the editing quality of facial attributes. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1A flowchart of a method for training a face attribute editing model provided by an exemplary embodiment of the present application is shown;

[0029] Figure 2 It is a schematic diagram of the principle of the model training process shown in an exemplary embodiment of the present application;

[0030] Figure 3 A flowchart of a method for training a face attribute editing model provided by another exemplary embodiment of the present application is shown;

[0031] Figure 4 is a schematic diagram of an implementation of a model training process shown in an exemplary embodiment of the present application;

[0032] Figure 5 is a schematic diagram of a network structure of a decoder shown in an exemplary embodiment of the present application;

[0033] Figure 6 is a schematic diagram of an implementation of an attribute perception loss determination process shown in an exemplary embodiment of the present application;

[0034] Figure 7 A flowchart of a method for editing face attributes provided by an exemplary embodiment of the present application is shown;

[0035] Figure 8 A structural block diagram of a training device for a face attribute editing model provided by an exemplary embodiment of the present application is shown;

[0036] Fig. 9 A structural block diagram of a face attribute editing device provided by an exemplary embodiment of the present application is shown. DETAILED DESCRIPTION

[0037] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0038] The term "multiple" as used herein refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.

[0039] For ease of understanding, the nouns involved in the embodiments of the present application are explained below.

[0040] Autoencoder: As an unsupervised learning neural network, the autoencoder is used to represent the input information by taking the input information as the learning target, so that the output information of the autoencoder is close to the input information. The autoencoder consists of an encoder and a decoder, where the encoder is used to extract features from the input information, and the decoder is used to restore the input information based on the features extracted by the encoder.

[0041] Generative Adversarial Networks (GAN): A deep learning model used to achieve unsupervised learning on complex distributions. It consists of a generative model and a discriminative model. The generative model is used to generate images based on the original image output, and the discriminative model is used to determine whether the image is an original image or a generated image. The training process of GAN is the game process between the generative model and the discriminative model. That is, the training goal of the generative model is that the discriminative model cannot distinguish between the original image and the generated image, and the training goal of the discriminative model is to accurately distinguish between the original image and the generated image.

[0042] The training method of the face attribute editing model and the face attribute editing method provided in the embodiments of the present application are applicable to face attribute editing scenarios. Two typical application scenarios are used as examples for illustration.

[0043] 1. Image editing scene

[0044] When the method provided by the embodiment of the present application is applied to a picture editing scenario, the developer first trains a facial attribute editing model for editing different facial attributes based on the facial attributes to be edited. For example, the developer trains a facial attribute editing model for aging a face, a facial attribute editing model for making a face younger, a facial attribute editing model for changing a male face to a female face, and a facial attribute editing model for changing a female face to a male face. After completing the facial attribute editing model training, the facial attribute editing model can be deployed on the server side, and a model calling interface can be set on the application side.

[0045] When editing facial attributes, the user uploads the facial image to be edited through the application and selects the facial attributes to be edited. The application then uploads the facial image and facial attributes to the application's backend server through the model call interface. The backend server obtains a facial attribute editing model that matches the facial attributes to be edited, and uses the facial image as model input to obtain the edited facial image output by the facial attribute model. The edited facial image is then fed back to the application, which then displays the edited facial image.

[0046] 2. Video Editing Scenario

[0047] Similar to the application in the picture editing scenario, when the method provided by the embodiment of the present application is applied to the video editing scenario, the developer also needs to train the face attribute editing model for editing different face attributes. In one possible implementation, when it is necessary to implement the celebrity face changing function, the developer pre-trains the corresponding face attribute editing model based on different celebrity pictures, deploys the face attribute editing model on the server side, and sets the model calling interface on the application side.

[0048] When editing facial attributes, upload the video to be edited through the application, and after selecting the celebrity whose face you want to change, the application uploads the video to be edited and the celebrity ID to the application's backend server through the model call interface. The backend server determines the matching facial attribute editing model based on the celebrity ID, and then uses each video frame in the video to be edited as the model input to obtain the edited video frame output by the facial attribute model (the face in the video frame is changed to the celebrity face), thereby generating an edited video based on the edited video frame, and feeding the edited video back to the application, which then displays the video.

[0049] Of course, the facial attribute editing model training method and facial attribute editing method provided in the embodiments of the present application can be applied not only to the above-mentioned scenarios, but also to other scenarios where facial attributes need to be edited, and other facial attributes other than the above-mentioned examples can be edited, and the embodiments of the present application do not constitute a limitation on this.

[0050] The training method of the face attribute editing model provided in the embodiments of the present application can be applied to computer devices with strong data processing capabilities such as personal computers, workstations, and servers; the face attribute editing method provided in the embodiments of the present application can be applied to electronic devices such as smart phones and tablet computers (for example, the trained face attribute editing model is deployed in a smart phone, so as to realize face attribute editing locally), and can also be applied to computer devices such as personal computers, workstations, and servers (for example, the trained face attribute editing model is deployed on a server, so that the server provides face attribute editing services for applications). For the convenience of description, the following embodiments are explained by taking the training method of the face attribute editing model and the application of the face attribute editing method to a computer device as an example.

[0051] Please refer to Figure 1 , which shows a flow chart of a method for training a face attribute editing model provided by an exemplary embodiment of the present application. The method may include the following steps:

[0052] Step 101: input a first picture into a picture encoder to obtain a coding feature output by the picture encoder, wherein a face in the first picture has a first attribute.

[0053] In a possible implementation, when a face attribute editing model for changing a first attribute of a face into a second attribute needs to be trained, the developer needs to prepare a training data set in advance, and the images in the training data set contain faces, and the faces have the first attribute. For example, when the first attribute is an adult and the second attribute is a child (i.e., the face becomes younger), the images in the training data set are all adult face images; when the first attribute is a female and the second attribute is a male, the images in the training data set are all male face images.

[0054] During the model training process, the computer device inputs the first image in the training data set as a training sample into the image encoder, and the image encoder extracts features from the first image to obtain encoding features. Optionally, the image encoder uses a convolutional neural network to extract features from the first image through several convolutional layers.

[0055] In a possible implementation, in order to improve the encoding and decoding quality, and thus improve the attribute editing quality, the image encoder uses a downsampling convolutional neural network to output structural coding features (structure) and style coding features (texture) through a series of convolutional layers and fully connected layers. The structural coding features are used to characterize the spatial structural features of the image (helping to improve the background reconstruction quality and optimize the occlusion in the image), and the style coding features are used to characterize the style features of the image. Among them, the structural coding features are feature maps of height H, width W, and channel C. SH*W*C, and the style encoding feature is the feature vector.

[0056] Indicatively, Figure 2 As shown, after the computer device inputs the first image 21 into the image encoder 22 , the image encoder 22 encodes the first image 21 to obtain the encoding feature 221 .

[0057] Step 102, input the encoded features into the first picture decoder and the second picture decoder respectively, obtain the second picture output by the first picture decoder, and the third picture output by the second decoder, the face in the second picture has the second attribute, the face in the third picture has the first attribute, and the first attribute is different from the second attribute.

[0058] For the coded features obtained by encoding, the computer device decodes the coded features through the first picture decoder and the second picture decoder respectively. In the embodiment of the present application, the first picture decoder is a decoder for editing facial attributes, and the second picture decoder is a decoder for reconstructing faces. Therefore, the second picture obtained by inputting the coded features into the first picture decoder has different facial attributes from the first picture, and the third picture obtained by inputting the coded features into the second picture decoder has the same facial attributes as the first picture.

[0059] Optionally, the first attribute of the face in the first image and the second attribute of the face in the second image can be different attribute values ​​of the same attribute type, for example, the attribute types corresponding to the first attribute and the second attribute are both age, the first attribute is adult, and the second attribute is child, or the attribute types corresponding to the first attribute and the second attribute are both gender, the first attribute is male, and the second attribute is female.

[0060] Indicatively, Figure 2 The computer device inputs the coding feature 221 into the first picture decoder 23 to obtain the second picture 231 decoded by the first picture decoder 23 ; and inputs the coding feature 221 into the second picture decoder 24 to obtain the third picture 241 decoded by the second picture decoder 24 .

[0061] Step 103: construct a target loss function of the first image decoder based on the second image and the third image. The target loss function includes adversarial loss and feature matching loss. The feature matching loss is used to constrain the similarity of deep semantic features between images.

[0062] Different from the related art, in which only adversarial loss is used as the loss function for model training, in the embodiment of the present application, while ensuring the effect of facial attribute editing, in order to ensure the similarity of deep semantic features between the generated image after facial attribute editing and the original image, that is, to ensure the similarity of facial features before and after facial attribute editing and avoid feature loss during the face editing process, in the embodiment of the present application, the computer device also needs to determine the feature matching loss between the images, thereby determining the target loss function of the first image decoder based on the adversarial loss and the feature matching loss.

[0063] In one possible implementation, a computer device adopts the idea of ​​GAN, determines the adversarial loss of the first image decoder based on the second image (the purpose is to make the generated second image have the second attribute), and determines the feature matching loss of the first image decoder based on the second image and the third image (the purpose is to make the deep semantic features between the second image and the third image similar), thereby fusing the adversarial loss and the feature matching loss to obtain the target loss function of the first image decoder.

[0064] Indicatively, Figure 2 As described, the computer device determines the adversarial loss 25 based on the second image 231 , determines the feature matching loss 26 based on the second image 231 and the third image 241 , and further determines the target loss function 27 based on the adversarial loss 25 and the feature matching loss 26 .

[0065] Step 104: train a first image decoder based on the target loss function, and determine the image encoder and the trained first image decoder as a face attribute editing model.

[0066] Further, the computer device trains the first image decoder based on the constructed target loss function until the training is completed when the loss converges. Optionally, during the training process, the computer device uses a gradient back propagation algorithm to optimize the parameters of the first image decoder.

[0067] After the training is completed, the computer device determines the image encoder and the first image decoder as a face attribute editing model for editing the face attribute from the first attribute to the second attribute. When the face attribute is subsequently edited, the image encoder is used to extract features, and the first image decoder is used to edit the face attribute based on the extracted features. Of course, when the computer device can also use different training data sets to train the face attribute editing model for editing different face attributes (the image encoder can be shared), the embodiments of the present application will not be repeated here.

[0068] Optionally, after completing the training of the first image decoder, the computer device may test the first image decoder using a test data set, which is not limited in this embodiment.

[0069] Indicatively, Figure 2 As shown, the computer device trains the first image decoder 23 based on the target loss function 27, and determines the trained first image decoder 23 and image encoder 22 as a face attribute editing model.

[0070] To summarize, in an embodiment of the present application, when training a facial attribute editing model, a first image decoder is used to perform facial attribute editing to obtain a second image, a second image decoder is used to perform face reconstruction to obtain a third image, and a feature matching loss that constrains the similarity of deep semantic features between images is used as part of a loss function to train the first image decoder. Since the similarity of deep semantic features between images is taken into account during the training process, when the trained first image decoder is used to edit facial attributes, the consistency of deep features in the generated image and the original image can be ensured, thereby avoiding the loss of important features in the original image in the generated image, and helping to improve the editing quality of facial attributes.

[0071] In a possible implementation, in order to ensure that during the facial attribute editing process, in addition to changing the first attribute to the second attribute, the generated image maintains consistency with other attributes of the face in the original image, such as the color of the pupil of the eye, the type of bangs, whether glasses are worn, etc., in an embodiment of the present application, the computer device will also use the attribute perception loss used to constrain the facial attributes as part of the target loss function, which is illustrated below using an exemplary embodiment.

[0072] Please refer to Figure 3 , which shows a flow chart of a method for training a face attribute editing model provided by another exemplary embodiment of the present application. The method may include the following steps:

[0073] Step 301: input a first picture into a picture encoder to obtain a coding feature output by the picture encoder, wherein a face in the first picture has a first attribute.

[0074] The implementation of this step may refer to the above step 101, and this embodiment will not be described in detail here.

[0075] Indicatively, Figure 4 As shown, when the face in the image needs to be rejuvenated, during the training process, the computer device inputs the first image 41 (the face attribute is adult) into the image encoder 42, and obtains the structural coding feature map 421 and the style coding feature vector 422 output by the image encoder 42.

[0076] Step 302, input the encoded features into the first picture decoder and the second picture decoder respectively, obtain the second picture output by the first picture decoder, and the third picture output by the second decoder, the face in the second picture has the second attribute, the face in the third picture has the first attribute, and the first attribute is different from the second attribute.

[0077] The implementation of this step may refer to the above step 102, and this embodiment will not be repeated here.

[0078] Indicatively, Figure 4 As shown, the computer device inputs the structural coding feature map 421 and the stylistic coding feature vector 422 into the first picture decoder 43 respectively, and obtains the second picture 431 output by the first picture decoder 43, and the attribute of the face in the second picture 431 is a child; the computer device inputs the structural coding feature map 421 and the stylistic coding feature vector 422 into the second picture decoder 44 respectively, and obtains the third picture 441 output by the second picture decoder 44, and the attribute of the face in the third picture 441 is also an adult.

[0079] Step 303: determine the adversarial loss based on the second image.

[0080] In a possible implementation, the computer device uses a least squares GAN (LSGAN) and constrains the second image through the adversarial loss of the adversarial network, so that the generated second image has the second attribute.

[0081] In an embodiment of the present application, during the model training process, the computer device is configured to discriminate between the original image (or real image) and the generated image with the second attribute, that is, the discriminator is used to distinguish whether the image with the second attribute is the original image or the generated image output by the generator (the second image decoder in the present application). The discriminator plays a key role in the adversarial loss, and needs to learn to distinguish the difference between the generated image and the original image (both with the second attribute) during the training process; and the generator is confronted with the discriminator during the training process, so that the discriminator cannot distinguish between the original image and the generated image.

[0082] In some embodiments, the computer device inputs the second image into the discriminator to obtain a discrimination result output by the discriminator, thereby determining the adversarial loss based on the discrimination result. The adversarial loss of the generator can be expressed as:

[0083] Loss_G=(D(G(x))-1) 2

[0084] Among them, G is the generator, D is the discriminator, x is the first picture, and the discriminator's discriminant result is a value of 0-1. When the discriminant result is 0, it indicates that the picture is a generated picture; when the discriminant result is 1, it indicates that the picture is an original picture.

[0085] Accordingly, in the process of training the second image decoder, the computer device needs to train the discriminator (using the generated image with the second attribute and the original image with the second attribute), wherein the second image decoder and the discriminator can be trained alternately. In the process of training the discriminator, the adversarial loss of the discriminator can be expressed as:

[0086] Loss_D=(D(x)-1) 2 +D(G(x)) 2

[0087] Indicatively, Figure 4 As shown, the computer device determines the adversarial loss 45 of the first picture decoder 43 based on the second picture 431 .

[0088] Step 304: Determine feature matching loss based on the deep semantic features corresponding to the second image and the third image respectively.

[0089] In order to ensure that the second image obtained by attribute editing can still maintain feature similarity with the first image, and because the third image is reconstructed from the first image (has similar features to the first image), in the embodiment of the present application, the computer device obtains the deep semantic features corresponding to the second image and the third image respectively, thereby determining the feature matching loss based on the difference between the deep semantic features of the two. In a possible implementation, this step may include the following steps.

[0090] 1. Obtain a first depth feature map in a process in which a first image decoder generates a second image, and a second depth feature map in a process in which a second image decoder generates a third image. The network structures of the first image decoder and the second image decoder are the same, and the first depth feature map and the second depth feature map are feature maps output by the same network layer.

[0091] In the embodiment of the present application, the network structure of the first image decoder and the second image decoder is the same. Therefore, when determining the degree of feature matching between the second image and the third image, the computer device extracts a layer of low-resolution feature map (i.e., a first depth feature map) with deep semantic information in the first image decoder, and extracts a layer of low-resolution feature map (i.e., a second depth feature map) with the same network depth (i.e., the same network layer output) in the second image decoder, so as to determine the degree of feature matching between the second image and the third image based on the first depth feature map and the second feature map of the same semantic depth, so that the first image can still maintain features similar to those of the first image on the low-resolution feature map after attribute editing.

[0092] Among them, the network level used when extracting the first depth feature map and the second depth feature map can be preset by the developer, and this embodiment does not limit this.

[0093] In a possible implementation, the first picture decoder and the second picture decoder are both composed of a series of residual modules based on adaptive instance normalization (Adaptive Instance Normalization, AdaIN), and the upsampling layer adopts a transpose convolution layer (Transpose Convolution Layer). Schematically, the structures of the first picture decoder and the second picture decoder are as follows Figure 5 shown.

[0094] The size of each feature map in the structural coding features of the input image decoder is 8×32, and the style coding features are vectors of 1×2048. The sizes of the residual modules in the image decoder are 32×128, 32×256, 32×384, 32×512, 54×512, 128×512, 256×256, and 512×128, respectively.

[0095] The residual module can be represented by the formula y=F(x)+x, where F(·) represents the convolution transformation, x is the input of the residual module, and y is the output of the residual module. The residual module allows the input feature x to be reused and can provide a shortcut for x in the back propagation process of parameter optimization, making the neural network with the residual module easier to train.

[0096] 2. Determine the feature matching loss based on the first depth feature map and the second depth feature map.

[0097] Further, the computer device determines the feature matching loss of the first image decoder by comparing the difference between the first depth feature map and the second depth feature map. The feature matching loss can be expressed as:

[0098] Feature Matching Loss=(x_-y_) 2

[0099] Among them, x_ is the first depth feature map, y_ is the second depth feature map, and the greater the feature matching loss, the higher the degree of feature loss or change when the first image decoder performs attribute editing, and the worse the feature retention is. Conversely, the better the feature retention is.

[0100] Indicatively, Figure 4 As shown, the computer device obtains the first depth feature map 432 and the second depth feature map 442 corresponding to the first image decoder 43 and the second image decoder 44 respectively, thereby determining the feature matching loss 46 between the second image and the third image based on the first depth feature map 432 and the second depth feature map 442.

[0101] Step 305 , determining an attribute perception loss based on the first image and the second image, where the attribute perception loss is used to constrain facial attributes other than the first attribute and the second attribute.

[0102] In the related art, when editing face attributes, in addition to the target face attributes to be edited, other attributes other than the target face attributes may also change or even be lost, affecting the final attribute editing quality. In order to make the other face attributes other than the target face attributes in the generated image consistent with the original image, in the embodiment of the present application, in the process of training the first image decoder, the attribute perception loss of the face attributes other than the first attribute and the second attribute is constrained as part of the target loss function.

[0103] In order to quantify the attribute perception loss between images, in an embodiment of the present application, before training the first image decoder, the computer device first trains a face attribute classifier for facial attribute classification, and then uses the trained face attribute classifier to determine the attribute perception loss between the first image and the second image.

[0104] Optionally, the face attribute classifier is composed of a feature extraction layer (composed of several convolutional layers) and a fully connected layer, the feature extraction layer is used to extract features from the input image, and the fully connected layer is used to classify based on the extracted features. When training the face attribute classifier, the following steps may be included:

[0105] 1. Get a first sample image, which contains a corresponding attribute label.

[0106] When training a face attribute classifier, it is first necessary to construct a training set, in which each first sample image contains a corresponding attribute label. For example, the attribute label is used to indicate the pupil color, lip shape, bangs type, whether glasses are worn, etc. of the face in the first sample image. This embodiment does not limit the attribute type.

[0107] 2. Input the first sample image into the face attribute classifier to obtain the sample attribute classification result output by the face attribute classifier.

[0108] After the computer device inputs the first sample image into the face attribute classifier, the face attribute classifier extracts features from the first sample image through the feature extraction layer, and inputs the extracted features into the fully connected layer, which performs fully connected processing, and then classifies the fully connected results through the classifier to obtain the sample attribute classification result corresponding to the first sample image.

[0109] 3. Determine the face attribute classifier based on the attribute label and sample attribute classification results.

[0110] In one possible implementation, a computer device uses attribute labels as supervision of sample attribute classification results, determines the attribute classification loss (cross entropy loss) of a face attribute classifier, and thereby trains the face attribute classifier based on the attribute classification loss, ultimately training a face attribute classifier that can accurately identify face attributes.

[0111] Accordingly, the computer device may determine the attribute perception loss of the first image and the second image, including the following steps:

[0112] 1. Input the first image and the second image into the feature extraction layer of the face attribute classifier respectively to obtain a first attribute feature map corresponding to the first image and a second attribute feature map corresponding to the second image.

[0113] Optionally, after the computer device inputs the first image and the second image into the face attribute classifier respectively, it obtains the feature map output by the last convolutional layer in the feature extraction layer as the first attribute feature map and the second attribute feature map.

[0114] Indicatively, Figure 6 As shown, the feature extraction layer 51 in the face attribute classifier performs feature extraction on the first image 41 to obtain a first attribute feature map 52 , and performs feature extraction on the second image 431 to obtain a second attribute feature map 53 .

[0115] 2. Input the first attribute feature map and the second attribute feature map into the fully connected layer of the face attribute classifier respectively to obtain the first face attribute classification result corresponding to the first image and the second face attribute classification result corresponding to the second image.

[0116] Furthermore, the computer device performs full connection processing on the first attribute feature map and the second attribute feature map respectively through the fully connected layer of the face attribute classifier to obtain a first face attribute classification result corresponding to the first image and a second face attribute classification result corresponding to the second image, wherein the first face attribute classification result and the second face attribute classification result are classification results without softmax processing.

[0117] Indicatively, Figure 6 As shown, the fully connected layer 54 in the face attribute classifier performs fully connected processing on the first attribute feature map 52 and the second attribute feature map 53 respectively to obtain a first face attribute classification result 55 and a second face attribute classification result 56.

[0118] 3. The L2 loss between the first attribute feature map and the second attribute feature map, and the L2 loss between the first face attribute classification result and the second face attribute classification result are determined as attribute perception loss.

[0119] In order to avoid the one-sidedness when determining the attribute perception loss based only on the face attribute classification result, in this embodiment, the computer device jointly determines the loss between the first attribute feature map and the second attribute feature map, and the loss between the first face attribute classification result and the second face attribute classification result as the attribute perception loss of the first image decoder, wherein the loss between the feature maps can adopt the L2 loss, and the loss between the classification results can also adopt the L2 loss.

[0120] Among them, the attribute perceptual loss (Attribute Perceptual Loss) of the first image decoder can be expressed as:

[0121] Attribute Perceptual Loss

[0122] =(Ext(G(x))-Ext(x)) 2 +(classifer(G(x))-classifer(x)) 2

[0123] Wherein, x is the first image, Ext(·) is the feature map output by the last convolutional layer of the face attribute classifier, classifer(·) is the face attribute classification result, and G is the generator (including the image encoder and the first image decoder).

[0124] Indicatively, Figure 6 As shown, the computer device jointly determines the L2 loss between the first attribute feature map 52 and the second attribute feature map 53, and the L2 loss between the first face attribute classification result 55 and the second face attribute classification result 56 as the attribute perception loss 47 of the first image decoder.

[0125] Step 306, determining a target loss function based on the adversarial loss, the feature matching loss, and the attribute perception loss.

[0126] Furthermore, the computer device jointly determines the target loss function based on the adversarial loss, feature matching loss and attribute perception loss, wherein the adversarial loss, feature matching loss and attribute perception loss in the target loss function may correspond to respective loss weights, which may be hyperparameters set during the training process, and this embodiment does not limit this.

[0127] Step 307: train the first image decoder based on the target loss function, and determine the image encoder and the trained first image decoder as a face attribute editing model.

[0128] The implementation of this step may refer to the above step 104, and this embodiment will not be repeated here.

[0129] In this embodiment, the computer device pre-trains a facial attribute classifier, and uses the facial attribute classifier to determine the attribute perception loss between the original image (i.e., the first image) and the generated image (i.e., the second image), thereby using the attribute perception loss as part of the target loss function for model training. During the model training process, the facial attributes of the generated image except for the first attribute and the second attribute in the original image are consistent, thereby further improving the editing quality of the facial attributes.

[0130] In a possible implementation, before training the first picture decoder, the computer device first trains the picture encoder and the second picture decoder, that is, pre-trains the autoencoder for facial picture reconstruction, and in the subsequent training of the first picture decoder, there is no need to train the picture encoder and the second picture decoder. Optionally, the computer device autoencodes the second sample picture through the picture encoder and the second picture decoder to obtain a sample generated picture, thereby determining the reconstruction loss function based on the sample generated picture and the second sample picture. In order to ensure the quality of training, the computer device uses the second sample picture to have a diversity of facial attributes, that is, to train with sample pictures of different ages and races, and the reconstruction loss function can be the L1 loss between the sample generated picture and the second sample picture, which is not limited in this implementation.

[0131] Furthermore, the computer device trains the picture encoder and the second picture decoder based on the reconstruction loss function. The computer device may use a gradient back propagation algorithm to optimize parameters of the picture encoder and the second picture decoder.

[0132] Please refer to Figure 7, which shows a flow chart of a method for editing face attributes provided by an exemplary embodiment of the present application. The method may include the following steps:

[0133] Step 701, obtaining the image to be edited and the target face attributes, wherein the attributes of the face in the image to be edited are different from the attributes of the target face.

[0134] In a possible implementation, the application provides several editable face attributes for the user to select, and the editable face attribute selected by the user is the target face attribute. The target face attribute can be a child face, an adult face, a male face, a female face, or a specific celebrity face, etc., which is not limited in this embodiment.

[0135] Optionally, the image to be edited is a single image, or a video frame in a video.

[0136] Step 702, determine the target face attribute editing model corresponding to the target face attribute, the target face attribute editing model is composed of an image encoder and an image decoder, and the image decoder is trained based on a target loss function, the target loss function includes adversarial loss and feature matching loss, and the feature matching loss is used to constrain the similarity of deep semantic features between images.

[0137] In a possible implementation, a face attribute editing model for editing different face attributes is deployed in a computer device, each face attribute editing model is composed of an image encoder and an image decoder, and each face attribute encoding model is trained using the face attribute encoding model training method provided in each of the above embodiments. Accordingly, the computer device selects the face attribute editing model for editing the target face attribute as the target face attribute editing model.

[0138] Optionally, different face attribute editing models may share a picture encoder, and different face attribute encoding models correspond to different picture decoders.

[0139] Step 703, input the image to be edited into the target face attribute editing model, obtain the target image output by the target face attribute editing model, and the face in the target image has the target face attributes.

[0140] Furthermore, the computer device uses the picture to be edited as the model input, and the picture encoder in the target facial attribute encoding model encodes the picture to be edited (i.e., feature extraction) to obtain encoding features, and the picture decoder decodes based on the encoding features (i.e., picture reconstruction) to obtain a target picture with target facial attributes.

[0141] To summarize, in an embodiment of the present application, when training a facial attribute editing model, a first image decoder is used to perform facial attribute editing to obtain a second image, a second image decoder is used to perform face reconstruction to obtain a third image, and a feature matching loss that constrains the similarity of deep semantic features between images is used as part of a loss function to train the first image decoder. Since the similarity of deep semantic features between images is taken into account during the training process, when the trained first image decoder is used to edit facial attributes, the consistency of deep features in the generated image and the original image can be ensured, thereby avoiding the loss of important features in the original image in the generated image, and helping to improve the editing quality of facial attributes.

[0142] Please refer to Figure 8 , which shows a structural block diagram of a training device for a face attribute editing model provided by an exemplary embodiment of the present application. The device may include:

[0143] An encoding module 801 is used to input a first picture into a picture encoder to obtain an encoding feature output by the picture encoder, wherein a face in the first picture has a first attribute;

[0144] A decoding module 802 is used to input the encoded features into a first picture decoder and a second picture decoder respectively, to obtain a second picture output by the first picture decoder and a third picture output by the second decoder, wherein the face in the second picture has a second attribute, the face in the third picture has a first attribute, and the first attribute is different from the second attribute;

[0145] A loss construction module 803 is used to construct a target loss function of the first picture decoder based on the second picture and the third picture, wherein the target loss function includes an adversarial loss and a feature matching loss, and the feature matching loss is used to constrain the similarity of deep semantic features between pictures;

[0146] The training module 804 is used to train the first picture decoder based on the target loss function, and determine the picture encoder and the first picture decoder obtained by training as the face attribute editing model.

[0147] Optionally, the loss construction module 803 includes:

[0148] A first loss determining unit, configured to determine the adversarial loss based on the second image;

[0149] A second loss determining unit, configured to determine the feature matching loss based on deep semantic features corresponding to the second picture and the third picture respectively;

[0150] A loss construction unit is used to determine the target loss function based on the adversarial loss and the feature matching loss.

[0151] Optionally, the second loss determining unit is configured to:

[0152] Obtaining a first depth feature map in a process in which the first picture decoder generates the second picture, and a second depth feature map in a process in which the second picture decoder generates the third picture, wherein the first picture decoder and the second picture decoder have the same network structure, and the first depth feature map and the second depth feature map are feature maps output by the same network layer;

[0153] The feature matching loss is determined based on the first depth feature map and the second depth feature map.

[0154] Optionally, the first loss determining unit is configured to:

[0155] Inputting the second image into a discriminator to obtain a discrimination result output by the discriminator, wherein the discriminator is used to discriminate between an original image and a generated image having the second attribute;

[0156] The adversarial loss is determined based on the discrimination result.

[0157] Optionally, the loss construction module 803 further includes:

[0158] a third loss determining unit, configured to determine an attribute perception loss based on the first picture and the second picture, wherein the attribute perception loss is used to constrain face attributes other than the first attribute and the second attribute;

[0159] The loss construction unit is used to:

[0160] The objective loss function is determined based on the adversarial loss, the feature matching loss, and the attribute-aware loss.

[0161] Optionally, the third loss determination unit is used to:

[0162] Inputting the first image and the second image into a feature extraction layer of a face attribute classifier respectively, to obtain a first attribute feature map corresponding to the first image and a second attribute feature map corresponding to the second image;

[0163] Inputting the first attribute feature map and the second attribute feature map into the fully connected layer of the face attribute classifier respectively, to obtain a first face attribute classification result corresponding to the first image, and a second face attribute classification result corresponding to the second image;

[0164] The L2 loss between the first attribute feature map and the second attribute feature map, and the L2 loss between the first face attribute classification result and the second face attribute classification result are determined as the attribute perception loss.

[0165] Optionally, the device further comprises a classifier training module, and the classifier training module is used to:

[0166] Obtain a first sample image, where the first sample image includes a corresponding attribute label;

[0167] Inputting the first sample image into the face attribute classifier to obtain a sample attribute classification result output by the face attribute classifier;

[0168] The face attribute classifier is determined based on the attribute label and the sample attribute classification result.

[0169] Optionally, the device further comprises an autoencoder training module, the autoencoder training module being used to:

[0170] Self-encode the second sample picture by using the picture encoder and the second picture decoder to obtain a sample generated picture;

[0171] Determine a reconstruction loss function based on the sample generated picture and the second sample picture;

[0172] The picture encoder and the second picture decoder are trained based on the reconstruction loss function.

[0173] Optionally, the coding features include structural coding features and style coding features, the structural coding features are used to characterize the spatial structural features of the image, and the style coding features are used to characterize the style features of the image.

[0174] To summarize, in an embodiment of the present application, when training a facial attribute editing model, a first image decoder is used to perform facial attribute editing to obtain a second image, a second image decoder is used to perform face reconstruction to obtain a third image, and a feature matching loss that constrains the similarity of deep semantic features between images is used as part of a loss function to train the first image decoder. Since the similarity of deep semantic features between images is taken into account during the training process, when the trained first image decoder is used to edit facial attributes, the consistency of deep features in the generated image and the original image can be ensured, thereby avoiding the loss of important features in the original image in the generated image, and helping to improve the editing quality of facial attributes.

[0175] Please refer to Fig. 9 , which shows a structural block diagram of a face attribute editing device provided by an exemplary embodiment of the present application. The device may include:

[0176] The acquisition module 901 is used to acquire the image to be edited and the attributes of the target face, wherein the attributes of the face in the image to be edited are different from the attributes of the target face;

[0177] A model determination module 902 is used to determine a target face attribute editing model corresponding to the target face attribute, wherein the target face attribute editing model is composed of an image encoder and an image decoder, and the image decoder is trained based on a target loss function, wherein the target loss function includes an adversarial loss and a feature matching loss, and the feature matching loss is used to constrain the similarity of deep semantic features between images;

[0178] The editing module 903 is used to input the image to be edited into the target face attribute editing model to obtain a target image output by the target face attribute editing model, wherein the face in the target image has the target face attributes.

[0179] It should be noted that: when the device provided in the above embodiment realizes its function, only the division of the above functional modules is used as an example. In actual application, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0180] An embodiment of the present application also provides a computer device, which includes a processor and a memory, wherein the memory stores at least one instruction, and the at least one instruction is used to be executed by the processor to implement the training method of the facial attribute editing model described in the above embodiments, or to implement the facial attribute editing method described in the above embodiments.

[0181] An embodiment of the present application also provides a computer-readable storage medium, which stores at least one instruction, and the at least one instruction is loaded and executed by a processor to implement the training method of the facial attribute editing model described in the above embodiments, or to implement the facial attribute editing method described in the above embodiments.

[0182] 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 including computer instructions, the computer instructions being 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 training method of the face attribute editing model provided in various optional implementations of the above aspects, or executes the face attribute editing method provided in various optional implementations of the above aspects.

[0183] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented with hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable storage medium or transmitted as one or more instructions or codes on a computer-readable storage medium. Computer-readable storage media include computer storage media and communication media, wherein the communication media include any media that facilitates the transmission of a computer program from one place to another. The storage medium can be any available medium that a general or special-purpose computer can access.

[0184] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

Claims

1. A training method for a face attribute editing model, It is characterized in that The method comprises: Inputting a first picture into a picture encoder to obtain a coding feature output by the picture encoder, wherein a face in the first picture has a first attribute; Inputting the encoded features into a first picture decoder and a second picture decoder respectively, obtaining a second picture output by the first picture decoder and a third picture output by the second picture decoder, wherein a face in the second picture has a second attribute, and a face in the third picture has a first attribute, and the first attribute is different from the second attribute; determining an adversarial loss based on the second image; Determine a feature matching loss based on the deep semantic features corresponding to the second picture and the third picture, where the feature matching loss is used to constrain the similarity of the deep semantic features between the pictures; Determine an attribute perception loss based on the first image and the second image, where the attribute perception loss is used to constrain face attributes other than the first attribute and the second attribute; Determine a target loss function based on the adversarial loss, the feature matching loss, and the attribute perception loss; The first image decoder is trained based on the target loss function, and the image encoder and the trained first image decoder are determined as the face attribute editing model.

2. The method according to claim 1, It is characterized in that The determining the feature matching loss based on the deep semantic features corresponding to the second picture and the third picture respectively includes: Obtaining a first depth feature map in a process in which the first picture decoder generates the second picture, and a second depth feature map in a process in which the second picture decoder generates the third picture, wherein the first picture decoder and the second picture decoder have the same network structure, and the first depth feature map and the second depth feature map are feature maps output by the same network layer; The feature matching loss is determined based on the first depth feature map and the second depth feature map.

3. The method according to claim 1, It is characterized in that The determining the adversarial loss based on the second image includes: Inputting the second image into a discriminator to obtain a discrimination result output by the discriminator, wherein the discriminator is used to discriminate between an original image and a generated image having the second attribute; The adversarial loss is determined based on the discrimination result.

4. The method according to claim 1, It is characterized in that The determining the attribute perception loss based on the first picture and the second picture includes: Inputting the first image and the second image into a feature extraction layer of a face attribute classifier respectively, to obtain a first attribute feature map corresponding to the first image and a second attribute feature map corresponding to the second image; Inputting the first attribute feature map and the second attribute feature map into the fully connected layer of the face attribute classifier respectively, to obtain a first face attribute classification result corresponding to the first image, and a second face attribute classification result corresponding to the second image; The L2 loss between the first attribute feature map and the second attribute feature map, and the L2 loss between the first face attribute classification result and the second face attribute classification result are determined as the attribute perception loss.

5. The method according to claim 4, It is characterized in that The method further comprises: Obtain a first sample image, where the first sample image includes a corresponding attribute label; Inputting the first sample image into the face attribute classifier to obtain a sample attribute classification result output by the face attribute classifier; The face attribute classifier is determined based on the attribute label and the sample attribute classification result.

6. The method according to any one of claims 1 to 5, It is characterized in that Before inputting the first picture into the picture encoder and obtaining the encoding feature output by the picture encoder, the method further includes: Self-encode the second sample picture by using the picture encoder and the second picture decoder to obtain a sample generated picture; Determine a reconstruction loss function based on the sample generated picture and the second sample picture; The picture encoder and the second picture decoder are trained based on the reconstruction loss function.

7. The method according to any one of claims 1 to 5, It is characterized in that The coding features include structural coding features and style coding features. The structural coding features are used to characterize the spatial structural features of the image, and the style coding features are used to characterize the style features of the image.

8. A method for editing face attributes, It is characterized in that The method comprises: Obtaining a picture to be edited and attributes of a target face, wherein the attributes of the face in the picture to be edited are different from the attributes of the target face; Determine a target facial attribute editing model corresponding to the target facial attribute, wherein the target facial attribute editing model is composed of an image encoder and an image decoder, and the image decoder is trained using the facial attribute editing model training method according to any one of claims 1 to 7; The image to be edited is input into the target face attribute editing model to obtain a target image output by the target face attribute editing model, wherein the face in the target image has the target face attributes.

9. A training device for a face attribute editing model, It is characterized in that The device comprises: an encoding module, configured to input a first picture into a picture encoder to obtain an encoding feature output by the picture encoder, wherein a face in the first picture has a first attribute; a decoding module, configured to input the encoded features into a first picture decoder and a second picture decoder respectively, to obtain a second picture output by the first picture decoder and a third picture output by the second picture decoder, wherein the face in the second picture has a second attribute, the face in the third picture has a first attribute, and the first attribute is different from the second attribute; A loss construction module, configured to determine an adversarial loss based on the second image; Determine a feature matching loss based on the deep semantic features corresponding to the second picture and the third picture, where the feature matching loss is used to constrain the similarity of the deep semantic features between the pictures; Determine an attribute perception loss based on the first image and the second image, where the attribute perception loss is used to constrain face attributes other than the first attribute and the second attribute; Determine a target loss function based on the adversarial loss, the feature matching loss, and the attribute perception loss; A training module is used to train the first image decoder based on the target loss function, and determine the image encoder and the first image decoder obtained by training as the face attribute editing model.

10. A facial attribute editing device, It is characterized in that The device comprises: An acquisition module, used to acquire the image to be edited and the attributes of a target face, wherein the attributes of the face in the image to be edited are different from the attributes of the target face; A model determination module, used for determining a target face attribute editing model corresponding to the target face attribute, wherein the target face attribute editing model is composed of a picture encoder and a picture decoder, and the picture decoder is trained by the training device for the face attribute editing model according to claim 9; The editing module is used to input the image to be edited into the target face attribute editing model to obtain a target image output by the target face attribute editing model, wherein the face in the target image has the target face attributes.

11. A computer device, It is characterized in that The computer device includes a processor and a memory; the memory stores at least one instruction, and the at least one instruction is used to be executed by the processor to implement the training method of the facial attribute editing model as described in any one of claims 1 to 7, or to implement the facial attribute editing method as described in claim 8.

12. A computer-readable storage medium, It is characterized in that The storage medium stores at least one instruction, and the at least one instruction is used to be executed by the processor to implement the training method of the facial attribute editing model as described in any one of claims 1 to 7, or to implement the facial attribute editing method as described in claim 8.