CR-Fill: Generative Image Inpainting with Auxiliary Contexutal Reconstruction

Yu Zeng, Zhe Lin, Huchuan Lu, Vishal M. Patel · DOI

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.

1. Introduction

Image inpainting—the task of filling in missing pixels in a way that is both semantically and structurally coherent—often relies on Contextual Attention (CA) layers. These layers allow a neural network to "borrow" patches from known parts of an image to fill in a hole (e.g., copying a piece of a brick wall to fill a gap in that same wall). However, CA layers suffer from two major drawbacks: a lack of supervision signals for patch correspondence, which often leads to visual artifacts, and significant computational overhead due to pair-wise similarity calculations across entire feature maps. This overhead scales poorly, often causing memory failures at high resolutions.

2. Methodology

The core innovation of CR-Fill is the Contextual Reconstruction (CR) loss. Instead of embedding an attention layer inside the generator, the authors move the "patch-borrowing" logic into an auxiliary branch used only during training.

The generator follows a standard coarse-to-fine CNN architecture but remains "attention-free" during inference. The auxiliary CR branch contains a similarity encoder and an auxiliary decoder. It takes the generator's features, finds the best matching patches from known regions, and reconstructs an "auxiliary image." The generator is penalized if this auxiliary image differs from the ground truth, forcing it to produce features that are inherently "reconstructable" from the surrounding context. Once trained, the auxiliary branch is discarded, allowing for high-quality, efficient inpainting using only standard convolutions.

Comparison of patch-borrowing mechanisms: (a) Input masked images. (b, c) Traditional attention-based methods often fail to find proper reference features, leading to artifacts. (d, e) CR-Fill implicitly learns proper patch-borrowing via the CR loss, resulting in cleaner outputs.

3. Evaluation and Results

The model was evaluated on large-scale benchmarks including Places2 and ImageNet, using both standard masks and object-shaped masks from the Salient Object Segmentation Dataset. CR-Fill outperforms previous state-of-the-art methods like DeepFillv2 and PENNet across several metrics. Quantitatively, it achieved lower L1 error and higher PSNR/SSIM scores. In a user study with 9 human raters, CR-Fill was preferred 271 times, compared to only 88 for the next best method.

Crucially, CR-Fill offers massive efficiency gains. By avoiding the $O(N^2)$ complexity of attention layers, it is significantly faster at high resolutions. For a $2048 \times 2048$ image, CR-Fill runs in just 0.72 seconds on a GPU, whereas attention-based models often fail due to memory limits or take hundreds of seconds on a CPU.

4. Conclusion

CR-Fill demonstrates that patch-borrowing behavior can be distilled into a vanilla CNN through a specialized loss function, bypassing the need for expensive similarity matrices during deployment. While highly effective for structural textures, future work could extend the CR loss to higher-level semantic representations to better handle complex, non-repetitive global structures.

Summary updated

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.
BibTeX
@inproceedings{zeng2021cr,
  author = {Yu Zeng and Zhe Lin and Huchuan Lu and Vishal M. Patel},
  title = {{CR-Fill: Generative Image Inpainting with Auxiliary Contexutal Reconstruction}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2021},
  doi = {10.1109/iccv48922.2021.01390},
}
Figure