DISK + LightGlue for Kornia
Register overlapping photos on a CPU with a 28.17 MB weight download. The original Kornia path downloads 52.01 MB across the DISK detector and LightGlue matcher. This package stores the detector in float32 and the matcher in float16. Kornia runs both modules in float32.
The compact package kept all 58 registrations that stock solved within five pixels across 72 HPatches pairs. It registered 60 pairs within that limit. On the 24 untouched confirmation pairs, both models solved 22. The threshold is the mean projected corner error at 640 by 480 pixels. Correspondences and fitted homographies can differ.
Match two photos
Install the tested packages in a Python 3.12 environment. The example ran on an Arm Mac CPU.
python -m pip install 'torch==2.8.0' 'kornia==0.8.2' 'pillow==12.2.0' 'safetensors==0.8.0' 'huggingface-hub==1.33.0' 'opencv-python-headless==4.12.0.88'
Save the example as match.py and run python match.py first.jpg second.jpg. The output homography maps the first resized image to the second.
import json
import os
import sys
import cv2
from huggingface_hub import hf_hub_download
import kornia.feature as features
import numpy as np
from PIL import Image
from safetensors.torch import load_file
import torch
torch.set_num_threads(4)
torch.set_num_interop_threads(1)
cv2.setNumThreads(4)
width, height = 640, 480
path = os.environ.get("LIGHTGLUE_WEIGHTS") or hf_hub_download(
"strangelab/disk-lightglue-kornia-fp16-storage", "model.safetensors", token=False
)
weights = load_file(path)
detector = features.DISK().eval()
matcher = features.LightGlue(features=None, input_dim=128).eval()
for prefix, network in (("disk.", detector), ("lightglue.", matcher)):
parameters = {name.removeprefix(prefix): tensor for name, tensor in weights.items()
if name.startswith(prefix)}
network.load_state_dict(parameters, strict=True)
images = []
for filename in sys.argv[1:3]:
with Image.open(filename) as image:
images.append(np.asarray(image.convert("RGB").resize((width, height), Image.Resampling.BILINEAR)))
batch = torch.from_numpy(np.stack(images)).permute(0, 3, 1, 2).float().div(255)
with torch.inference_mode():
points = detector(batch, n=2048, pad_if_not_divisible=True)
inputs = {
f"image{index}": {
"keypoints": item.keypoints[None],
"descriptors": item.descriptors[None],
"image_size": torch.tensor([[width, height]], dtype=torch.float32),
}
for index, item in enumerate(points)
}
matches = matcher(inputs)["matches"][0]
sources = points[0].keypoints[matches[:, 0]].numpy()
targets = points[1].keypoints[matches[:, 1]].numpy()
homography, inliers = None, None
if len(matches) >= 4:
cv2.setRNGSeed(3011)
homography, inliers = cv2.findHomography(
sources, targets, cv2.RANSAC, 3, maxIters=5000, confidence=0.999
)
print(json.dumps({
"matches": len(matches),
"inliers": int(inliers.sum()) if inliers is not None else 0,
"homography": homography.tolist() if homography is not None else None,
}))
Sources
The detector comes from DISK depth, and the matcher comes from LightGlue's DISK release. Both licenses are included. DISK depth · LightGlue release · Kornia docs · HPatches evaluation data
The Transformers checkpoint has a separate configuration and loader. Use the Kornia recipe above for this package. Transformers checkpoint