# LoFTR: Detector-Free Local Feature Matching with Transformers

LoFTR matches image pairs without detecting interest points first

Jiaming Sun, Zehong Shen, Yuang Wang, Hujun Bao, Xiaowei Zhou · arXiv · 2021-4-1

- **Problem** Detector-based matchers pick interest points first, so they fail in low-texture regions where no repeatable points appear. Without points there is nothing to match, however good the descriptor is.
- **Method** LoFTR skips detection and predicts dense coarse matches with self and cross attention Transformer layers over CNN features. It then refines the selected matches to sub-pixel positions.
- **Results** LoFTR-DS reaches 65.9 AUC on HPatches homography estimation, versus 53.9 for SP with SuperGlue.

## Why detector-based matching stalls

Detector-based pipelines first select interest points and only then describe and match them, so a region where no repeatable interest point appears gives the matcher nothing to work with, however good the descriptor is. The authors stress that this is most visible indoors, where low-texture walls and repetitive patterns can cover most of the field of view.

Dense approaches that predict matches at every pixel avoid the detection step, but their convolutional features have a limited receptive field, so they cannot tell apart regions that look alike locally. The argument is that people resolve such regions by looking at the surrounding layout, for instance by relating a textureless patch to the nearby edges, which calls for a large receptive field in the feature extractor.

## Dense coarse matches followed by refinement

A convolutional backbone with a feature pyramid network produces two feature maps per image: coarse features at 1/8 of the image dimension and fine features at 1/2. Matching is carried out on the coarse level, where the grid is small enough for dense correspondences to be computed affordably, and the fine level is kept for the later refinement.

The coarse feature maps of the two images are flattened into sequences of vectors and given a positional encoding before they enter the LoFTR module. Convolution is used for the first stage because its inductive biases, translation equivariance and locality, suit local feature extraction, and because its downsampling shortens the sequence the Transformer must process.

Each match is then fixed in two steps: a coarse selection on the transformed coarse features, followed by a correlation step on the fine features around every selected coarse match.

## Self and cross attention in the LoFTR module

Self-attention takes the features of one image as both input and context, while cross-attention takes the features of one image as the query side and the other image as the context, and the direction is switched between layers. The two kinds of layers are interleaved Nc times, with Nc set to 4 in the default model.

Because each output feature is a weighted combination over all positions, the transformed features can depend on the whole image pair rather than a fixed neighbourhood, and the positional encoding lets them depend on location as well. A linear variant of attention is used to keep the cost of this global operation at a manageable level.

The paper's attention visualisations show a point on a textureless region drawing on the edges of nearby objects, which is the behaviour the global context is meant to produce.

## Selecting coarse matches

The score between a location i in image A and a location j in image B is the inner product of their transformed features, scaled by a temperature, which can be written as \\(S(i,j)=\\frac{1}{\\tau}\\langle F^{tr}\_A(i),F^{tr}\_B(j)\\rangle\\). Two matching layers turn this score matrix into a confidence matrix: an optimal transport layer, which uses the negated score matrix as the cost of a partial assignment problem, or a dual-softmax, which applies softmax along both dimensions and multiplies the two results.

With dual-softmax the confidence is \\(P\_c(i,j)=\\mathrm{softmax}(S(i,\\cdot))\_j\\cdot\\mathrm{softmax}(S(\\cdot,j))\_i\\), which combines a row-wise and a column-wise normalisation and so favours pairs that agree in both directions. A coarse match is kept only if its confidence is at least \\(\\theta\_c\\), set to 0.2, and it is also a mutual nearest neighbour, which removes many outliers.

## Sub-pixel refinement and training

For each coarse match, a window of size w by w is cropped around its position in the fine features of both images, and a smaller LoFTR module with Nf layers transforms the two windows, with Nf set to 1 and w set to 5. The centre feature of the first window is correlated with every position in the second window, and the expectation over the resulting heatmap gives the refined position with sub-pixel accuracy.

The coarse stage is trained with a negative log-likelihood over the confidence matrix, using ground-truth grid matches derived from the camera poses and depth maps, with the loss averaged over the set of ground-truth coarse matches. The formula is \\(L\_c=-\\frac{1}{\|M^{gt}\_c\|}\\sum\_{(\\tilde i,\\tilde j)\\in M^{gt}\_c}\\log P\_c(\\tilde i,\\tilde j)\\), and the leading minus sign makes minimising the loss equivalent to maximising the log-likelihood of the correct grid pairs.

The fine stage uses an l2 distance between the refined position and the position warped with the ground-truth pose and depth, weighted by the inverse of the heatmap variance, and the variance is not back-propagated through. The full dual-softmax model runs at 116 ms per 640×480 pair on an RTX 2080Ti, and with the optimal transport layer and three sinkhorn iterations it runs at 130 ms.

## Homography estimation on HPatches

HPatches contains 52 sequences with large illumination changes and 56 with large viewpoint changes, and every sequence pairs one reference image with five others. LoFTR was trained on MegaDepth for this test, with images resized to a shorter side of 480, and homographies were fitted with OpenCV RANSAC and scored by the corner error of the warped images.

LoFTR-DS reaches 65.9, 75.6 and 84.6 AUC at the 3, 5 and 10 pixel thresholds, while SP with SuperGlue reaches 53.9, 68.3 and 81.7, and the other detector-free and detector-based baselines are lower still. The gap to SP with SuperGlue is largest at 3 pixels and smaller at 10 pixels, and the authors describe the advantage as growing with a stricter correctness threshold.

The authors attribute the result to the larger number of candidate matches that a detector-free design yields and to the global receptive field of the Transformer, with the coarse-to-fine step adding sub-pixel precision. The comparison caps every method at 1K matches, but local features were limited to 2K features before mutual nearest neighbour matching, so the setup differs between the two groups.

## Relative pose on ScanNet and MegaDepth

ScanNet contains 1613 monocular sequences, and the authors sample 230M training pairs with overlap scores between 0.4 and 0.8, then test on 1500 pairs at 640×480. Pose error is the maximum of the rotation and translation angular errors, scored as AUC at 5, 10 and 20 degrees.

On ScanNet, LoFTR-DS reaches 22.06, 40.8 and 57.62, and LoFTR-OT reaches 21.51, 40.39 and 57.96, against 16.16, 33.81 and 51.84 for SP with SuperGlue. The authors describe the two matching layers as performing comparably on ScanNet, and a DRC-Net model trained on MegaDepth scores 7.69, 17.93 and 30.49 in the same table. The LoFTR model trained on MegaDepth, marked with a dagger, reaches 16.88, 33.62 and 50.62 on ScanNet, which the authors use as the fair comparison to DRC-Net trained on MegaDepth.

On MegaDepth, LoFTR-DS reaches 52.8, 69.19 and 81.18 and LoFTR-OT reaches 50.31, 67.14 and 79.93, against 42.18, 61.16 and 75.96 for SP with SuperGlue and 27.01, 42.96 and 58.31 for DRC-Net. At AUC@10 degrees the authors report LoFTR outperforming DRC-Net by 61% and SuperGlue by 13%, and on this outdoor set LoFTR-DS is better than LoFTR-OT, which is the reverse of the indoor result.

## Visual localization on Aachen and InLoc

The evaluation covers the Aachen Day-Night benchmark and the InLoc dataset, and it has two tracks: a full pipeline using HLoc with LoFTR matches, and a local feature track in which the matcher is evaluated alone.

On the night queries of the local feature track, LoFTR-DS reaches 72.8, 88.5 and 99.0, while SP with SuperGlue reaches 73.3, 88.0 and 98.4, so the baseline is higher at the tightest threshold. In the full localization track, LoFTR-OT reaches 88.7, 95.6 and 99.0 on day queries and 78.5, 90.6 and 99.0 on night queries, against 89.8, 96.1 and 99.4 and 77.0, 90.6 and 100.0 for SP with SuperGlue, which the authors describe as on par on night queries and slightly worse on day queries.

On the first InLoc column, HLoc with LoFTR-OT reaches 47.5, 72.2 and 84.8, against 49.0, 68.7 and 80.8 for HLoc with SuperPoint and SuperGlue, so LoFTR-OT is higher at the 0.5 m and 1.0 m thresholds and lower at 0.25 m. The authors credit the Transformer, the optimal transport layer and the detector-free design for the gain on InLoc, which they describe as containing appearance changes, more textureless areas and repetitive elements.

## What the ablations isolate

Replacing the LoFTR module with convolution of comparable size lowers the 10 degree AUC to 32.04, against 40.8 for the full model, and the 5 degree AUC to 14.98, against 20.06. The full row of the ablation table is its own measurement and is not the same row as the LoFTR-OT entry of the main ScanNet table, so the two should not be compared directly.

A smaller model with 1/16 coarse and 1/4 fine resolution reaches 16.75, 34.82 and 54.0, and the authors report a running time of 104 ms with a degraded accuracy. Placing positional encoding at every layer, as in a DETR-style Transformer, reaches 18.02, 35.64 and 52.77, which the authors describe as a noticeable decline.

Doubling the layers to Nc = 8 and Nf = 2 gives 20.87, 40.23 and 57.56, which the authors describe as barely changing the results. Each variant was trained and evaluated with the same ScanNet protocol and an optimal transport layer, so the variants differ only in the stated component.

## Limitations

Matching precision was not compared with detector-based methods, because no well-defined metric exists for evaluating detector-free matchers. The comparisons therefore rest on pose, homography and localization accuracy, not on matching precision or recall.

The ablation table covers five variants, all trained and evaluated on ScanNet, and no ablation on MegaDepth or the visual localization benchmarks is reported. The conclusion names matching under severe seasonal changes as a direction for extension, and that setting is not evaluated in the paper.

The reported running times are for one RTX 2080Ti, at 116 ms for dual-softmax and 130 ms for the optimal transport setup on 640×480 pairs.

## Paper info

- **Authors**: Jiaming Sun, Zehong Shen, Yuang Wang, Hujun Bao, Xiaowei Zhou
- **Venue**: arXiv · Preprint
- **First published**: 2021-4-1
- **Added**: 2026-11-12
- **Updated**: 2021-4-1
- **Version**: v1
- **arXiv**: 2104.00680
- **Category**: cs.CV · cs.RO
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2104.00680v1) · [PDF ↗](https://arxiv.org/pdf/2104.00680v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Jiaming Sun, Zehong Shen, Yuang Wang, Hujun Bao, Xiaowei Zhou (2021). LoFTR: Detector-Free Local Feature Matching with Transformers. arXiv:2104.00680v1. https://arxiv.org/abs/2104.00680v1

**BibTeX**

```
@misc{sun2021loftr,
  title = {{LoFTR: Detector-Free Local Feature Matching with Transformers}},
  author = {Jiaming Sun and Zehong Shen and Yuang Wang and Hujun Bao and Xiaowei Zhou},
  year = {2021},
  eprint = {2104.00680},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.00680v1}
}
```

## Other paper commentary

- [Generalized Cross Entropy Loss for Training Deep Neural Networks with Noisy Labels](https://refivu.com/en/papers/41c59d55-611c-4abf-a4e2-459eb900711f-generalized-cross-entropy-loss-for-training-deep-neural.md)
- [Hypergraph Neural Networks](https://refivu.com/en/papers/cf9d7d35-b5ef-4472-b64e-4c332f808ace-hypergraph-neural-networks.md)
- [Deep Ordinal Regression Network for Monocular Depth Estimation](https://refivu.com/en/papers/e525192f-9651-4698-8525-b6cda281195b-deep-ordinal-regression-network-for-monocular-depth.md)
- [Stacked Attention Networks for Image Question Answering](https://refivu.com/en/papers/aa94a5f2-b4fb-441a-af4b-22eda9ad2985-stacked-attention-networks-for-image-question-answering.md)
- [A guide to convolution arithmetic for deep learning](https://refivu.com/en/papers/7690e8f8-368e-4a59-a827-7093c4415777-a-guide-to-convolution-arithmetic-for-deep-learning.md)
- [Explainable Artificial Intelligence: Understanding, Visualizing and Interpreting Deep Learning Models](https://refivu.com/en/papers/6bd22a78-4fb3-465f-b297-2113b18ee3f2-explainable-artificial-intelligence-understanding.md)
- [Prompt-to-Prompt Image Editing with Cross Attention Control](https://refivu.com/en/papers/a18cb3bd-2a1b-4adf-9a2a-f866c7f83edf-prompt-to-prompt-image-editing-with-cross-attention.md)
- [Named Entity Recognition with Bidirectional LSTM-CNNs](https://refivu.com/en/papers/454922d0-d836-4e69-a3cd-d40cf940d456-named-entity-recognition-with-bidirectional-lstm-cnns.md)
- [Transferability in Machine Learning: from Phenomena to Black-Box Attacks using Adversarial Samples](https://refivu.com/en/papers/0070f617-bee7-4459-b94e-a20f7c1d2de5-transferability-in-machine-learning-from-phenomena-to-black.md)
- [Conditional Adversarial Domain Adaptation](https://refivu.com/en/papers/a233380e-bb76-4fca-bc73-df4e86a220e3-conditional-adversarial-domain-adaptation.md)
- [TotalSegmentator: robust segmentation of 104 anatomical structures in CT images](https://refivu.com/en/papers/38d65e87-91c3-4285-bca2-9755328de70d-totalsegmentator-robust-segmentation-of-104-anatomical.md)
- [RMPE: Regional Multi-person Pose Estimation](https://refivu.com/en/papers/a258675a-c286-4c65-9760-3d72305d7120-rmpe-regional-multi-person-pose-estimation.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [AUC](https://refivu.com/en/terms/017a335bbf0e-auc)
- [SuperGLUE](https://refivu.com/en/terms/e4683d9c222e-superglue)
- [Scannet](https://refivu.com/en/terms/bef8b5634a3a-scannet)
- [homography estimation](https://refivu.com/en/terms/23c05499d73d-homography-estimation)
- [HPatches](https://refivu.com/en/terms/fe0bb4e2e38f-hpatches)
- [linear transformer](https://refivu.com/en/terms/d8bd1026d78c-linear-transformer)
- [LoFTR](https://refivu.com/en/terms/23a13283085c-loftr)
- [MegaDepth](https://refivu.com/en/terms/4aef33cefa67-megadepth)
- [SuperPoint](https://refivu.com/en/terms/850221d238fc-superpoint)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/7c0476a6-4dcb-4eab-beac-aaa3eb492203-loftr-detector-free-local-feature-matching-with-transformers)
