Models · Dense matching

LoFTR

LoFTR (Zhejiang University, CVPR 2021): detector-free matching of two photos of one scene with transformers; semi-dense matches as keypoint pairs (the form COLMAP takes). Outdoor (MegaDepth) and indoor (ScanNet) weights. Apache-2.0 code and weights.

experimental Fork of zju3dv/LoFTR@df7ca80 · backends: portable, kernels

Checkpoint

Paper 2021 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 95.9 ms 768x1024, fp16
vs the faster original 2.5× original fp32: 241 ms
Peak memory 760 MiB original: 1,739 MiB
Accuracy vs original fp32 +0.5 portable AUC@5°, MegaDepth-1500 (50.1 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install fastforks-core

from fastforks import matching

model = matching.load("loftr-outdoor")  # kernels on a supported GPU, else portable PyTorch
result = model(image_a, image_b)
result.keypoints1  # also: keypoints2, pairs, scores
result.backend  # what ran: mode, device, dtype, kernels

points1, points2 = result.matches(5000)  # matched pixels, sampled where the model is certain
pose = matching.estimate_pose(points1, points2, K1, K2)  # relative pose on the GPU (RANSAC); K = intrinsics [3, 3]
pose.R, pose.t, pose.inliers  # rotation, unit translation, inlier mask
fastforks bench loftr-outdoor

Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.

Speed and memory

Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.

Input: synthetic, 768x1024 (the task’s standard size)

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original (own default)upstream LoFTR default_cfg, temp_bug_fix False, long side 840fp32 241–1,739 MiB/1,870 MiB0.30.24
Portable fp32fp32not measured ––––
Portablefp16 1102.2×796 MiB/904 MiB0.20.58
Kernelsfp16 95.92.5×760 MiB/886 MiB0.70.37
Portable + torch.compile 1761.4×1,149 MiB/1,232 MiB33 (build)–
TensorRTplanned for 0.2.1fails––––

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.

Other devices

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-17Originalfp32997 6,998 MiB process–768x1024
Portablefp16723 3,614 MiB processmatches768x1024
Portablefp32875 5,767 MiB processmatches768x1024
Kernelsfp16not implemented–768x1024
Kernelsfp32not implemented–768x1024

CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.

Licence and weights

Commercial use allowed

Code
Apache-2.0 LICENSE
Weights
Apache-2.0 source
Training data

Our reading of the licences, not legal advice.

Weights

loftr_outdoor.ckpt 46.3 MB· hosted on Hugging Face

fastforks downloads and checks these files on first use (fastforks download loftr-outdoor).

Accuracy

The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.

MegaDepth-1500

relative pose AUC@5 / @10 / @20 degrees

RundtypeAUC@5° ↑AUC@10° ↑AUC@20° ↑Δ AUC@5° vs fp32 originalpairsms / pair
Original fp32fp3250.167.580.3 reference 1500 152
Original fp16not measured
Portable fp32fp3250.867.880.2 +0.6 1500 150
Portablefp1650.667.680.3 +0.5 1500 74.0
Kernelsnot measured

Dense matchers: 5000 matches per pair sampled from the warp by certainty (upstream's balanced KDE sampling); sparse matchers: all their matches of one call (LightGlue, XFeat: LightGlue's MegaDepth-1500 setting; LoFTR, DeDoDe: their card defaults). OpenCV essential-matrix RANSAC (0.5 px threshold, normalised by the mean focal length); AUC of the larger of the rotation and translation-direction errors. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-15; portable fp32, portable: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 3a7e4880, 2026-11-15.

MegaDepth-1500

every 10th pair, relative pose AUC@5 / @10 / @20 degrees

RundtypeAUC@5° ↑AUC@10° ↑AUC@20° ↑Δ AUC@5° vs fp32 originalpairsms / pair
Original fp32fp3253.871.883.7 reference 150 155
Original fp16not measured
Portable fp32fp3252.171.083.3 −1.7 150 155
Portablefp3252.171.083.3 −1.7 150 155
Kernelsfp1657.174.285.0 +3.3 150 61.2

Dense matchers: 5000 matches per pair sampled from the warp by certainty (upstream's balanced KDE sampling); sparse matchers: all their matches of one call (LightGlue, XFeat: LightGlue's MegaDepth-1500 setting; LoFTR, DeDoDe: their card defaults). OpenCV essential-matrix RANSAC (0.5 px threshold, normalised by the mean focal length); AUC of the larger of the rotation and translation-direction errors. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13; portable fp32, portable: RTX 5060 Ti, torch 2.14.1+cu130, fastforks aee4b565, 2026-11-13; kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 68b2f345, 2026-11-16.

Relative pose on the GPU

A dense matcher is usually followed by RANSAC on its matches to get the camera motion. fastforks does that step on the GPU too: result.matches(n) samples matched points where the model is certain, and matching.estimate_pose runs essential-matrix RANSAC on them, many image pairs per call, with no copy to the CPU. Like the models it has a portable (plain PyTorch) and a kernels (CUDA) backend.

SolverRuns onThreshold (px)Pose AUC@5 / @10 / @20Pairs per second
fastforks estimate_pose, kernelsGPU, batches of 500 pairs1.069.9 / 81.5 / 89.318,446
fastforks estimate_pose, portableGPU, batches of 500 pairs1.069.6 / 81.2 / 89.1418
PoseLib 2.0.5CPU, 16 processes1.070.0 / 81.6 / 89.5325
OpenCV USAC (MAGSAC++)CPU, 16 processes0.565.7 / 78.6 / 87.3271
OpenCV RANSACCPU, 16 processes0.562.9 / 76.9 / 86.4323

MegaDepth-1500, RoMa v2 matches (5000 per pair), 5 samplings, the same matches for every solver, on one machine: RTX 5060 Ti and a Ryzen 7 5800X (16 threads). Each solver runs at the inlier threshold where it is most accurate. Pairs per second is wall-clock throughput over all 7500 poses: the CPU solvers run one pair per call in 16 single-threaded processes, the GPU solver takes 500 pairs per call. One pair alone takes about 1.7 ms with the kernels, 29 ms with PoseLib and 24 ms with OpenCV RANSAC on one core. The accuracy table above stays on OpenCV RANSAC, as in the papers, so it is comparable with published numbers; this table is the only place the GPU solver is used.

Closeness to the original

Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 3e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0025 and p99 <= 0.02 (absolute error of the output keypoints1).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.00003 not recorded
cpu_min_recall≤ 0.99 not recorded
cpu_min_match≤ 0.99 not recorded
GPU default dtypes, mean |diff|≤ 0.0025 0.00211
GPU default dtypes, p99 |diff|≤ 0.02 0.01445
gpu_min_recall≤ 0.998 not recorded
gpu_min_match≤ 0.998 not recorded

Recorded for loftr-outdoor on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-15, with these kernels: cudnn_hacccutlass_convigev

Details

LoFTR (Sun et al., CVPR 2021): detector-free dense matching. A ResNet-FPN gives 1/8 and 1/2 resolution features; a linear-attention transformer matches the 1/8 cells of both images (dual-softmax, mutual nearest neighbours above a confidence threshold) and a second transformer refines each match to sub-pixel precision in a 5 x 5 window at 1/2 resolution. Returns the matched points of both images, their (identity) index pairs and the coarse confidence.

Input / output
Input: two RGB images of one scene. Output: for every pixel of the first image its position in the second (x, y in pixels) and a certainty that the pixel is visible in both.
What the numbers mean, and which models need the camera focal length

Sparse matchers (LightGlue) return the keypoints of both images and the index pairs of the matched ones instead. To reconstruct camera poses from an image folder with these matchers, see [structure from motion](../sfm.md).

Input size
any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (1,943 MiB allocated)
Options
  • long_side=840>= 0· changes the output
Outputs
keypoints1, keypoints2, pairs, scores
Checkpoint
temp_bug_fix=false, border_rm=2
CUDA kernels
  • igevIGEV stereo: convolution epilogues, correlation lookups, GRU gates
  • cutlass_convCUTLASS convolutions with the recurrent update (GRU) fused in
  • cudnn_haccconvolutions with fp16 accumulation (cuDNN)
Apple (MPS)
fp32, fp16

Limitations

  • Sparse output: no dense warp. `result.matches()` gives the matched points for `estimate_pose`; every match is its own keypoint pair (`pairs` is `[[0, 0], [1, 1], ...]`).
  • One image pair per call internally (batches run pair by pair); the match counts differ per pair.
  • No exportable module: the match counts are data-dependent (`torch.compile` runs with graph breaks; ONNX / TensorRT export fails).
  • Images are converted to grayscale and matched at `long_side` (default 840, upstream's MegaDepth test size); the coarse matching holds an (H W / 64)^2 score matrix, so memory grows with the 4th power of the side. The indoor weights were evaluated by upstream at 640 x 480 (ScanNet).
Full reference, generated from the repository

LoFTR (Zhejiang University, CVPR 2021): detector-free matching of two photos of one scene with transformers; semi-dense matches as keypoint pairs (the form COLMAP takes). Outdoor (MegaDepth) and indoor (ScanNet) weights. Apache-2.0 code and weights.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
loftr-outdoorsynthetic (768x1024)original
portable
kernels
portable + torch.compile
TensorRT fp16
241
110
95.9
176
planned for 0.2.1
1739 / 1870
796 / 904
760 / 886
1149 / 1232
–
loftr-indoorsynthetic (768x1024)original
portable
kernels
portable + torch.compile
TensorRT fp16
242
111
96.2
71.0
planned for 0.2.1
1751 / 1910
796 / 904
760 / 886
634 / 684
–
Details
  • Original code: https://github.com/zju3dv/LoFTR at df7ca80f9173
  • Code licence: Apache-2.0 (permissive); files: LICENSE
  • Weights licence: Apache-2.0
  • Licence evidence: https://github.com/zju3dv/LoFTR/blob/df7ca80f917334b94cfbe32cc2901e09a80e70a8/LICENSE ; https://huggingface.co/kornia/loftr/tree/0fb3b456cf176746709c38fa9cf80695a1c82dac
  • Training data: MegaDepth (Internet photo collections with SfM / MVS depth) (loftr-outdoor: MegaDepth. loftr-indoor: ScanNet (ScanNet terms of use: non-commercial research), README training section.)
  • Options: long_side = 840 (>= 0)
  • Kernel libraries: igev, cutlass_conv, cudnn_hacc
  • Variants: loftr-outdoor, loftr-indoor
  • Not in this release (planned for 0.2.1): loftr-outdoor ONNX / TensorRT export: torch.export stops at a data-dependent branch (loftr.py:190); loftr-indoor ONNX / TensorRT export: torch.export fails (TorchExportError, step 1/3 of the ONNX export)
  • Outputs: keypoints1, keypoints2, pairs, scores
  • Input size: any H x W >= 32, padded to a multiple of 32
  • Tested up to (portable, fp16, RTX 5060 Ti 16 GB): loftr-outdoor 3000x4000 (1.9 GiB peak allocated, 2.8 reserved); loftr-indoor 3000x4000 (2.0 GiB peak allocated, 2.8 reserved)
  • loftr-outdoor 768x1024, first call: portable + torch.compile 33 s (cold Inductor cache).
  • loftr-indoor 768x1024, first call: portable + torch.compile 30 s (cold Inductor cache).
  • loftr-outdoor original 768x1024: upstream LoFTR default_cfg, temp_bug_fix False, long side 840
  • loftr-indoor original 768x1024: upstream LoFTR default_cfg, temp_bug_fix True, long side 840
  • loftr-outdoor load / first call: original 0.35 s / 0.242 s, portable 0.24 s / 0.578 s, kernels 0.67 s / 0.369 s
  • loftr-indoor load / first call: original 1.49 s / 0.693 s, portable 0.32 s / 0.53 s, kernels 0.54 s / 0.429 s
  • Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5

Measured

Dense matchers: 5000 matches per pair sampled from the warp by certainty (upstream's balanced KDE sampling); sparse matchers: all their matches of one call (LightGlue, XFeat: LightGlue's MegaDepth-1500 setting; LoFTR, DeDoDe: their card defaults). OpenCV essential-matrix RANSAC (0.5 px threshold, normalised by the mean focal length); AUC of the larger of the rotation and translation-direction errors. Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32portableportable fp32kernelsnote
loftr-outdoorMegaDepth-1500, relative pose AUC@5 / @10 / @20 degrees50.1 / 67.5 / 80.350.6 / 67.6 / 80.350.8 / 67.8 / 80.2
loftr-outdoorMegaDepth-1500, every 10th pair, relative pose AUC@5 / @10 / @20 degrees53.8 / 71.8 / 83.752.1 / 71.0 / 83.357.1 / 74.2 / 85.0

Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 3a7e4880 / aee4b565, 2026-11-13 to 2026-11-15; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 3a7e4880, 2026-11-15; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 68b2f345, 2026-11-16.

Parity

CPU, float32: max |diff| <= 3e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0025 and p99 <= 0.02 (absolute error of the output keypoints1).

variantkernels error vs original, mean / p99GPU, torchkernels used
loftr-outdoor0.00211 / 0.01445RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, igev@f075827d68c6:sm_120
loftr-indoor0.00174 / 0.01007RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, igev@f075827d68c6:sm_120

Limitations

  • Sparse output: no dense warp. result.matches() gives the matched points for estimate_pose; every match is its own keypoint pair (pairs is [[0, 0], [1, 1], ...]).
  • One image pair per call internally (batches run pair by pair); the match counts differ per pair.
  • No exportable module: the match counts are data-dependent (torch.compile runs with graph breaks; ONNX / TensorRT export fails).
  • Images are converted to grayscale and matched at long_side (default 840, upstream's MegaDepth test size); the coarse matching holds an (H W / 64)^2 score matrix, so memory grows with the 4th power of the side. The indoor weights were evaluated by upstream at 640 x 480 (ScanNet).

Example output

No example rendered for this checkpoint yet.