colmap icon indicating copy to clipboard operation
colmap copied to clipboard

Add ALIKED/LightGlue feature based on libtorch

Open ahojnnes opened this issue 1 year ago • 9 comments

  • Adds support for extracting ALIKED features.
  • Adds support for matching ALIKED features using simple dot-product based nearest neighbor search.
  • Adds support for matching ALIKED and SIFT using LightGlue.

ahojnnes avatar Dec 21 '24 09:12 ahojnnes

Does this mean no need for SIFT anymore?

behnamasadi avatar Jan 27 '25 13:01 behnamasadi

@MrNeRF We found two necessary fixes that you may want to also apply to your upstream version: https://github.com/colmap/colmap/pull/3068/commits/a6c360a33b6255682fef4778990311b6d0cb6c18 and https://github.com/colmap/colmap/pull/3068/commits/1bd573c55fb4a44112453e2ec99b804addce7d9d

ahojnnes avatar Apr 10 '25 10:04 ahojnnes

Oh cool! Thanks for pinging me.

MrNeRF avatar Apr 10 '25 12:04 MrNeRF

@MrNeRF Do you have an example for how you converted the original lightglue .pth files to your .pt files? I am trying to also convert the SIFT model but cannot get it to be in the same format. Thanks.

ahojnnes avatar Apr 14 '25 08:04 ahojnnes

@MrNeRF Do you have an example for how you converted the original lightglue .pth files to your .pt files? I am trying to also convert the SIFT model but cannot get it to be in the same format. Thanks.

Try

from collections import OrderedDict
import torch

modelname = "sift_lightglue"
filename = modelname + ".pth"
checkpoint = torch.load(filename, map_location="cpu")

# Convert to a plain dict
if isinstance(checkpoint, OrderedDict):
    checkpoint = dict(checkpoint)

print(type(checkpoint))  # Now <class 'dict'>

# Save the result as a standard dict
torch.save(checkpoint, modelname + ".pt")

yimingc avatar Apr 14 '25 19:04 yimingc

@MrNeRF Do you have an example for how you converted the original lightglue .pth files to your .pt files? I am trying to also convert the SIFT model but cannot get it to be in the same format. Thanks.

Try

from collections import OrderedDict
import torch

modelname = "sift_lightglue"
filename = modelname + ".pth"
checkpoint = torch.load(filename, map_location="cpu")

# Convert to a plain dict
if isinstance(checkpoint, OrderedDict):
    checkpoint = dict(checkpoint)

print(type(checkpoint))  # Now <class 'dict'>

# Save the result as a standard dict
torch.save(checkpoint, modelname + ".pt")

Yeah! Beside heavily using the C++ debugger and asserts, I didn't do anything smart or fancy. Basically just this.

MrNeRF avatar Apr 15 '25 06:04 MrNeRF

@MrNeRF Do you have an example for how you converted the original lightglue .pth files to your .pt files? I am trying to also convert the SIFT model but cannot get it to be in the same format. Thanks.

Try

from collections import OrderedDict
import torch

modelname = "sift_lightglue"
filename = modelname + ".pth"
checkpoint = torch.load(filename, map_location="cpu")

# Convert to a plain dict
if isinstance(checkpoint, OrderedDict):
    checkpoint = dict(checkpoint)

print(type(checkpoint))  # Now <class 'dict'>

# Save the result as a standard dict
torch.save(checkpoint, modelname + ".pt")

Yeah! Beside heavily using the C++ debugger and asserts, I didn't do anything smart or fancy. Basically just this.

Thank you.

ahojnnes avatar Apr 16 '25 13:04 ahojnnes

It seems LiftFeat is approximately twice as fast as ALIKED and also achieves higher accuracy. It's also designed to handle challenging scenarios such as drastic lighting changes, low-texture regions, and repetitive patterns. Maybe consider switching from ALIKED to LiftFeat or adding both?

xiemeilong avatar May 09 '25 05:05 xiemeilong

I'm really interested in this, Looking forward to see this PR merged soon! Are there any problem blocking this PR?

Ben-Mack avatar May 26 '25 07:05 Ben-Mack

Colmap ALIKED + Lightglue produces worse result than hloc.

HLOC ALIKED + Lightglue with default parameters image

colmap ALIKED + Lightglue with default parameters(not all images registered) image

colmap ALIKED + Lightglue with --ALIKEDExtraction.max_image_size 1024 --ALIKEDMatching.min_similarity 0.1 image

xiemeilong avatar Jun 24 '25 02:06 xiemeilong

@xiemeilong Thanks for the feedback. There are still some known issues related to torch under Windows that I cannot root cause. I am not sure if these hint at some larger issues also on other platforms. On which platform did you run this comparison? Unrelated to these issues, the current colmap implementation does not auto-rotate the images to be upright (e.g., based on EXIF image orientation information). ALIKED/LightGlue only work reliably up to ~45deg rotation change between images. Can it be that your images are inconsistently rotated?

ahojnnes avatar Jul 07 '25 11:07 ahojnnes

@ahojnnes I tested this on Linux, and all images orientations are same. I found that LightGlue doesn't work well with aliked-n32 in my tests, hloc uses aliked-n16 by default.

xiemeilong avatar Jul 08 '25 02:07 xiemeilong