MatchFormer: Interleaving Attention in Transformers for Feature Matching

Qing Wang, Jiaming Zhang, Kailun Yang, Kunyu Peng, Rainer Stiefelhagen

Abstract

Feature matching is a fundamental component of computer vision tasks such as 3D reconstruction and autonomous navigation. Traditional deep learning pipelines often rely on an "extract-then-match" paradigm, where a standard encoder extracts features in isolation before a heavy decoder attempts to find correspondences. This approach often leads to suboptimal features and high computational costs. This paper introduces MatchFormer, a novel "extract-and-match" transformer architecture. By interleaving self-attention and cross-attention directly within a hierarchical encoder, MatchFormer creates a "match-aware" backbone that is both more efficient and more robust than previous state-of-the-art models.

Introduction

Feature matching—the process of identifying corresponding points between two different views of a scene—is essential for Structure-from-Motion (SfM) and Simultaneous Localization and Mapping (SLAM). Historically, this was achieved through detector-based methods that identified and described points before matching them. Recently, "extract-to-match" pipelines like LoFTR have gained prominence by using CNNs for feature extraction followed by transformer decoders for matching.

However, these models suffer from two primary limitations. First, the Overburdened Decoder must perform the bulk of the computational work, leading to high latency. Second, the Ignorant Encoder extracts features without considering the eventual matching task, which often results in poor performance in challenging, low-texture environments such as indoor scenes with plain walls.

Methodology: The Match-Aware Backbone

MatchFormer shifts the paradigm from extract-then-match to extract-and-match. The core innovation is the integration of matching logic directly into the feature extraction process.

Interleaving Attention

Inside each of the four stages of the hierarchical encoder, MatchFormer alternates between self-attention and cross-attention. Self-attention allows the model to understand the internal structure of a single image, while cross-attention allows it to find similarities across the image pair. This "synchronous" process mimics human intuition, where an observer looks back and forth between two images to find correspondences.

Hierarchical Strategy and PosPE

The authors observed that shallow layers benefit more from self-attention to capture fine-grained texture, while deeper layers benefit from cross-attention to capture semantic similarities. To preserve local detail, the model utilizes Positional Patch Embedding (PosPE). Unlike standard Vision Transformer (ViT) patch embeddings, PosPE uses overlapping and depth-wise convolutions to maintain continuous local information and encode spatial position via padding.

Efficient Attention Variants

To maintain high resolution without the prohibitive memory costs of standard transformers, MatchFormer employs two efficient attention mechanisms:

  • Spatial Efficient Attention (SEA): Optimized for sparse, low-texture indoor scenes.
  • Linear Attention (LA): Optimized for dense, high-resolution outdoor environments.

Experimental Results

MatchFormer was evaluated across four major benchmarks: ScanNet (indoor pose estimation), MegaDepth (outdoor pose estimation), HPatches (homography estimation), and InLoc (indoor visual localization).

Performance and Efficiency

The "large" version of MatchFormer achieved state-of-the-art (SOTA) performance across all four benchmarks. More impressively, the MatchFormer-lite-SEA variant achieved a 41% running speed increase over LoFTR while improving precision in indoor pose estimation by 1.3%. By making the encoder "match-aware," the authors were able to utilize a significantly lighter, FPN-like decoder, reducing GFLOPs to just 45% of previous models.

Data Efficiency and Robustness

One of the most striking findings was the model's data efficiency. When trained on only 10% of the standard training data, MatchFormer outperformed competing models trained on the full 100%. This suggests a much stronger inductive bias for the matching task. Qualitatively, the model consistently identifies correct matches on challenging surfaces like floors and ceilings where previous methods typically produce noisy mismatches.

Conclusion

MatchFormer demonstrates that interleaving self- and cross-attention within the encoder creates a more efficient and effective feature matching pipeline. By shifting the computational load from the decoder to a match-aware encoder, the model achieves superior performance with lower resource requirements. Future work will focus on developing a unified efficient attention module to handle both indoor and outdoor scenarios with equal hardware efficiency and exploring even lighter MLP-based decoders.

Summary updated

BibTeX
@inproceedings{wang2022matchformer,
  author = {Qing Wang and Jiaming Zhang and Kailun Yang and Kunyu Peng and Rainer Stiefelhagen},
  title = {{MatchFormer: Interleaving Attention in Transformers for Feature Matching}},
  booktitle = {ACCV},
  year = {2022},
  doi = {10.1007/978-3-031-26313-2\_16},
}
Figure