High-resolution Face Swapping via Latent Semantics Disentanglement

Yangyang Xu, Bailin Deng, Junle Wang, Yanqing Jing, Jia Pan, Shengfeng He

Introduction

Face swapping—the process of transferring a source identity onto a target face while preserving the target's pose, expression, and environmental lighting—has seen significant progress with the advent of deep learning. However, achieving high-fidelity results at resolutions such as 1024×1024 remains a formidable challenge. Traditional end-to-end models often suffer from information compression, leading to blurry outputs. While recent approaches leverage pre-trained Generative Adversarial Networks (GANs) like StyleGAN to utilize their high-resolution priors, they frequently encounter the issue of "semantic entanglement." In StyleGAN’s latent space, attributes like identity, pose, and lighting are often intertwined. Simple manipulation of latent codes can result in "ghosting" artifacts or a failure to accurately capture the target's environmental context.

This research introduces a novel framework designed to achieve high-resolution face swapping by explicitly disentangling latent semantics. By treating facial attributes as distinct classes—specifically separating "structure" (pose and expression) from "appearance" (lighting and skin tone)—the proposed method produces sharper, more realistic results that maintain both source identity and target context.

Methodology

The core of the proposed approach lies in the strategic manipulation of StyleGAN’s latent space ($W+$) and the integration of multi-scale feature blending.

Latent Semantics Disentanglement

The researchers exploit the hierarchical nature of StyleGAN, where shallow layers typically control coarse structural features and deeper layers manage fine-grained appearance details. The framework separates the swapping process into two distinct pipelines:

  1. Landmark-Driven Structure Transfer: Rather than directly swapping latent codes, which can lead to identity loss, the model utilizes a Landmark Encoder. This encoder identifies a specific "direction" in the latent space that corresponds to the structural difference between the source and target. By applying this directional delta to the source’s latent code, the model adjusts the source identity to match the target’s pose and expression without compromising the underlying facial features.
  2. Appearance Reuse: To ensure the swapped face matches the target’s lighting and skin tone, the model directly extracts latent codes from the target's deeper layers. These are then integrated into the newly generated "swapped" latent code, ensuring seamless environmental consistency.

Multi-scale Background Blending

A common artifact in face swapping is the "pasted-on" look, where the boundary between the generated face and the original background is visible. To mitigate this, the authors implement a dedicated Target Encoder and Decoder. This module extracts features from the original target image and blends them with the GAN-generated features across multiple resolutions. This multi-scale approach ensures that the transition between the swapped face and the original background is smooth and preserves details like hair and skin texture at the boundaries.

Temporal Consistency in Video

Extending high-resolution swapping to video introduces the challenge of temporal flickering. The framework addresses this through two specific constraints:

  • Code Trajectory Constraint: This ensures that the evolution of latent codes over time follows the motion trajectory of the target.
  • Flow Trajectory Constraint: By utilizing optical flow, the model enforces pixel-level smoothness across consecutive frames, resulting in stable and flicker-free video output.

Experimental Evaluation

The model was trained and evaluated using several high-quality datasets, including CelebA-HQ (30,000 images at 1024×1024 resolution) and FFHQ (used for pre-training the StyleGAN2 generator). For video evaluation, the researchers used FaceForensics++, a benchmark of 1,000 YouTube videos, to assess consistency and compare against existing lower-resolution baselines.

Quantitative and Qualitative Results

The proposed method demonstrates a clear advantage over previous state-of-the-art models, such as MegaFS. In quantitative evaluations on CelebA-HQ, the model achieved a significantly higher ID Similarity score (0.5688 vs. 0.5214) and a lower Fréchet Inception Distance (FID) (9.987 vs. 11.645). These metrics indicate superior identity preservation and higher overall image realism, respectively.

Qualitatively, the results are noticeably sharper. The disentanglement strategy allows the model to handle extreme differences in skin tone and complex lighting conditions that often cause artifacts in other models. Furthermore, the temporal constraints make this the first viable solution for high-resolution video face swapping, effectively eliminating the "jitter" common in frame-by-frame processing.

Discussion and Limitations

While the framework represents a significant step forward, it is not without limitations. The quality of the final swap is heavily dependent on the "GAN inversion" process; if the initial encoder (such as pSp) fails to accurately map the source or target face into the latent space, the resulting swap will inherit those inaccuracies. Additionally, the current model transfers appearance attributes globally. Future work could explore "fine-grained" appearance control, such as preserving the source's makeup while adopting the target's lighting.

Finally, the authors acknowledge the ethical implications of high-resolution face swapping technology. While it poses risks regarding deepfakes, they argue that the creation of high-quality, high-resolution results is essential for developing more robust forgery detection systems.

Summary updated

BibTeX
@inproceedings{xu2022high,
  author = {Yangyang Xu and Bailin Deng and Junle Wang and Yanqing Jing and Jia Pan and Shengfeng He},
  title = {{High-resolution Face Swapping via Latent Semantics Disentanglement}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2022},
  doi = {10.1109/cvpr52688.2022.00749},
}
Figure