Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.

LoFTR: Detector-Free Local Feature Matching with Transformers

Project Page | Paper

LoFTR: Detector-Free Local Feature Matching with Transformers
Jiaming Sun*, Zehong Shen*, Yu'ang Wang*, Hujun Bao, Xiaowei Zhou
CVPR 2021


TODO List and ETA

  • Inference code and pretrained models (DS and OT) (2021-4-7)
  • Code for reproducing the test-set results (2021-4-7)
  • Webcam demo to reproduce the result shown in the GIF above (2021-4-13)
  • Training code and training data preparation (expected 2021-6-10)

Discussions about the paper are welcomed in the discussion panel.


  1. Undistorted images from D2Net are not available anymore.
    For a temporal alternative, please use the undistorted images provided by the MegaDepth_v1 (should be downloaded along with the required depth files). We numerically compared these images and only found very subtle difference.

🚩 Updates

Colab demo

Want to run LoFTR with custom image pairs without configuring your own GPU environment? Try the Colab demo: Open In Colab

Using from kornia

LoFTR is integrated into kornia library since version 0.5.11.

pip install kornia

Then you can import it as

from kornia.feature import LoFTR

See tutorial on using LoFTR from kornia here.


# For full pytorch-lightning trainer features (recommended)
conda env create -f environment.yaml
conda activate loftr

# For the LoFTR matcher only
pip install torch einops yacs kornia

We provide the download link to

  • the scannet-1500-testset (~1GB).
  • the megadepth-1500-testset (~600MB).
  • 4 pretrained models of indoor-ds, indoor-ot, outdoor-ds and outdoor-ot (each ~45MB).

By now, the environment is all set and the LoFTR-DS model is ready to go! If you want to run LoFTR-OT, some extra steps are needed:

[Requirements for LoFTR-OT]

We use the code from SuperGluePretrainedNetwork for optimal transport. However, we can't provide the code directly due its strict LICENSE requirements. We recommend downloading it with the following command instead.

cd src/loftr/utils  

Run LoFTR demos

Match image pairs with LoFTR

[code snippets]
from src.loftr import LoFTR, default_cfg

# Initialize LoFTR
matcher = LoFTR(config=default_cfg)
matcher = matcher.eval().cuda()

# Inference
with torch.no_grad():
    matcher(batch)    # batch = {'image0': img0, 'image1': img1}
    mkpts0 = batch['mkpts0_f'].cpu().numpy()
    mkpts1 = batch['mkpts1_f'].cpu().numpy()

An example is given in notebooks/demo_single_pair.ipynb.

Online demo

Run the online demo with a webcam or video to reproduce the result shown in the GIF above.

cd demo
set -e
# set -x

if [ ! -f ]; then
    echo "Downloading from the SuperGlue repo."
    echo "We cannot provide this file directly due to its strict licence."

# Use webcam 0 as input source. 
# or use a pre-recorded video given the path.
# input=/home/sunjiaming/Downloads/scannet_test/$scene_name.mp4

# Toggle indoor/outdoor model here.
# model_ckpt=../weights/outdoor_ds.ckpt

# Optionally assign the GPU ID.

echo "Running LoFTR demo.."
eval "$(conda shell.bash hook)"
conda activate loftr
python --weight $model_ckpt --input $input
# To save the input video and output match visualizations.
# python --weight $model_ckpt --input $input --save_video --save_input

# Running on remote GPU servers with no GUI.
# Save images first.
# python --weight $model_ckpt --input $input --no_display --output_dir="./demo_images/"
# Then convert them to a video.
# ffmpeg -framerate 15 -pattern_type glob -i '*.png' -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

Reproduce the testing results with pytorch-lightning

You need to setup the testing subsets of ScanNet and MegaDepth first. We create symlinks from the previously downloaded datasets to data/{{dataset}}/test.

# set up symlinks
ln -s /path/to/scannet-1500-testset/* /path/to/LoFTR/data/scannet/test
ln -s /path/to/megadepth-1500-testset/* /path/to/LoFTR/data/megadepth/test
conda activate loftr
# with shell script
bash ./scripts/reproduce_test/

# or
python configs/data/ configs/loftr/ --ckpt_path weights/indoor_ds.ckpt --profiler_name inference --gpus=1 --accelerator="ddp"

For visualizing the results, please refer to notebooks/visualize_dump_results.ipynb.


See Training LoFTR for more details.


If you find this code useful for your research, please use the following BibTeX entry.

  title={{LoFTR}: Detector-Free Local Feature Matching with Transformers},
  author={Sun, Jiaming and Shen, Zehong and Wang, Yuang and Bao, Hujun and Zhou, Xiaowei},


This work is affiliated with ZJU-SenseTime Joint Lab of 3D Vision, and its intellectual property belongs to SenseTime Group Ltd.

Copyright SenseTime. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.