TL;DR
Traditional image inpainting methods struggle with irregular, user-drawn "free-form" masks because standard convolutions treat masked and unmasked pixels identically. This paper introduces Gated Convolution, a technique that learns a dynamic, channel-wise feature selection mechanism to seamlessly blend filled regions. Combined with a patch-based GAN loss (SN-PatchGAN), this approach enables high-quality automatic hole-filling and interactive, sketch-guided image editing.
What Problem Does This Paper Address?
Most deep learning-based image inpainting models are designed to fill in clean, rectangular holes. However, real-world applications—like removing a distracting object or erasing a watermark—require handling arbitrary, irregular shapes (free-form masks).
Standard vanilla convolutions apply the same filter weights across the entire image, treating missing pixels the same as valid ones. This leads to visual artifacts like color discrepancy, blurriness, and harsh edges around the edited zones. While recent work introduced Partial Convolutions (PConv) to mask out invalid pixels using hardcoded rules, PConv has significant limitations:
- It treats all channels identically using a single binary mask.
- The mask values progressively turn to all ones in deeper layers, losing the context of where the original hole was.
- It cannot naturally incorporate user guidance, such as sparse sketches, because it's unclear whether sketch pixels should be treated as "valid" or "invalid" during the rule-based mask update.
Methods
The authors propose a two-stage coarse-to-fine encoder-decoder architecture that replaces standard convolutions with two novel components:
1. Gated Convolution (GatedConv)
Instead of relying on hardcoded, binary mask updates, Gated Convolution learns a soft, dynamic gating mechanism directly from the data for every channel and spatial location.
For an input feature $I$, the layer splits the operation into two parallel convolutions: one to compute the features, and one to compute the gating intensities: $$\text{Gating}_{y,x} = \sum \sum W_g \cdot I$$ $$\text{Feature}_{y,x} = \sum \sum W_f \cdot I$$ $$\text{Output}_{y,x} = \phi(\text{Feature}_{y,x}) \odot \sigma(\text{Gating}_{y,x})$$
Where $\sigma$ is the sigmoid function (producing gating values between 0 and 1), $\phi$ is the activation function, and $\odot$ represents element-wise multiplication. This allows the network to automatically decide which features to retain or suppress based on context.
2. SN-PatchGAN
Because free-form masks can appear anywhere and in any shape, traditional global and local GAN discriminators (which require a single bounding box around the hole) fail. The authors introduce SN-PatchGAN, a discriminator that operates on dense image patches. By applying Spectral Normalization to stabilize GAN training, it evaluates the realism of many local patches across different locations and semantics simultaneously.
3. User-Guided Extension
The architecture easily scales to interactive editing by adding an optional sketch channel, resulting in a 5-channel input (RGB + Mask + Sketch).
Datasets
The system was trained and evaluated on two standard large-scale image benchmarks:
- Places2: Natural scenes, used to test the model's ability to reconstruct complex backgrounds and textures.
- CelebA-HQ: High-quality face images, used to evaluate semantic consistency and fine detail generation (like eyes, hair, and skin).
Key Insights and Ideas
- Soft Gating > Hard Rules: The core "aha moment" is that the network performs much better when it learns how to mask itself. Visualizing the intermediate gating values revealed that different channels learn to focus on different aspects—some highlight the mask boundaries, others focus on user sketches, and some even perform implicit semantic segmentation.
- No Need for a Global Discriminator: Because the receptive field of the deep patch discriminator is large enough to cover the entire input image, a separate global discriminator is redundant. This significantly simplifies the GAN architecture for irregular mask generation.
- Simplified Loss Functions: Unlike competing methods that require up to six different hyperparameter-tuned loss terms, this framework achieves state-of-the-art results using just a simple 1:1 combination of pixel-wise $\ell_1$ reconstruction loss and the SN-PatchGAN hinge loss.
Key Results
Quantitative Performance
Evaluated on the Places2 validation set, the proposed method outperformed traditional patch-matching and deep learning baselines in both $\ell_1$ and $\ell_2$ error metrics:
| Metric (Free-Form Mask) | PatchMatch | Global&Local | ContextAttention | PartialConv* | Ours |
|---|---|---|---|---|---|
| $\ell_1$ Error | 11.3% | 21.6% | 17.2% | 10.4% | 9.1% |
| $\ell_2$ Error | 2.4% | 7.1% | 4.7% | 1.9% | 1.6% |
*Authors' re-implementation within the same framework.
Qualitative & User Study
Qualitatively, GatedConv eliminates the color discrepancies and boundary artifacts common in vanilla convolutions. In user-guided tasks, the model faithfully follows sparse user sketches to generate realistic structures (e.g., completing a face or modifying a landscape layout).
In a blind user study with 104 participants comparing the proposed model against the official PartialConv model, 79.4% of users preferred the results generated by GatedConv.
Limitations and Future Work
The authors do not explicitly detail failure modes or limitations in the text. However, they note that because image hole-filling is an underdetermined problem with many plausible solutions, extremely large masked areas can remain ambiguous. Future work is implied in expanding interactive controls so users can better guide the generative process when filling highly complex or massive missing regions.
Summary updated