TFill: Image Completion via a Transformer-Based Architecture

Chuanxia Zheng, Tat-Jen Cham, Jianfei Cai

Abstract

Bridging global context interactions correctly is important for high-fidelity image completion with large masks. Previous methods attempting this via deep or large receptive field (RF) convolutions cannot escape from the dominance of nearby interactions, which may be inferior. In this paper, we propose to treat image completion as a directionless sequence-to-sequence prediction task, and deploy a transformer to directly capture long-range dependence in the encoder. Crucially, we employ a restrictive CNN with small and non-overlapping RF for weighted token representation, which allows the transformer to explicitly model the long-range visible context relations with equal importance in all layers, without implicitly confounding neighboring tokens when larger RFs are used. To improve appearance consistency between visible and generated regions, a novel attention-aware layer (AAL) is introduced to better exploit distantly related high-frequency features. Overall, extensive experiments demonstrate superior performance compared to state-of-the-art methods on several datasets.

Introduction

Image completion, or inpainting, aims to fill missing regions of an image with plausible, photorealistic content. When masks are large or irregular, the network must look far across the image to find relevant context—for instance, looking at the background on the left to complete the background on the right.

Traditionally, Convolutional Neural Networks (CNNs) achieve this global view by stacking many layers to increase their receptive field (RF). However, this creates a "proximity bias": information flows gradually, meaning a masked pixel is heavily influenced by its immediate neighbors rather than distant, potentially more relevant pixels. While Transformers are naturally suited for long-range dependencies, applying them to high-resolution images is memory-intensive. Furthermore, existing vision transformers often use deep CNNs to extract tokens, which inadvertently reintroduces proximity bias by smearing masked and visible pixels together before the transformer processes them.

Methodology

TFill treats image completion as a directionless sequence-to-sequence prediction task using a two-stage architecture.

Content Inference Network (TFill-Coarse)

The first stage focuses on global structure. Instead of using deep CNNs or simple pixel-flattening to create tokens, TFill uses a restrictive CNN with small, non-overlapping receptive fields. This ensures each token represents only local visible information. By preventing neighboring tokens from implicitly mixing, the Transformer is forced to explicitly model long-range relationships.

The transformer's attention mechanism is modified to bias towards visible pixels. Attention scores are scaled by a weight reflecting the fraction of visible pixels in that specific patch, which updates layer-by-layer. Unlike autoregressive transformers that generate pixels one-by-one, TFill uses a CNN decoder to predict all tokens simultaneously, drastically speeding up inference.

Appearance Refinement Network (TFill-Refined)

To scale to high resolutions (e.g., 512x512) and ensure the generated content matches the visible content, the authors introduce the Attention-Aware Layer (AAL). Standard self-attention struggles here because generated features and real features look mathematically distinct, causing them to ignore each other. The AAL explicitly splits attention into two streams—similarity to visible regions and similarity to generated regions—and dynamically balances them. This is crucial for maintaining symmetric consistency, such as ensuring a generated eye matches the visible one.

Figure 1: Face completion example highlighting the challenge of maintaining symmetric consistency in features like eyes.

Evaluation and Results

The model was evaluated on standard high-resolution datasets including CelebA-HQ, FFHQ, Places2, and ImageNet using free-form irregular and center rectangular masks.

Performance and Speed

TFill outperforms leading CNN and Transformer baselines (like CRFill, HiFill, and ICT) across all mask ratios on Places2. On 20-30% masks, it achieves a PSNR of 25.10 and an FID of 15.28, significantly beating prior state-of-the-art methods.

Crucially, TFill is remarkably fast. By using a CNN decoder to predict all tokens in one step, it takes just 0.18 seconds per image. In contrast, the autoregressive transformer ICT takes 152.48 seconds per image.

Qualitative Analysis

Visually, TFill excels at maintaining structural alignment and symmetric consistency even under massive, challenging masks. As shown in Figure 2, TFill produces significantly cleaner and more semantically coherent results compared to previous transformer-based approaches that suffer from artifacts or blurriness in large masked regions.

Figure 2: Qualitative comparison on a complex scene. (a) Masked image, (b) Baseline result (ICT), (c) TFill result showing superior clarity and structure.

Discussion and Limitations

A key insight of this work is that token representation is critical for inpainting. If a standard deep CNN creates tokens, large overlapping receptive fields cause empty masked regions to absorb values from nearby pixels, ruining the Transformer's ability to route global information objectively. By restricting the CNN to purely local, non-overlapping feature extraction, the Transformer is freed to perform unbiased routing across the entire image.

However, the authors note a limitation regarding high-level semantic reasoning. While TFill is excellent at copying and blending visual textures, it lacks a deep understanding of the physical world. For example, it might reconstruct the siding of a house perfectly but fail to generate a door, not "knowing" that a house requires one. Future work will likely need to explore how to inject deeper semantic world knowledge into the generative process.

Summary updated

BibTeX
@inproceedings{zheng2021tfill,
  author = {Chuanxia Zheng and Tat-Jen Cham and Jianfei Cai},
  title = {{TFill: Image Completion via a Transformer-Based Architecture}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2021},
}
Figure