Encoding in Style: a StyleGAN Encoder for Image-to-Image Translation

Elad Richardson, Yuval Alaluf, Or Patashnik, Yotam Nitzan, Yaniv Azar, Stav Shapiro, Daniel Cohen-Or · DOI

Abstract

The pixel2style2pixel (pSp) framework introduces a novel encoder architecture designed to map real images directly into the $W+$ latent space of a pre-trained StyleGAN. By reframing image-to-image translation as an encoding task, pSp facilitates diverse applications such as facial frontalization, super-resolution, and sketch-to-image synthesis. Unlike previous methods, pSp avoids task-specific architectures and costly per-image optimization, providing a fast and accurate solution for high-quality image translation.

Introduction

Traditional image-to-image (I2I) translation frameworks, such as pix2pix, typically rely on pixel-to-pixel correspondence. This reliance creates a "locality bias," making it difficult for models to handle tasks where input and output are spatially misaligned—for example, rotating a profile view of a face to a frontal view.

While StyleGAN is capable of generating hyper-realistic images, "inverting" a real image into its latent code remains a challenge. Existing inversion methods are often either too slow (requiring minutes of optimization) or too inaccurate to capture fine details. The pSp framework addresses these issues with a generic, fast, and accurate encoder that leverages the generative power of a fixed StyleGAN.

The pSp Framework

The core of the pSp architecture is an encoder built on a Feature Pyramid Network (FPN) backbone. Unlike standard encoders that produce a single latent vector, pSp extracts feature maps at three hierarchical scales: coarse, medium, and fine.

Hierarchical Encoding and map2style

Small convolutional networks, termed map2style blocks, transform these multi-scale feature maps into 18 distinct style vectors within the $W+$ latent space. These vectors are then fed directly into the corresponding layers of a pre-trained StyleGAN generator. This hierarchical approach allows the model to capture both global structure and fine-grained details.

A segmentation map used as input for image-to-image translation.

Training Objectives

The model is trained using a multi-faceted loss function:

  • Pixel-wise and Perceptual Similarity: $L_2$ and LPIPS losses ensure the output resembles the input.
  • Identity Preservation: A pre-trained ArcFace network ($L_{ID}$) ensures facial identity is maintained.
  • Regularization: $L_{reg}$ keeps latent vectors near the average style to maintain image quality.

Experimental Results

The pSp framework was evaluated across multiple domains, including CelebA-HQ, FFHQ, and AFHQ (cats and dogs).

Performance and Versatility

pSp performs inversion in approximately 0.1 seconds, a significant improvement over optimization-based methods. In perceptual studies, pSp was preferred over state-of-the-art models like SPADE and pix2pixHD by over 93% of users for tasks such as sketch-to-image synthesis.

Overview of pSp performance across various tasks including frontalization, sketch-to-image, and super-resolution.

Quantitative results further highlight pSp's superiority in identity preservation, achieving a similarity score of 0.56, compared to 0.06 for ALAE and 0.18 for IDInvert. The architecture's versatility is demonstrated by its success in tasks ranging from 32x super-resolution to facial frontalization and inpainting, all using the same underlying structure.

Discussion and Conclusion

By mapping images to styles rather than pixels, pSp operates on a global level, effectively solving tasks without strict spatial correspondence. Because it utilizes a pre-trained StyleGAN, it eliminates the need for unstable adversarial training during the translation phase.

However, the framework is limited by the expressiveness of the underlying generator; it cannot produce features (like specific accessories or extreme expressions) that the StyleGAN has not encountered. Future work will focus on improving the preservation of fine-grained details and extending the framework to more diverse, non-facial domains.

Summary updated

BibTeX
@inproceedings{richardson2020encoding,
  author = {Elad Richardson and Yuval Alaluf and Or Patashnik and Yotam Nitzan and Yaniv Azar and Stav Shapiro and Daniel Cohen-Or},
  title = {{Encoding in Style: a StyleGAN Encoder for Image-to-Image Translation}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2020},
  doi = {10.1109/cvpr46437.2021.00232},
}
Figure