Deepfake AI Face Swap

What is it? How does it work?

John Negoita
6 min readJan 4, 2024
Deepfake AI Face Swap

Have you ever wondered how some apps can swap your face with someone else’s? This is called face swapping, and it is a fun and creative way to make new images.

But how does it work?

How can a computer program change your face without making it look weird or fake?

In this article, we will explain the main idea behind a new method for face swapping, developed by researchers from Lancaster University. This method can produce high-quality and realistic face swaps, even when the source and target faces are very different.

Deepfake is a term that refers to the use of deep learning methods, such as generative adversarial networks (GANs), to synthesize realistic images or videos of human faces or bodies.

The method mentioned proposes a novel framework for high-fidelity face swapping using style blending, which leverages the style code of StyleGAN to extract and blend facial attributes in the latent space.

Challenges in Face Swapping

The main challenge of face swapping is to transfer the identity of one face to another, while keeping the other details, such as the expression, the pose, the lighting, and the background. For example, if you want to swap your face with a celebrity, you want to keep your smile, your angle, and your surroundings, but change your facial features to match the celebrity’s.

Deepfake AI Swap

Facial Landmark Alignment is a way of finding and marking some special points on a face, such as the eyes, nose, mouth, and chin. These points can help us understand the shape and position of the face better. For example, we can use these points to make sure the face is not tilted or turned too much, or to change the face to look like someone else’s face. Facial Landmark Alignment is useful for many things, such as making funny pictures, recognizing faces, or creating animations.

Generative Adversarial Networks (GANs)

For this particular face swap method, the researchers used a special type of artificial intelligence model called a generative adversarial network (GAN). A GAN consists of two parts: a generator and a discriminator. The generator tries to create new images that look real, and the discriminator tries to tell apart real images from fake ones. By competing with each other, the generator learns to make better and better images.

Generative Adversarial Networks (GANs)

The researchers used a GAN that can generate realistic faces based on a code that represents the style of the face.

Style Code and its Role

The style code or the is a set of numbers that capture the essential features of a face, such as the shape, the color, the texture, and so on. By changing the style code, the GAN can create different faces with different styles.

Facial attributes encoder

The style code in this context is derived through the use of an encoder, specifically a StyleGAN-based facial attributes encoder. An encoder, in the realm of neural networks, is a component responsible for extracting essential features from input data. In the case of face swapping, this encoder analyzes facial attributes from the source and target faces and encapsulates them into a latent style code. The StyleGAN-based approach ensures that the encoder operates within the framework of a Generative Adversarial Network designed for generating realistic faces. By employing this encoder, the researchers aim to capture the critical elements of facial appearance, including shape, color, texture, and other significant features. The resulting style code becomes a numerical representation that holds the key information necessary for successful face swapping, allowing the subsequent manipulation of facial characteristics while preserving other details like expression, pose, lighting, and background.

The key idea of the new method is to blend the style codes of the source and target faces, using a technique called style blending. Style blending is a way of mixing the style codes in a smart way, so that the resulting code contains the identity information from the source face, and the other information from the target face. For example, if you want to swap your face with a celebrity, the style blending will take the style code of your face, and replace the parts that are related to the identity with the parts from the celebrity’s style code. The rest of the code will remain the same, so that the expression, the pose, the lighting, and the background are preserved.

Style Blending Module

The style blending is done using a module called SBM, which stands for style blending module. The SBM uses a mechanism called attention, which allows it to focus on the relevant parts of the style codes, and ignore the irrelevant parts. The SBM also uses some constraints, such as facial landmark alignment and dual swap consistency, to make sure that the face swap is accurate and smooth.

Style Blending Module

After the style blending, the new style code is fed to the GAN, which generates the final image. The GAN also uses some tricks, such as injecting noise and recycling features, to make the image more realistic and detailed.

The result is a high-quality and realistic face swap, that can handle different faces, expressions, poses, and backgrounds. The researchers tested their method on a large dataset of face images, and compared it with other methods. They found that their method can produce better face swaps, with fewer artifacts and more similarity to the source and target faces.

In Conclusion

To summarize, the new method for face swapping uses a GAN that can generate realistic faces based on a style code. The method blends the style codes of the source and target faces, using a SBM that uses attention and constraints. The method can produce high-quality and realistic face swaps, even when the source and target faces are very different.

A real life example of face swapping is the app MockoFun face swap, which allows you to swap your face with celebrities, movie characters, or cartoons.

You can use this app to create funny and creative images, and share them with your friends. Face swapping can also be used for entertainment, education, or privacy purposes. However, face swapping can also be misused for malicious or deceptive purposes, such as spreading fake news, impersonating someone, or violating someone’s rights. Therefore, it is important to use face swapping responsibly, and to respect the ethics and laws of face synthesis.

--

--