Transforming the latent space of stylegan for real face editing

Heyi Li, Xinyu Zhang, Jinlong Liu, Yunzhi Bai, Huayan Wang, Klaus Mueller · DOI

TL;DR

This paper introduces W++, a novel latent space for StyleGAN that bridges the gap between reconstruction fidelity and semantic editing quality for real faces. By replacing fully-connected layers in StyleGAN's mapping network with attention-based transformers, they achieve superior performance in both areas while maintaining state-of-the-art generation quality and compatibility with existing editing tools.

What Problem Does This Paper Address?

Generating realistic and editable human faces is a cornerstone of many AI applications. Generative Adversarial Networks (GANs), particularly StyleGAN, have revolutionized image synthesis. However, editing real faces using these models presents a significant challenge. The core issue lies in the trade-off between two crucial aspects:

  1. Reconstruction Quality: How accurately can we represent a given real face within the GAN's latent space?
  2. Editing Quality: How well can we semantically alter attributes (like age, gender, or expression) of the reconstructed face without introducing artifacts or losing identity?

StyleGAN operates with different latent spaces:

  • W space: A more constrained space that offers good semantic control for editing but often results in lower reconstruction quality.
  • W+ space: A more expansive space that allows for better reconstruction but suffers from "ill-posed" edits, where manipulating one attribute can unintentionally alter others or degrade image quality.

This fundamental conflict forces a compromise, making it difficult to achieve both high-fidelity reconstruction and natural semantic editing simultaneously for real-world images.

Methods

The authors propose a novel approach to create a new latent space, W++, by modifying StyleGAN's mapping network. The key innovation is the replacement of the standard fully-connected (FC) layers within the mapping network with attention-based transformer structures.

Here's a breakdown of their method:

  • Transformer Integration: Instead of using FC layers to map an initial latent code (from the Z space) to style codes, they employ a series of 8 transformer blocks. These transformers, inspired by the "Attention is All You Need" architecture, utilize multi-head self-attention mechanisms.
  • W++ Space Creation: This transformer-based mapping network generates a new latent space, W++, which has the same dimensionality as W+ (k x 512, where k is the number of style codes, set to 14 for 256x256 resolution).
  • Benefits of Transformers:
    • Correlation: The self-attention mechanism inherently captures relationships between different style codes, ensuring a degree of correlation among them. This is crucial for maintaining global feature consistency, unlike approaches that use entirely independent mapping networks.
  • Computational Efficiency: While transformers introduce complexity, the authors argue that the overall computational cost for the mapping network increases only about five-fold, which is a minor burden compared to the synthesis network.
  • Structural Similarity: The W++ space maintains structural similarity with W/W+, allowing existing inversion and editing algorithms to be used with minimal modifications.

Datasets

  • FlickrFaces-HQ (FFHQ) dataset: Used for both training and evaluating the proposed model. This is a standard, high-quality dataset for face generation and editing research.

Key Insights and Ideas

  • Transformers as a Bridge: The core insight is that attention-based transformers are well-suited to bridge the W and W+ spaces. Their ability to model long-range dependencies and learn complex relationships between different parts of the latent code allows for a more unified and effective representation.
  • W++: The Best of Both Worlds: The W++ space successfully combines the strengths of W (good editing) and W+ (good reconstruction) by providing a latent representation that is both faithful to the original image and amenable to semantically meaningful edits.
  • Preserving Identity: A critical finding is that W++ significantly improves robustness for long-distance manipulations (e.g., large age transformations or gender transitions), preventing the "distance effect" where edits in W/W+ can lead to identity loss or unwanted attribute changes (like race changing during gender transition).
  • Compatibility is Key: The fact that W++ works seamlessly with existing inversion and editing methods without major overhauls is a significant practical advantage, lowering the barrier to adoption.

Key Results

  • Generation Quality: The modified StyleGAN with W++ maintains state-of-the-art generation quality, with FID scores comparable to the original StyleGANv2 (4.67 vs. 4.69). It also shows a slight improvement in diversity metrics (recall, coverage).
  • Reconstruction Quality:
    • Optimization-based: W++ significantly outperforms W in both perceptual loss and MSE loss. It achieves comparable results to W+, with minor differences in metrics.
  • Learning-based (pSp): W++ shows equivalent superiority to W+ in reconstruction quality, outperforming W.
  • Editing Quality:
    • InterfaceGAN: W++ demonstrates superior robustness for long-distance manipulations (age and gender) compared to W and W+. It avoids issues like identity degradation and unintended attribute changes.
  • cGAN-based Pipeline: W++ enables exceptional attribute disentanglement, ensuring that edits to one attribute (e.g., smile) do not alter irrelevant features.
  • User Study: A user study revealed that participants overwhelmingly preferred W++ over W and W+ for both reconstruction and editing tasks, with high statistical significance. For example, 91.7% found W++ better for reconstruction than W, and 96.3% preferred W++ for aging edits over W+.

Limitations and Future Work

  • Minor Reconstruction Discrepancy: The authors acknowledge that while W++ achieves excellent reconstruction, the inverted image still looks "a little different" from the input real image. This slight dissimilarity can adversely impact editing quality.
  • Future Work: The primary future direction is to close this gap between the inverted image and the original real image. This would further enhance the editing quality by ensuring perfect identity preservation before manipulation.

Summary updated

BibTeX
@misc{li2021transforming,
  author = {Heyi Li and Xinyu Zhang and Jinlong Liu and Yunzhi BAI and Huayan Wang and Klaus Mueller},
  title = {{Transforming the latent space of stylegan for real face editing}},
  year = {2021},
  eprint = {2105.14230},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2105.14230},
}
Figure