NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

In-Domain GAN Inversion for Faithful Reconstruction and Editability

Jiapeng Zhu, Yujun Shen, Yinghao Xu, Deli Zhao, Qifeng Chen, Bolei Zhou

TL;DR

This paper introduces IDInvert, a novel GAN inversion framework that ensures real images are not just reconstructed pixel-perfectly, but remain "editable." By using a domain-guided encoder and a domain-regularized optimizer, the authors keep inverted latent codes within the GAN's native semantic space, preventing the common trade-off where high-fidelity reconstruction destroys the ability to manipulate image attributes.

What Problem Does This Paper Address?

Generative Adversarial Networks (GANs) are famous for creating realistic faces or landscapes from random "latent codes." Because GANs spontaneously learn to organize these codes semantically (e.g., one direction in the latent space might control "age," another "lighting"), we can easily edit synthetic images.

However, applying these edits to real images requires "GAN Inversion"—finding the specific latent code that produces a given real-world photo. The challenge is that most inversion methods focus purely on pixel-level reconstruction. While they might produce a code that looks like the target image, that code often ends up in a "no-man's-land" of the latent space where the GAN’s learned editing rules no longer apply. The result? You can reconstruct the face, but as soon as you try to make it smile, the image falls apart into artifacts.

Methods

The authors propose a two-stage approach called In-Domain GAN Inversion (IDInvert):

  1. Domain-Guided Encoder: Unlike traditional encoders trained on synthetic images to predict latent codes, this encoder is trained on real images. It uses a fixed generator and a discriminator to ensure that the codes it produces always land within the "native" latent distribution of the GAN. This provides a semantically meaningful starting point.
  2. Domain-Regularized Optimizer: Optimization is usually used to fine-tune the latent code for better pixel accuracy. IDInvert adds a "domain regularizer" to this process. It uses the previously trained encoder to pull the latent code back toward the semantic domain whenever the optimization tries to "overfit" to pixels at the expense of semantics.
  3. StyleGAN2 Integration: For StyleGAN2, the authors found that adding the average latent code ($\bar{w}$) as an initial bias significantly stabilized training and improved the alignment between the encoder's output and the GAN's internal knowledge.

Datasets

The researchers evaluated their method across several high-resolution datasets:

  • FFHQ: 70,000 high-quality face images.
  • LSUN: Specifically the Tower, Church, and Bedroom sub-categories to demonstrate that the method works for both objects and complex scenes.
  • CelebA: Used for attribute labels to validate the "editability" of the inverted codes.

Key Insights and Ideas

  • The "In-Domain" Philosophy: The core "aha moment" is that reconstruction and editability are often at odds. If you give the optimizer too much freedom, it will find a code that matches every pixel but ignores the "logic" of the GAN. By constraining the code to the "In-Domain" space, you sacrifice a tiny bit of pixel-perfection for massive gains in usability.
  • The Starting Point Matters: The paper demonstrates that a good encoder isn't just a speed boost; it provides an "inductive bias." Starting from a semantically correct point makes it much harder for the optimizer to wander into regions of the latent space that produce garbage results during editing.
  • The Trade-off of Space: The authors explored enlarging the inversion space (e.g., using $W+$ or noise maps). They found a clear rule: the more parameters you use to reconstruct the image, the more you "dilute" the semantics. Using all the noise maps in a GAN allows for near-perfect reconstruction but makes the image almost impossible to edit.

Key Results

  • Superior Editability: In facial attribute manipulation (adding glasses, changing age), IDInvert significantly outperformed the state-of-the-art Image2StyleGAN. While Image2StyleGAN often introduced blurriness or changed the person's identity during edits, IDInvert maintained high fidelity.
  • Quantitative Gains: IDInvert achieved much lower FID (Fréchet Inception Distance) and SWD (Sliced Wasserstein Distance) scores for image interpolation and manipulation, indicating that the generated transitions are much more realistic.
  • Efficiency: The framework is significantly faster than pure optimization methods. Inverting an image takes about 8 seconds on a 2080 Ti GPU, compared to nearly 5 minutes for optimization-heavy baselines.
  • Semantic Diffusion: The authors showcased a "Semantic Diffusion" task, where a part of one image (like a face) is seamlessly blended into another context while maintaining the target's identity and the context's style.

Limitations and Future Work

  • Out-of-Distribution Images: The method relies on the pre-trained GAN's knowledge. If you try to invert an image that is vastly different from the training set (e.g., a cat image using a face-trained GAN), the "in-domain" constraint will force the result to look like a human face, failing the reconstruction.
  • Fine Details: While the method is excellent at maintaining identity, extremely fine stochastic details (like specific strands of hair or intricate jewelry) can still be lost because they aren't fully captured by the semantic latent space.
  • Future Directions: The authors suggest that exploring how to better balance the reconstruction-editability trade-off without manual hyperparameter tuning remains an open and promising area of research.

Summary updated

BibTeX
@article{zhu2024domain,
  author = {Jiapeng Zhu and Yujun Shen and Yinghao Xu and Deli Zhao and Qifeng Chen and Bolei Zhou},
  title = {{In-Domain GAN Inversion for Faithful Reconstruction and Editability}},
  journal = {IEEE Trans. Pattern Anal. Mach. Intell.},
  year = {2024},
  url = {https://openreview.net/forum?id=272dXqiv9K},
}
Figure