ShapeEditer: a StyleGAN Encoder for Face Swapping

Shuai Yang, Kai Qiao · DOI

Abstract

In this paper, we propose a novel encoder, called ShapeEditor, for high-resolution, realistic and high-fidelity face exchange. First of all, in order to ensure sufficient clarity and authenticity, our key idea is to use an advanced pretrained high-quality random face image generator, i.e. StyleGAN, as backbone. Secondly, we design ShapeEditor, a two-step encoder, to make the swapped face 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 respectively; in the second step, we map the concatenation of identity vector and attribute vector into the $\mathcal{W+}$ potential space. In addition, for learning to map into the latent space of StyleGAN, we propose a set of self-supervised loss functions with which the training data do not need to be labeled manually. Extensive experiments on the test dataset show that the results of our method not only have a great advantage in clarity and authenticity than other state-of-the-art methods, but also reflect the sufficient integration of identity and attribute.

Introduction

Face swapping—the process of transferring a source identity onto a target face while maintaining the target's expressions, pose, and environmental lighting—is a central challenge in computer vision. Despite significant progress, existing models often struggle with a "fidelity-resolution" trade-off. Many GAN-based approaches are limited to low-resolution outputs (e.g., 256x256) and suffer from artifacts like "eye ghosting" or unnatural transitions. While 3D-based methods handle geometry well, they often lack fine-grained texture realism.

ShapeEditer addresses these issues by leveraging the rich generative priors of a pretrained StyleGAN model. By treating face swapping as a navigation task within StyleGAN’s latent space, the framework produces high-fidelity, 1024x1024 resolution results that preserve complex attributes and identity features.

Methodology

The core of the framework is the ShapeEditer encoder, designed to map source and target information into the $\mathcal{W+}$ latent space of StyleGAN. The process is divided into two primary stages:

  1. Identity and Attribute Extraction: The model extracts a robust identity vector ($I_{id}$) from the source image using a pretrained ArcFace network. Simultaneously, it extracts attribute features ($I_{attr}$), such as pose and expression, from the target image using a ResNet-50 backbone coupled with Convolutional Mappers (CM).
  2. Latent Space Mapping: These vectors are concatenated and processed by a Multilayer Perceptron (MLP) that maps the combined data into the 18x512-dimensional $\mathcal{W+}$ space. This specific space is chosen for its superior balance between editability and reconstruction accuracy.

To train the network without ground-truth swapped images, the authors utilize a self-supervised loss strategy. This includes Identity Loss (via ArcFace), Attribute Loss (spatial feature matching), and a Reconstruction Loss that forces the model to perfectly recreate an image when the source and target are identical.

Key Results

ShapeEditer was trained on the FFHQ dataset and evaluated using CelebAMask-HQ. Compared to previous state-of-the-art methods like FSGAN and FaceShifter, ShapeEditer offers several advantages:

  • High Resolution: Native support for 1024x1024 resolution, significantly higher than the 256x256 standard of many competitors.
  • Robustness: The model maintains high fidelity even under challenging conditions, such as extreme lighting or partial facial occlusions.
  • Semantic Integrity: The system successfully preserves the target's hairstyle and background, avoiding the "generic head" problem seen in other StyleGAN-based inversion methods.
Qualitative face swapping results showing the integration of source identity and target attributes.

Discussion and Limitations

The primary innovation of ShapeEditer lies in using StyleGAN as a prior rather than just a generator. By utilizing ArcFace for identity recognition, the model prioritizes structural features that define a person's appearance over transient environmental factors.

However, some limitations remain. The quality of the swap is inherently capped by the diversity of the pretrained StyleGAN backbone; if the backbone has not encountered specific facial types or accessories, the encoder may struggle. Additionally, the accuracy of the identity transfer depends on the MLP's ability to find the precise coordinates in the $\mathcal{W+}$ space, which remains a complex optimization challenge. Future work may focus on improving the inference speed and the precision of the latent vector generation.

Summary updated

BibTeX
@misc{yang2021shapeediter,
  author = {Shuai Yang and Kai Qiao},
  title = {{ShapeEditer: a StyleGAN Encoder for Face Swapping}},
  year = {2021},
  eprint = {2106.13984},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2106.13984},
}
Figure