Abstract
Recent deep generative inpainting methods use attention layers to allow the generator to explicitly borrow feature patches from the known region to complete a missing region. Due to the lack of supervision signals for the correspondence between missing regions and known regions, it may fail to find proper reference features, which often leads to artifacts in the results. Also, it computes pair-wise similarity across the entire feature map during inference bringing a significant computational overhead. To address this issue, we propose to teach such patch-borrowing behavior to an attention-free generator by joint training of an auxiliary contextual reconstruction task, which encourages the generated output to be plausible even when reconstructed by surrounding regions. The auxiliary branch can be seen as a learnable loss function, i.e. named as contextual reconstruction (CR) loss, where query-reference feature similarity and reference-based reconstructor are jointly optimized with the inpainting generator. The auxiliary branch (i.e. CR loss) is required only during training, and only the inpainting generator is required during the inference. Experimental results demonstrate that the proposed inpainting model compares favourably against the state-of-the-art in terms of quantitative and visual performance.
Introduction
Image inpainting—the process of filling in missing pixels in a way that looks natural—usually relies on two strategies: hallucinating new content or "borrowing" patches from elsewhere in the image. Recent deep learning models use Contextual Attention (CA) layers to explicitly search the image for matching patches. While effective, CA layers have two major flaws: computational overhead ($O(N^2)$ complexity) and a lack of direct supervision, which often results in blurry or mismatched artifacts.
Methodology
The authors propose CR-Fill, which uses a standard coarse-to-fine generator but removes attention layers during inference. Instead, they introduce an auxiliary training branch called the Contextual Reconstruction (CR) loss.
The generator is a standard, attention-free convolutional neural network (CNN). During training, the CR loss branch acts as a "teacher," taking the features generated by the model and attempting to reconstruct the missing area by explicitly copying patches from known regions. The model is penalized if the "reconstructed" image looks unrealistic or doesn't match the ground truth. This forces the generator to learn features that are inherently compatible with the surrounding textures.
Once training is over, the CR branch is discarded. The generator has already "learned" the patch-borrowing behavior, allowing it to produce high-quality results using only standard convolutions, achieving $O(N)$ time complexity.
Experimental Results
The model was trained and evaluated on the Places2 and ImageNet datasets using various mask shapes, including squares and irregular brush strokes.
Performance and Efficiency
CR-Fill consistently outperformed state-of-the-art models like DeepFillv2 and PENNet across metrics like FID (visual realism), PSNR, and SSIM. The efficiency gains are dramatic: at a resolution of $2048 \times 2048$, CR-Fill processed images in about 0.72 seconds on a GPU—nearly 10x faster than competitors which often crash due to memory limits.
Visual Quality
Qualitative results show fewer artifacts and better structural continuity compared to previous methods. The CR loss essentially treats inpainting like a differentiable jigsaw puzzle, encouraging the generator to produce pieces that fit perfectly into the holes based on the surrounding context.
Conclusion
CR-Fill introduces a clever way to improve image inpainting by moving the heavy lifting from the model's architecture to its loss function. By using a novel Contextual Reconstruction (CR) loss during training, the authors teach a simple, fast generator to "borrow" textures from known areas without needing computationally expensive attention layers. While the model excels at texture matching, future work could extend the CR loss to higher-level semantic representations to handle more complex, intelligent reconstructions.
Summary updated