TL;DR
Researchers from Peking University have developed a two-stage interactive image inpainting framework that gives users direct control over the restoration process. By combining a novel External Spatial Attention (ESPA) mechanism with semantic guidance, the model allows users to tweak a generated semantic mask to customize the final textures and structures of a corrupted image.
What Problem Does This Paper Address?
Traditional deep learning-based image inpainting models are often "black boxes." They either produce a single, fixed result based on learned priors or generate multiple random solutions. In both cases, the user has little to no control over the specific content generated in the missing regions.
While some "controllable" models exist, they often require users to draw guidance (like edges or masks) from scratch, which is difficult for complex scenes. Furthermore, many two-stage models discard vital color and texture information from the first stage, leading to final results that feel disconnected from the original image context. This paper aims to bridge the gap between automated restoration and user-driven customization.
Methods
The authors propose a two-stage architecture designed for both efficiency and controllability:
- Stage 1: The ESPA Autoencoder. This stage generates a coarse inpainting result and a corresponding semantic mask. The core innovation here is the External Spatial Attention (ESPA) module. Unlike standard self-attention, which has quadratic computational complexity ($O(N^2)$), ESPA uses two external, learnable parameter matrices to model long-range dependencies with linear complexity ($O(N)$). This allows the model to better propagate spatial information from the uncorrupted context into the missing regions without a massive computational hit.
- User Interaction: The coarse semantic mask from Stage 1 serves as a medium. Users can modify this mask (e.g., changing the shape of a nose or the position of a waterfall) using simple drawing tools.
- Stage 2: The Semantic Decoder. This stage takes the reconstructed features from the ESPA autoencoder and the user-customized semantic mask as inputs. It uses Spatially Adaptive Normalization (SPADE) layers to ensure the final high-resolution output respects the user's semantic guidance while preserving the textures and colors identified in the first stage.
Datasets
The model was trained and evaluated on three standard, challenging datasets:
- FFHQ: High-quality human face images.
- Celeba-HQ: Another high-resolution face dataset, used for quantitative comparisons.
- Outdoorscenes: A dataset containing complex natural landscapes (mountains, water, sky) to test the model's ability to handle diverse semantic categories.
Key Insights and Ideas
- Controllability via "Coarse-to-Fine" Semantics: Instead of making users draw from scratch, the model provides a "best guess" mask that the user can then refine. This significantly lowers the barrier for user interaction.
- Feature Preservation: A major "aha" moment is the realization that the second stage shouldn't just look at the mask; it must be conditioned on the encoded features from the first stage. This ensures that the global color palette and local textures remain consistent across the entire image.
- Linear Attention for Inpainting: By applying external attention at the spatial dimension rather than the channel dimension, the authors made long-range context modeling feasible for high-resolution inpainting tasks.
Key Results
The proposed method outperformed several state-of-the-art (SOTA) approaches, including EdgeConnect (EC) and SPG-Net, across both face and landscape datasets.
- Quantitative: On the Celeba-HQ dataset, the model achieved a PSNR of 28.09 and an SSIM of 0.9232, significantly higher than its competitors (e.g., EC at 25.75 PSNR). It also achieved the lowest FID (3.86), indicating higher visual realism.
- Qualitative: The model demonstrates impressive flexibility. As shown in the Outdoorscenes results, changing the semantic mask allows the model to realistically generate different features, such as moving the position of a waterfall or changing the silhouette of a mountain range, while keeping the water and rock textures consistent.
Limitations and Future Work
The authors note that the quality of the final result is still heavily dependent on the autoencoder in Stage 1. If the initial feature reconstruction is poor, the second stage may struggle to produce high-quality textures, even with a perfect semantic mask.
For future work, the team plans to incorporate reference images. This would allow users to not only customize the structure of the inpainting via masks but also specify the style (color and texture) by providing an example image for the model to emulate.
Summary updated