LoFTR

Sun 2021 · Paper

One-line summary — Detector-free dense feature matching with Transformers: self- and cross-attention condition features on both images, producing reliable matches even in texture-poor regions where keypoint detectors fail.

Problem

The classical pipeline performs feature detection, description, and matching sequentially, so everything hinges on the detector producing repeatable interest points in both images — which detectors notoriously fail to do in low-texture areas (blank walls, floors) and under repetitive patterns. Existing dense alternatives searched correspondences through cost volumes, which is expensive and still relies on local evidence. LoFTR skips detection entirely: establish pixel-wise dense matches at a coarse level first, then refine the good ones — with a Transformer’s global receptive field deciding what matches, conditioned on both images at once.

Method & architecture

Backbone. A ResNet-18 + FPN CNN extracts coarse features F~A,F~B\tilde{F}^A, \tilde{F}^B at 1/8 resolution and fine features F^A,F^B\hat{F}^A, \hat{F}^B at 1/2 resolution.

LoFTR module. 2D sinusoidal positional encodings (added once) make features position-dependent — crucial for matching indistinctive regions. Then Nc=4N_c = 4 interleaved self- and cross-attention layers transform the coarse features into F~trA,F~trB\tilde{F}^A_{tr}, \tilde{F}^B_{tr}. Vanilla attention Attention(Q,K,V)=softmax(QKT)V\mathrm{Attention}(Q,K,V) = \mathrm{softmax}(QK^T)\,V costs O(N2)O(N^2), so LoFTR uses the Linear Transformer kernel

sim(Q,K)=ϕ(Q)ϕ(K)T,ϕ()=elu()+1\mathrm{sim}(Q,K) = \phi(Q)\cdot\phi(K)^{T}, \quad \phi(\cdot) = \mathrm{elu}(\cdot) + 1

which, by associativity of matrix products (compute ϕ(K)TV\phi(K)^T V first, feature dim DND \ll N), reduces the cost to O(N)O(N).

Coarse matching. A score matrix S(i,j)=1τF~trA(i),F~trB(j)\mathcal{S}(i,j) = \frac{1}{\tau} \langle \tilde{F}^A_{tr}(i), \tilde{F}^B_{tr}(j) \rangle feeds either an optimal-transport layer (as in SuperGlue) or dual-softmax:

Pc(i,j)=softmax(S(i,))jsoftmax(S(,j))i\mathcal{P}_c(i,j) = \mathrm{softmax}\big(\mathcal{S}(i,\cdot)\big)_j \cdot \mathrm{softmax}\big(\mathcal{S}(\cdot,j)\big)_i

Coarse matches are pairs that are mutual nearest neighbours in Pc\mathcal{P}_c with confidence θc=0.2\geq \theta_c = 0.2.

Coarse-to-fine refinement. For every coarse match, w×w=5×5w \times w = 5 \times 5 local windows are cropped from the fine feature maps and transformed by a smaller LoFTR module (Nf=1N_f = 1); correlating the centre vector of the query window against the other window yields a matching-probability heatmap whose expectation gives the sub-pixel position j^\hat{j}'.

Supervision. L=Lc+Lf\mathcal{L} = \mathcal{L}_c + \mathcal{L}_f: negative log-likelihood over ground-truth coarse grid matches (from poses + depth, as in SuperGlue), plus a heatmap-variance-weighted 2\ell_2 loss on the fine offsets:

Lf=1Mf(i^,j^)Mf1σ2(i^)j^j^gt2\mathcal{L}_f = \frac{1}{|\mathcal{M}_f|} \sum_{(\hat{i},\hat{j}')\in\mathcal{M}_f} \frac{1}{\sigma^2(\hat{i})} \big\lVert \hat{j}' - \hat{j}'_{gt} \big\rVert_2

Cost. 116 ms per 640×480 pair on an RTX 2080Ti with dual-softmax (130 ms with optimal transport); trained end-to-end from scratch, 24 h on 64 GTX 1080Ti GPUs for the indoor model.

Results

Why it matters for SLAM

Indoor SLAM constantly fails where there is nothing to detect — blank walls, floors, repetitive surfaces. LoFTR showed that a global-context matcher can produce correspondences there anyway, and it established the detector-free paradigm that RoMa, EfficientLoFTR, and many others build on. In practice it is a go-to choice for indoor reconstruction, wide-baseline relocalization, and loop-closure verification when sparse matching is too brittle, at the cost of more compute than sparse matchers.