LightGlue

cvgApache-2.0活跃维护

LightGlue 是一个基于 Transformer 的轻量级局部特征匹配网络,速度快、精度高,适合 SLAM、三维重建和位姿估计等需要实时图像匹配的场景。

LightGlue: Local Feature Matching at Light Speed (ICCV 2023)

v0.2发布于 2024-06-20 21:37 UTC4,871star +5 / 7 天579fork同步于 2026-11-10 23:37 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/cvg/LightGlue.git && cd LightGlue
python -m pip install -e .
硬件要求按 README 说明

README 未给出显存要求;示例代码默认 .cuda(),需 NVIDIA GPU,基准测试用 RTX 3080;也支持 CPU 运行,Intel i7 10700K 上 512 关键点约 20 FPS。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

轻量级稀疏局部特征匹配网络,输入两张图的关键点与描述子,快速输出对应点索引

LightGlue 是一个基于 Transformer 的轻量级局部特征匹配网络,速度快、精度高,适合 SLAM、三维重建和位姿估计等需要实时图像匹配的场景。

核心能力

  • 用自适应深度早停与宽度剪枝降低计算量
  • 支持 SuperPoint、DISK、ALIKED、SIFT 等特征
  • 集成 FlashAttention 与混合精度推理加速
  • 提供 match_pair 便捷接口一次完成匹配
  • 可导出 ONNX 并接入 kornia、hloc 生态

容易踩的坑

示例代码默认调用 .cuda(),无 GPU 时需手动改为 CPU;首次运行会自动下载预训练权重,需联网;SuperPoint 及其权重采用限制性许可,商用前需确认;FlashAttention 与 torch.compile 需 torch>=2.0 才能启用。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

2 个版本v0.2
  1. v0.2pre-release最新正式版2024-06-20 · 2024-06-20 21:37 UTC

    Release for conda, see #129.

  2. v0.1_arxivpre-release2023-06-26 · 2023-06-26 00:42 UTC
    查看更新说明

    Initial Release with SIFT, DISK, ALIKED, SuperPoint and DogHardNet (thanks to @ducha-aiki) extractors.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    This repository hosts the inference code of LightGlue, a lightweight feature matcher with high accuracy and blazing fast inference. It takes as input a set of keypoints and descriptors for each image and returns the indices of corresponding points. The architecture is based on adaptive pruning techniques, in both network width and depth - check out the paper for more details.

    We release pretrained weights of LightGlue with SuperPoint, DISK, ALIKED and SIFT local features. The training and evaluation code can be found in our library glue-factory.

    LightGlue is now part of 🤗 Hugging Face Transformers (credit to @sbucaille!). It enables easy inference in a few lines of Python code, using pip install transformers (model card).

    Installation and demo Open In Colab

    Install this repo using pip:

    git clone https://github.com/cvg/LightGlue.git && cd LightGlue
    python -m pip install -e .
    

    We provide a demo notebook which shows how to perform feature extraction and matching on an image pair.

    Here is a minimal script to match two images:

    from lightglue import LightGlue, SuperPoint, DISK, SIFT, ALIKED, DoGHardNet
    from lightglue.utils import load_image, rbd
    
    # SuperPoint+LightGlue
    extractor = SuperPoint(max_num_keypoints=2048).eval().cuda()  # load the extractor
    matcher = LightGlue(features='superpoint').eval().cuda()  # load the matcher
    
    # or DISK+LightGlue, ALIKED+LightGlue or SIFT+LightGlue
    extractor = DISK(max_num_keypoints=2048).eval().cuda()  # load the extractor
    matcher = LightGlue(features='disk').eval().cuda()  # load the matcher
    
    # load each image as a torch.Tensor on GPU with shape (3,H,W), normalized in [0,1]
    image0 = load_image('path/to/image_0.jpg').cuda()
    image1 = load_image('path/to/image_1.jpg').cuda()
    
    # extract local features
    feats0 = extractor.extract(image0)  # auto-resize the image, disable with resize=None
    feats1 = extractor.extract(image1)
    
    # match the features
    matches01 = matcher({'image0': feats0, 'image1': feats1})
    feats0, feats1, matches01 = [rbd(x) for x in [feats0, feats1, matches01]]  # remove batch dimension
    matches = matches01['matches']  # indices with shape (K,2)
    points0 = feats0['keypoints'][matches[..., 0]]  # coordinates in image #0, shape (K,2)
    points1 = feats1['keypoints'][matches[..., 1]]  # coordinates in image #1, shape (K,2)
    

    We also provide a convenience method to match a pair of images:

    from lightglue import match_pair
    feats0, feats1, matches01 = match_pair(extractor, matcher, image0, image1)
    

    Advanced configuration

    • n_layers: Number of stacked self+cross attention layers. Reduce this value for faster inference at the cost of accuracy (continuous red line in the plot above). Default: 9 (all layers).
    • flash: Enable FlashAttention. Significantly increases the speed and reduces the memory consumption without any impact on accuracy. Default: True (LightGlue automatically detects if FlashAttention is available).
    • mp: Enable mixed precision inference. Default: False (off)
    • depth_confidence: Controls the early stopping. A lower values stops more often at earlier layers. Default: 0.95, disable with -1.
    • width_confidence: Controls the iterative point pruning. A lower value prunes more points earlier. Default: 0.99, disable with -1.
    • filter_threshold: Match confidence. Increase this value to obtain less, but stronger matches. Default: 0.1

    The default values give a good trade-off between speed and accuracy. To maximize the accuracy, use all keypoints and disable the adaptive mechanisms:

    extractor = SuperPoint(max_num_keypoints=None)
    matcher = LightGlue(features='superpoint', depth_confidence=-1, width_confidence=-1)
    

    To increase the speed with a small drop of accuracy, decrease the number of keypoints and lower the adaptive thresholds:

    extractor = SuperPoint(max_num_keypoints=1024)
    matcher = LightGlue(features='superpoint', depth_confidence=0.9, width_confidence=0.95)
    

    The maximum speed is obtained with a combination of:

    matcher = matcher.eval().cuda()
    matcher.compile(mode='reduce-overhead')
    

    For inputs with fewer than 1536 keypoints (determined experimentally), this compiles LightGlue but disables point pruning (large overhead). For larger input sizes, it automatically falls backs to eager mode with point pruning. Adaptive depths is supported for any input size.

    Benchmark

    Obtain the same plots for your setup using our benchmark script:

    python benchmark.py [--device cuda] [--add_superglue] [--num_keypoints 512 1024 2048 4096] [--compile]
    

    Note: Point pruning introduces an overhead that sometimes outweighs its benefits. Point pruning is thus enabled only when the there are more than N keypoints in an image, where N is hardware-dependent. We provide defaults optimized for current hardware (RTX 30xx GPUs). We suggest running the benchmark script and adjusting the thresholds for your hardware by updating LightGlue.pruning_keypoint_thresholds['cuda'].

    Training and evaluation

    With Glue Factory, you can train LightGlue with your own local features, on your own dataset! You can also evaluate it and other baselines on standard benchmarks like HPatches and MegaDepth.

    Other links

    BibTeX citation

    If you use any ideas from the paper or code from this repo, please consider citing:

    @inproceedings{lindenberger2023lightglue,
      author    = {Philipp Lindenberger and
                   Paul-Edouard Sarlin and
                   Marc Pollefeys},
      title     = {{LightGlue: Local Feature Matching at Light Speed}},
      booktitle = {ICCV},
      year      = {2023}
    }
    

    License

    The pre-trained weights of LightGlue and the code provided in this repository are released under the Apache-2.0 license. DISK follows this license as well but SuperPoint follows a different, restrictive license (this includes its pre-trained weights and its inference file). ALIKED was published under a BSD-3-Clause license.