ShapeEditor: A StyleGAN Encoder for Stable and High Fidelity Face Swapping

Shuai Yang, Kai Qiao, Ruoxi Qin, Pengfei Xie, Shuhao Shi, Ningning Liang, Linyuan Wang, Jian Chen, Guoen Hu, Bin YanFrontiers in Neurorobotics 2022

Abstract

With the continuous development of deep-learning technology, ever more advanced face-swapping methods are being proposed. Recently, face-swapping methods based on generative adversarial networks (GANs) have realized many-to-many face exchanges with few samples, which advances the development of this field. However, the images generated by previous GAN-based methods often show instability. The fundamental reason is that the GAN in these frameworks is difficult to converge to the distribution of face space in training completely. To solve this problem, we propose a novel face-swapping method based on a pretrained StyleGAN generator with a stronger ability for high-quality face image generation. The critical issue is how to control StyleGAN to generate swapped images accurately. We design the control strategy of the generator based on the idea of encoding and decoding and propose an encoder called ShapeEditor to complete this task. ShapeEditor is a two-step encoder used to generate a set of coding vectors that integrate the identity and attribute of the input faces. In the first step, we extract the identity vector of the source image and the attribute vector of the target image; in the second step, we map the concatenation of the identity vector and attribute vector onto the potential internal space of StyleGAN. Extensive experiments on the test dataset show that the results of the proposed method are not only superior in clarity and authenticity than other state-of-the-art methods but also sufficiently integrate identity and attribute.

What Problem Does This Paper Address?

Face swapping—the process of transferring a source person's identity onto a target person while maintaining the target's expression, lighting, and pose—is a cornerstone of digital media manipulation. While GAN-based models like FaceShifter and FSGAN have enabled many-to-many swapping, they frequently suffer from visual instability.

Common artifacts include "ghosting," where facial features like eyebrows or noses appear doubled or blurred, and unnatural transitions in lighting. These failures often stem from the model's attempt to learn the entire manifold of human faces from scratch during training.

Figure 1: Examples of abnormal results (ghosting and artifacts) generated by the FaceShifter model.

To address this, the researchers behind ShapeEditor propose using a pretrained StyleGAN generator. By leveraging a model that already "understands" the distribution of high-quality human faces, the task shifts from generation to precise control.

Methods: The ShapeEditor Architecture

The core innovation is the ShapeEditor encoder, a two-step system designed to map source and target information into StyleGAN’s extended latent space ($W+$).

1. ID-ATTR Encoding

The process begins by extracting two distinct sets of information:

  • Identity ($I_{id}$): A pretrained ArcFace network extracts a 512-dimensional identity vector from the source image, capturing the unique features of the individual.
  • Attributes ($I_{attr}$): A custom pyramid-shaped feature extractor captures the target's pose, expression, and lighting at multiple scales. These features are then compressed into attribute vectors via Convolutional Mappers (CM).

2. Latent-space Mapping

The identity and attribute vectors are concatenated and processed through a series of Multilayer Perceptrons (MLPs). These MLPs map the combined data into the $W+$ latent space. Unlike the standard $W$ space, $W+$ consists of 18 different 512-dimensional vectors, providing the "bandwidth" necessary to control fine-grained details and environmental attributes simultaneously.

Key Results and Performance

ShapeEditor was trained on the FFHQ dataset and evaluated using CelebAMask-HQ. It was compared against leading methods including FSGAN and FaceShifter.

  • Visual Fidelity: ShapeEditor produces images with significantly higher clarity, successfully avoiding the ghosting artifacts seen in earlier models. It also handles complex scenarios like facial occlusions (e.g., hands) and glasses more robustly.
  • Quantitative Metrics: The model achieved superior scores in SSIM (Structural Similarity) and PSNR (Peak Signal-to-Noise Ratio), indicating better preservation of the target's structure and overall image quality.
  • Authenticity: In automated forgery detection tests, ShapeEditor had the lowest Forgery Detection Rate (FDR), suggesting its outputs are more difficult for algorithms to distinguish from real photos.
  • Emotional Consistency: The model achieved 75.38% accuracy in transmitting the target's emotional state, outperforming previous StyleGAN-based manipulation methods (65.35%).

Limitations and Future Work

While ShapeEditor represents a significant step forward, two primary limitations remain:

  1. Background Blurring: Because the underlying StyleGAN is optimized for faces, the background of swapped images can occasionally lose sharpness compared to the original target.
  2. Demographic Bias: The model shows some performance variance across different ethnicities, likely due to the demographic distribution of the FFHQ training set.

Future research will focus on integrating image segmentation to isolate the head from the background and training on more diverse datasets to ensure equitable performance across all demographics.

Summary updated

BibTeX
@inproceedings{yang2022shapeeditor,
  author = {Shuai Yang and Kai Qiao and Ruoxi Qin and Pengfei Xie and Shuhao Shi and Ningning Liang and Linyuan Wang and Jian Chen and Guoen Hu and Bin Yan},
  title = {{ShapeEditor: A StyleGAN Encoder for Stable and High Fidelity Face Swapping}},
  booktitle = {Frontiers in Neurorobotics},
  year = {2022},
  doi = {10.3389/fnbot.2021.785808},
}
Figure