High-Fidelity Image Inpainting with Multimodal Guided GAN Inversion

Libo Zhang, Yongsheng Yu, Jiali Yao, Heng Fan

TL;DR

MMInvertFill bridges the gap between GAN inversion and image inpainting by introducing a novel $\mathcal{F}\&\mathcal{W}+$ latent space that enforces strict consistency between unmasked input regions and generated outputs. By combining a multi-modal guided encoder (integrating RGB, edges, and segmentation) with a dynamic soft-update mean latent module, it achieves state-of-the-art, high-fidelity image completion even for massive holes and out-of-domain images without requiring complex post-processing.

What Problem Does This Paper Address?

GAN inversion leverages the rich, generative priors of well-trained models (like StyleGAN2) to fill in missing image regions with highly realistic textures. However, standard GAN inversion suffers from a fundamental flaw when applied to inpainting: it struggles to respect the "hard constraint" that the unmasked regions of the input and output images must remain exactly identical. This mismatch causes a "gapping" problem—conspicuous color discrepancies and semantic inconsistencies along the mask boundaries.

Furthermore, existing methods typically rely solely on the RGB modality or use predicted structural priors (like predicted edges or segmentation maps) directly to guide the process. Because these predicted priors are often biased or imperfect, they introduce cumulative errors and artifacts into the final output.

Methods

The authors propose MMInvertFill, an encoder-based GAN inversion framework consisting of several key innovations:

  1. Multi-Modality Guided Encoder (MGE): Instead of relying only on RGB, the encoder processes three modalities simultaneously: the masked image, semantic segmentation maps, and edge textures. It features Adaptive Contextual Bottlenecks (ACBs) that dynamically adjust convolutional dilation rates based on the mask shape and image content.
  2. Gated Mask-aware Attention (GMA): To fuse these modalities without introducing noise, the authors use an Auxiliary DeNormalization (ADN) layer and a mask-aware self-attention mechanism. This ensures tokens in masked regions do don't corrupt the features of unmasked regions.
  3. $\mathcal{F}\&\mathcal{W}+$ Latent Space: To solve the gapping problem, the authors introduce skip connections that feed the multi-scale feature maps ($\mathcal{F}$) of the unmasked input directly into the StyleGAN2 generator via element-wise addition, forcing color and structural alignment.
  4. Soft-update Mean Latent (SML): To prevent the encoder from overfitting to the training set's average patterns (which causes blurry or mosaic artifacts far from mask boundaries), the authors introduce a dynamically fluctuating mean latent code during training, smoothing its convergence using a reinforcement learning-inspired moving average.
Fig. 2: A high-level schematic diagram illustrat- ing the full pipeline of the proposed method.

Datasets

The model was extensively evaluated across six challenging benchmarks:

  • CelebA-HQ: 30,000 high-quality face images with 15 merged semantic categories.
  • Places2: Over 10 million real-world scene images across 400 categories (36,500 used for evaluation).
  • OST & CityScapes: Used specifically for multi-modal ablation studies due to their ground-truth edge and segmentation annotations.
  • MetFaces & Scenery: Used to test out-of-domain robustness (zero-shot generalization of the encoder without retraining the GAN generator).

Key Insights and Ideas

  • The "Gapping" Solution via Skip Connections: Traditional GAN inversion treats the generator as a black box fed only by a latent code. By opening up the generator and injecting multi-scale feature maps from the unmasked input via skip connections, the model naturally enforces pixel-level and color consistency without needing complex post-processing like image blending.
  • Unbiased Multi-Modal Interplay: Instead of using predicted structures as a rigid, direct guide (which propagates errors), MMInvertFill jointly learns the interplay between RGB, edges, and segmentation maps within a shared decoder, filtering out redundant and noisy content.
  • Target Network Analogy for Latents: Borrowing the concept of target networks from reinforcement learning, the Soft-update Mean Latent (SML) prevents the encoder from taking a "shortcut" (overfitting to a static mean face/texture), preserving the diversity and crispness of the generated textures.

Key Results

MMInvertFill consistently outperforms state-of-the-art methods (including LaMa, ZITS, MISF, and pSp) across various mask ratios (10% to 90%), showing its greatest strength in massive corruptions (70-90% mask coverage).

  • On Places2 (70-90% mask): The proposed method outperforms the second-best baseline by 2037.5% in P-IDS, 192.2% in U-IDS, and 59.9% in FID, demonstrating a massive leap in generating high-fidelity, human-perceptible realism.
  • Out-of-Domain Generalization: When tested on unseen domains (e.g., applying a CelebA-HQ trained model to historical portraits in MetFaces), MMInvertFill successfully synthesized semantically coherent styles and patches without retraining the underlying GAN generator.

Limitations and Future Work

Despite its strengths, MMInvertFill faces challenges with highly fine-grained details in extreme long-tail distributions. For instance, because the GAN model is fundamentally constrained by its pre-trained latent space, it struggles with non-frontal views (side faces) or rare objects not well-represented in the original GAN training data (e.g., attempting to reconstruct a face within a dataset primarily consisting of mountains and buildings). Future work will likely focus on expanding the flexibility of the pre-trained latent space to handle these highly diverse or out-of-distribution fine-grained structures.

Summary updated

BibTeX
@article{zhang2025high,
  author = {Libo Zhang and Yongsheng Yu and Jiali Yao and Heng Fan},
  title = {{High-Fidelity Image Inpainting with Multimodal Guided GAN Inversion}},
  journal = {Int. J. Comput. Vis.},
  year = {2025},
  doi = {10.1007/s11263-025-02448-w},
}
Figure