TL;DR
GradPaint is a training-free inpainting algorithm that steers pre-trained diffusion models toward global coherence using gradient guidance. By optimizing intermediate noise maps with a custom harmonization loss, it eliminates the "copy-paste" artifacts common in zero-shot inpainting and outperforms both unsupervised and fully supervised state-of-the-art methods.
What Problem Does This Paper Address?
Image inpainting—filling in missing regions of an image—is a classic computer vision challenge. While Denoising Diffusion Probabilistic Models (DDPMs) excel at generating realistic images, adapting them for inpainting without re-training is difficult.
Existing zero-shot methods typically rely on a "copy-and-paste" strategy: at each denoising step, they replace the known regions of the noisy latent with noised versions of the original image. However, because diffusion models are heavily influenced by their initial random noise, they often fail to harmonize the generated content inside the mask with the existing context outside it. This leads to visible seams, mismatched textures, and a lack of global structural coherence.
Methods
GradPaint introduces a gradient-guided update to the standard DDPM denoising cycle. Instead of just replacing pixels, it treats the denoising process as an optimization problem.
- Denoised Estimation: At each step $t$, the model predicts the final clean image $\hat{x}_0$.
- Dual-Component Loss: The authors define a total loss $\mathcal{L}$ consisting of:
- Masked MSE Loss: Ensures the generated regions outside the mask match the original input image.
- Alignment Loss: A novel term that measures the smoothness of transitions across the mask boundaries using normalized image gradients. This encourages the model to "blend" the new content naturally into the old.
- Gradient Update: The algorithm backpropagates this loss through the diffusion model itself to calculate the gradient with respect to the current noisy state $x_t$. It then performs a single step of gradient descent to update $x_t$ before moving to the next denoising step.
The method is training-free, meaning it can be applied to any off-the-shelf diffusion model (including latent models like Stable Diffusion) without further fine-tuning.
Datasets
The researchers evaluated GradPaint across five diverse datasets to prove its generalizability:
- FFHQ & CelebA-HQ: High-resolution human faces.
- ImageNet: A wide variety of objects and categories.
- Places2: Complex outdoor and indoor scenes.
- COCO: Used for text-conditioned inpainting experiments with Stable Diffusion.
Evaluation focused on "thick masks," which are more challenging as they remove significant portions of the image.
Key Insights and Ideas
- Early Intervention Matters: The authors observed that the most realistic results occur when the generated content is harmonized with the context from the very beginning of the denoising process. Standard methods wait too long to integrate context, at which point it's "too late" to fix misalignments.
- Soft Steering vs. Hard Constraints: Simply replacing pixels (a hard constraint) creates discontinuities. Gradient guidance acts as a "soft" steering mechanism that allows the model's internal priors to reconcile with the external image constraints.
- Mask Agnosticism: Because it is training-free, GradPaint is agnostic to mask distributions. Supervised models like LaMa often fail when presented with masks that differ from their training data (e.g., random pixel masks), whereas GradPaint remains robust.
Key Results
- State-of-the-Art Realism: On the FFHQ dataset, GradPaint achieved an FID score of 5.65, significantly better than supervised models like LaMa (6.27) and Palette (7.28), as well as other training-free methods like RePaint (9.09).
- Efficiency: While GradPaint is roughly 3x slower than simple gradient-free baselines due to backpropagation, it is much faster than the popular RePaint algorithm (66 seconds vs. 313 seconds per image).
- GradPaint-Fast: The authors found that stopping the gradient guidance halfway through the process (at 50% steps) retains most of the quality while reducing computation time by 33%.
- Latent Diffusion: When applied to Stable Diffusion (GradPaint-Latent), the inference time drops to just 7.2 seconds per image while maintaining high quality.
Limitations and Future Work
- Computational Cost: Even with optimizations, the requirement for backpropagation at every step makes it more resource-intensive than simple feed-forward inpainting.
- Contextual Bias: The alignment loss can occasionally over-index on background colors. For example, a pink background might cause the model to generate a pinkish tint on an inpainted object (like a dog's nose).
- Latent Space Constraints: The alignment loss, which relies on pixel-level gradients, does not currently work in the latent space of models like Stable Diffusion. For these models, the authors only used the Masked MSE loss. Future work could involve developing a latent-friendly version of the alignment loss.
Summary updated