# US 2025/0054108 A1 · Method for training face swap model, computer device, and storage medium

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2025/0054108 A1
- Document ID: US20250054108A1
- Status: Published application
- Kind: A1
- Application number: 18/813,534
- Filed: 2024-08-23
- Published: 2025-02-13
- Earliest claimed: 2022-11-22
- Assignees: Tencent Technology (Shenzhen) Company Limited
- Applicants: Tencent Technology (Shenzhen) Company Limited
- Inventors: Keke HE; Junwei ZHU; Ying TAI; Chengjie WANG
- Web page: https://patentgrep.com/patent/US20250054108A1

## CPC

- G06T 5/50: using two or more images, e.g. averaging or subtraction
- G06F 18/00: Pattern recognition
- G06T 9/00: Image coding (bandwidth or redundancy reduction for static pictures H04N1/41; coding or decoding of static colour picture signals H04N1/64; methods or arrangements for coding, decoding, compressing or decompressing digital video signals H04N19/00)
- G06V 10/761: {Proximity, similarity or dissimilarity measures}
- G06V 10/806: {of extracted features}
- G06V 10/82: using neural networks
- G06V 40/171: {Local features and components; Facial parts (eye characteristics G06V40/18); Occluding parts, e.g. glasses; Geometrical relationships}
- G06V 40/174: {Facial expression recognition}
- G06T 2207/20084: Artificial neural networks [ANN]
- G06T 2207/20221: Image fusion; Image merging
- G06T 2207/30201: Face
- G06T: IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06V: IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING

## Abstract

A method for training a face swap model includes concatenating an expression feature of a template image and an identity feature of a source face image to obtain a combined feature; performing encoding based on the source face image and the template image to obtain an encoding feature required for face swap; fusing the encoding feature and the combined feature to obtain a fused feature; performing decoding based on the fused feature to obtain a swapped face image; respectively predicting image attribute discrimination results of the swapped face image and a reference image by using a discriminator network of the face swap model; and calculating a difference between an expression feature of the swapped face image and the template image, calculating a difference between an identity feature of the swapped face image and the source face image, and updating the generator network and the discriminator network.

## Claims

### Claim 1

A method for training a face swap model, performed by a computer device, the method comprising:
acquiring a sample triplet, the sample triplet comprising a source face image, a template image, and a reference image;
concatenating an expression feature of the template image and an identity feature of the source face image to obtain a combined feature;
performing encoding based on the source face image and the template image by using a generator network of the face swap model to obtain an encoding feature required for face swap;
fusing the encoding feature and the combined feature to obtain a fused feature;
performing decoding based on the fused feature by using the generator network of the face swap model to obtain a swapped face image;
respectively predicting an image attribute discrimination result of the swapped face image and an image attribute discrimination result of the reference image by using a discriminator network of the face swap model, an image attribute comprising forged image and non-forged image; and
calculating a difference between an expression feature of the swapped face image and the expression feature of the template image, calculating a difference between an identity feature of the swapped face image and an identity feature of the source face image, and updating the generator network and the discriminator network, based on the image attribute discrimination result of the swapped face image and the image attribute discrimination result of the reference image, the calculated difference of the expression features between the swapped face image and the template image, and the calculated difference of the identity features between the swapped face image and the source face image.

### Claim 2 (depends on 1)

The method according to claim 1, wherein the acquiring of the sample triplet comprises:
acquiring a first image and a second image, the first image and the second image corresponding to a same identity attribute and corresponding to different non-identity attributes;
acquiring a third image, the third image and the first image corresponding to different identity attributes;
replacing an object in the second image with an object in the third image to obtain a fourth image; and
constructing the sample triplet by using the first image as the source face image, the fourth image as the template image, and the second image as the reference image.

### Claim 3 (depends on 1)

The method according to claim 1, further comprising:
extracting a feature from the template image by using an expression recognition network of the face swap model to obtain the expression feature of the template image; and
extracting a feature from the source face image by using a face recognition network of the face swap model to obtain the identity feature of the source face image,
the expression recognition network and the face recognition network both being pre-trained neural network models.

### Claim 4 (depends on 1)

The method according to claim 1, wherein performing the encoding based on the source face image and the template image by using the generator network of the face swap model to obtain the encoding feature required for face swap comprises:
concatenating the source face image and the template image to obtain an input image;
inputting the input image into the face swap model; and
encoding the input image by using the generator network of the face swap model to obtain the encoding feature required for face swap on the template image.

### Claim 5 (depends on 1)

The method according to claim 1, wherein fusing the encoding feature and the combined feature to obtain the fused feature comprises:
calculating a mean value and a standard deviation of the encoding feature, and calculating a mean value and a standard deviation of the combined feature;
normalizing the encoding feature based on the mean value and the standard deviation of the encoding feature to obtain a normalized encoding feature; and
transferring a style of the combined feature to the normalized encoding feature based on the mean value and the standard deviation of the combined feature to obtain the fused feature.

### Claim 6 (depends on 1)

The method according to claim 1, wherein respectively predicting the image attribute discrimination result of the swapped face image and the image attribute discrimination result of the reference image by using the discriminator network of the face swap model comprises:
inputting the swapped face image into the discriminator network of the face swap model, and predicting a first probability that the swapped face image is a non-forged image by using the discriminator network; and
inputting the reference image into the discriminator network of the face swap model, and predicting a second probability that the reference image is a non-forged image by using the discriminator network.

### Claim 7 (depends on 1)

The method according to claim 1, wherein after the swapped face image is obtained, the method further comprises:
extracting a feature from the swapped face image by using the expression recognition network of the face swap model to obtain the expression feature of the swapped face image; and
extracting a feature from the swapped face image by using the face recognition network of the face swap model to obtain the identity feature of the swapped face image,
the expression recognition network and the face recognition network both being pre-trained neural network models.

### Claim 8 (depends on 1)

The method according to claim 1, wherein updating the generator network and the discriminator network based on the image attribute discrimination result of the swapped face image and the image attribute discrimination result of the reference image, the calculated difference between the expression features, and the calculated difference between the identity features comprises:
alternately performing following operations till a training stop condition is satisfied and a trained discriminator network and a trained generator network are obtained:
constructing, when a network parameter of the generator network is fixed, a discrimination loss for the discriminator network based on the first probability that the swapped face image is a non-forged image and the second probability that the reference image is a non-forged image, and updating a network parameter of the discriminator network based on the discrimination loss; and
constructing, when the network parameter of the discriminator network is fixed, a generation loss for the generator network based on the first probability that the swapped face image is a non-forged image, constructing an expression loss based on the difference between the expression feature of the swapped face image and the expression feature of the template image, constructing an identity loss based on the difference between the identity feature of the swapped face image and the identity feature of the source face image, constructing a face swap loss for the generator network based on the generation loss, the expression loss, and the identity loss, and updating the network parameter of the generator network based on the face swap loss.

### Claim 9 (depends on 1)

The method according to claim 1, further comprising:
respectively recognizing facial key points in the template image and facial key points in the swapped face image by using a pre-trained facial key point network to obtain facial key point information of the template image and facial key point information of the swapped face image; and
constructing a key point loss based on a difference between the facial key point information of the template image and the facial key point information of the swapped face image, the key point loss being configured for participating in training for the generator network of the face swap model.

### Claim 10 (depends on 1)

The method according to claim 1, further comprising:
respectively extracting an image feature from the swapped face image and an image feature from the reference image by using a pre-trained feature extraction network to obtain the image feature of the swapped face image and the image feature of the reference image; and
constructing a similarity loss based on a difference between the image feature of the swapped face image and the image feature of the reference image, the similarity loss being configured for participating in the training for the generator network of the face swap model.

### Claim 11 (depends on 1)

The method according to claim 1, further comprising:
constructing a reconstruction loss based on a pixel-level difference between the swapped face image and the reference image, the reconstruction loss being configured for participating in the training for the generator network of the face swap model.

### Claim 12 (depends on 1)

The method according to claim 1, further comprising:
acquiring a to-be-face-swapped video and a source face image comprising a target face;
acquiring, for each video frame of the to-be-face-swapped video, an expression feature of the video frame;
acquiring an identity feature of the source face image comprising the target face;
concatenating the expression feature and the identity feature to obtain a combined feature; and
performing encoding based on the source face image comprising the target face and the video frame by using the trained generator network of the face swap model to obtain an encoding feature required for face swap, performing decoding based on a fused feature obtained by fusing the encoding feature and the combined feature, and outputting a swapped face video in which an object in the video frame is replaced with the target face.

### Claim 13

A computer device, comprising:
one or more processors and a memory containing a computer-executable program that, when being executed, causes the one or more processors to perform:
acquiring a sample triplet, the sample triplet comprising a source face image, a template image, and a reference image;
concatenating an expression feature of the template image and an identity feature of the source face image to obtain a combined feature;
performing encoding based on the source face image and the template image by using a generator network of a face swap model to obtain an encoding feature required for face swap;
fusing the encoding feature and the combined feature to obtain a fused feature;
performing decoding based on the fused feature by using the generator network of the face swap model to obtain a swapped face image;
respectively predicting an image attribute discrimination result of the swapped face image and an image attribute discrimination result of the reference image by using a discriminator network of the face swap model, an image attribute comprising forged image and non-forged image; and
calculating a difference between an expression feature of the swapped face image and the expression feature of the template image, calculating a difference between an identity feature of the swapped face image and an identity feature of the source face image, and updating the generator network and the discriminator network, based on the image attribute discrimination result of the swapped face image and the image attribute discrimination result of the reference image, the calculated difference of the expression features between the swapped face image and the template image, and the calculated difference of the identity features between the swapped face image and the source face image.

### Claim 14 (depends on 13)

The device according to claim 13, wherein the one or more processors are configured to perform:
acquiring a first image and a second image, the first image and the second image corresponding to a same identity attribute and corresponding to different non-identity attributes;
acquiring a third image, the third image and the first image corresponding to different identity attributes;
replacing an object in the second image with an object in the third image to obtain a fourth image; and
constructing the sample triplet by using the first image as the source face image, the fourth image as the template image, and the second image as the reference image.

### Claim 15 (depends on 13)

The device according to claim 13, wherein the one or more processors are configured to perform:
extracting a feature from the template image by using an expression recognition network of the face swap model to obtain the expression feature of the template image; and
extracting a feature from the source face image by using a face recognition network of the face swap model to obtain the identity feature of the source face image,
the expression recognition network and the face recognition network both being pre-trained neural network models.

### Claim 16 (depends on 13)

The device according to claim 13, wherein the one or more processors are configured to perform:
concatenating the source face image and the template image to obtain an input image;
inputting the input image into the face swap model; and
encoding the input image by using the generator network of the face swap model to obtain the encoding feature required for face swap on the template image.

### Claim 17 (depends on 13)

The device according to claim 13, wherein the one or more processors are configured to perform:
calculating a mean value and a standard deviation of the encoding feature, and calculating a mean value and a standard deviation of the combined feature;
normalizing the encoding feature based on the mean value and the standard deviation of the encoding feature to obtain a normalized encoding feature; and
transferring a style of the combined feature to the normalized encoding feature based on the mean value and the standard deviation of the combined feature to obtain the fused feature.

### Claim 18 (depends on 13)

The device according to claim 13, wherein the one or more processors are configured to perform:
inputting the swapped face image into the discriminator network of the face swap model, and predicting a first probability that the swapped face image is a non-forged image by using the discriminator network; and
inputting the reference image into the discriminator network of the face swap model, and predicting a second probability that the reference image is a non-forged image by using the discriminator network.

### Claim 19 (depends on 13)

The device according to claim 13, wherein the one or more processors are configured to perform:
extracting a feature from the swapped face image by using the expression recognition network of the face swap model to obtain the expression feature of the swapped face image; and
extracting a feature from the swapped face image by using the face recognition network of the face swap model to obtain the identity feature of the swapped face image,
the expression recognition network and the face recognition network both being pre-trained neural network models.

### Claim 20

A non-transitory computer-readable storage medium, storing a computer-executable instruction that, when being executed, causes one or more processors to perform:
acquiring a sample triplet, the sample triplet comprising a source face image, a template image, and a reference image;
concatenating an expression feature of the template image and an identity feature of the source face image to obtain a combined feature;
performing encoding based on the source face image and the template image by using a generator network of the face swap model to obtain an encoding feature required for face swap;
fusing the encoding feature and the combined feature to obtain a fused feature;
performing decoding based on the fused feature by using the generator network of the face swap model to obtain a swapped face image;
respectively predicting an image attribute discrimination result of the swapped face image and an image attribute discrimination result of the reference image by using a discriminator network of the face swap model, an image attribute comprising forged image and non-forged image; and
calculating a difference between an expression feature of the swapped face image and the expression feature of the template image, calculating a difference between an identity feature of the swapped face image and an identity feature of the source face image, and updating the generator network and the discriminator network, based on the image attribute discrimination result of the swapped face image and the image attribute discrimination result of the reference image, the calculated difference of the expression features between the swapped face image and the template image, and the calculated difference of the identity features between the swapped face image and the source face image.
