Diverse Inpainting and Editing with GAN Inversion

Ahmet Burak Yildirim, Hamza Pehlivan, Bahri Batuhan Bilecen, Aysegul Dundar · DOI

Introduction

Generative Adversarial Networks (GANs), particularly architectures like StyleGAN, have revolutionized image synthesis by providing a structured latent space. In this space, semantic attributes—such as facial expressions, hair color, or lighting—can be manipulated by traversing specific vectors. However, applying these capabilities to real-world images requires GAN Inversion, the process of mapping a physical image back into the GAN's latent representation.

While inversion is well-studied for complete images, performing inversion on corrupted or "erased" images introduces a dual challenge: the model must realistically inpaint missing regions while maintaining the ability to edit the resulting image. This paper proposes a novel two-stage framework designed to achieve high-fidelity, seamless reconstructions that are both editable and diverse.

The Challenges of Inversion and Inpainting

Existing GAN inversion techniques typically struggle with two primary hurdles:

  1. The Fidelity-Editability Trade-off: High-fidelity reconstruction often requires mapping images into "out-of-distribution" regions of the latent space. While this captures fine details, it often breaks the semantic structure, making subsequent edits (like adding a smile) look distorted or unrealistic.
  2. Lack of Diversity in Inpainting: Most inversion methods are deterministic, providing only a single "best guess" for missing data. In reality, a missing portion of an image could be filled in many plausible ways.

Methodology: A Two-Stage Approach

The authors address these issues through a decoupled training pipeline that separates the generation of diverse content from the refinement of visual details.

Stage 1: Gated Mixing for Diversity

To enable multiple plausible outputs for a single erased image, the framework employs a Mixing Network with a gating mechanism. The network takes two inputs:

  • $W^{enc}$: Features extracted from the visible portions of the image.
  • $W^{rand}$: A random latent code sampled to introduce stochasticity.

Unlike simple concatenation, which models often ignore, the authors use a learned sigmoid gate to blend these inputs. This forces the network to incorporate the random noise, ensuring that different random seeds result in meaningfully different inpainting results. To train this effectively, the authors use synthetic data generated by the GAN itself. Because the "ground truth" latent code for a synthetic image is known, the model can be trained to reconstruct the original when given the correct code, while still learning to produce realistic alternatives when given different noise.

Stage 2: High-Fidelity Refinement

While Stage 1 handles the "what" of the inpainting, Stage 2 focuses on the "how" — ensuring the new content blends perfectly with the existing pixels. Standard latent spaces like $W+$ often lack the resolution to capture fine textures, leading to visible seams at the edges of erased areas. The authors introduce skip connections to the $F+$ feature space (higher-resolution maps). This allows the model to pass high-frequency details from the original image directly to the generator, ensuring a seamless transition between the original and inpainted regions.

Experimental Evaluation

The framework was evaluated on the FFHQ (faces), AFHQ Cat, and AFHQ Dog datasets. It was compared against state-of-the-art inversion methods (e.g., pSp, HyperStyle) and specialized inpainting models (e.g., CoModGAN).

  • Realism: On the FFHQ dataset, the model achieved an FID score of 5.92, significantly lower than CoModGAN (7.35) and HyperStyle (7.46), indicating higher image quality.
  • Diversity: The model achieved an LPIPS score of 0.2026, more than double the diversity of CoModGAN (0.0790).
  • Simultaneous Editing: Because the output remains within a structured latent space, users can perform semantic edits on the inpainted image immediately. For instance, a user can fill a missing eye and simultaneously change the subject's hair color or expression using standard latent direction tools like InterfaceGAN.

Conclusion and Future Directions

This research demonstrates that by decoupling diversity and fidelity into a two-stage process and leveraging synthetic training data, it is possible to overcome the traditional trade-offs in GAN inversion. While the current work focuses on $256 \times 256$ resolutions, future iterations could scale to megapixel resolutions or explore more complex masking scenarios where the majority of the context is missing.

Summary updated

BibTeX
@misc{yildirim2023diverse,
  author = {Ahmet Burak Yildirim and Hamza Pehlivan and Bahri Batuhan Bilecen and Aysegul Dundar},
  title = {{Diverse Inpainting and Editing with GAN Inversion}},
  year = {2023},
  eprint = {2307.15033},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.15033},
}
Figure