Introduction
Image inpainting—the process of reconstructing missing or corrupted parts of an image—is a fundamental task in computer vision with applications ranging from photo editing to object removal. While traditional methods excel at filling simple textures, they often struggle with complex semantic structures like human faces or natural landscapes. Modern deep learning approaches typically employ an encoder-decoder architecture; however, these models frequently fail when faced with "free-form" masks—irregular, unpredictable holes that can appear anywhere in an image. This paper introduces a novel two-stage approach that leverages contrastive learning and a Dual Attention Fusion (DAF) module to achieve state-of-the-art results in free-form inpainting.
The Challenge of Free-Form Masks
Traditional inpainting models often assume regular, rectangular masks. When these models encounter irregular, brush-stroke-like holes, the encoder often fails to learn a robust representation of the underlying scene. This leads to common artifacts such as color mismatches, blurry patches, and disjointed boundaries where the synthesized content meets the original pixels.
Methodology
The authors propose a two-stage paradigm designed to enhance both the semantic understanding of the encoder and the reconstructive precision of the decoder.
1. Self-Supervised Siamese Inference Network
To improve encoder robustness, the framework utilizes Contrastive Learning based on the MoCo (Momentum Contrast) framework. During training, two identical encoders are used in a Siamese configuration. One encoder receives an image with one mask (the "query"), while the other receives the same image with a different mask (the "key"). By training the network to recognize that these different masked versions represent the same underlying image, the encoder learns to capture high-level semantics while ignoring the specific shape of the missing regions.
2. Dual Attention Fusion (DAF) Module
The DAF module is a "plug-and-play" component integrated into the decoder to ensure seamless blending. It operates through two mechanisms:
- Channel Attention: Recalibrates feature maps to prioritize the most relevant information for reconstruction.
- Spatial Attention: Calculates the similarity between the synthesized content and the known surrounding regions. This ensures a smooth transition, effectively filling the hole from the "outside-in" by propagating reliable textures into the masked area.
3. Multi-Scale Decoding
By placing DAF modules at multiple layers of the decoder, the network progressively refines the image from low to high resolution. The training process is guided by a comprehensive loss function comprising Reconstruction ($L_1$), Perceptual (VGG-16 based), Style (Gram matrices), Total Variation, and Adversarial (GAN) losses.
Experimental Results
The model was rigorously evaluated on four diverse benchmarks: CelebA-HQ (faces), Places2 (natural scenes), Paris Street View, and ImageNet.
Quantitative Performance
On the Places2 dataset, the proposed method outperformed existing heavyweights like Partial Convolutions (PConv) and Contextual Attention (CA). Key metrics included:
- PSNR (Peak Signal-to-Noise Ratio): 27.54 (indicating superior reconstruction quality).
- SSIM (Structural Similarity): 0.9350 (indicating excellent structural preservation).
- FID (Fréchet Inception Distance): 9.15 (indicating high visual realism).
Qualitative Performance
Visual results demonstrate that the method produces sharper textures and more consistent color profiles than previous approaches. Even with large, complex masks on human faces or intricate animal fur, the model's outputs are often indistinguishable from the ground truth.
Conclusion and Future Work
By combining contrastive learning for semantic robustness with dual attention for spatial coherence, this research sets a new benchmark for free-form image inpainting. While the computational cost of Siamese training and multi-scale attention is higher than simpler models, the gains in visual quality are significant. Future research may explore extending the DAF module's spatial dependency logic to handle temporal dependencies in video inpainting, as well as addressing the "final frontier" of extremely large holes that require deep expressive semantic knowledge.
Summary updated