MegaLoc (fastforks)

MegaLoc (Berton and Masone, CVPR 2025 workshops): one image-retrieval model for visual place recognition, landmark retrieval and structure-from-motion pair selection. A DINOv2 ViT-B/14 fine-tuned on a mix of place-recognition, landmark and SfM datasets; its patch features are assigned to 64 clusters by optimal transport (SALAD-style aggregation) and projected to an 8448-d unit descriptor.

This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/gmberton/MegaLoc at 5fe0dd697c4a.

Author weight repos: https://huggingface.co/gberton/MegaLoc.

Task: retrieval. Tier: experimental. Outputs: descriptor. Backends: portable, kernels.

Input: one RGB image. Output: a global descriptor [D] (unit L2 norm) for image retrieval / visual place recognition; fastforks.retrieval.top_k and pairs find the nearest images (cosine similarity) on the GPU.

Variants

Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.

variant weights (author link) SHA-256 weights licence commercial use
megaloc@1 megaloc.safetensors d4f9f2bcb600 MIT yes

Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: MIT. Licence files: LICENSE.

Training data: LVD-142M (DINOv2's curated web-image set, not released), GSV-Cities (Google Street View images of 62k places in 40 cities), Mapillary Street-Level Sequences, MegaScenes (Internet photo collections of scenes from Wikimedia Commons), ScanNet (RGB-D scans of indoor scenes), San Francisco eXtra Large (street-view images of San Francisco) (Fine-tuned from DINOv2 ViT-B/14 (LVD-142M) on GSV-Cities, MSLS, MegaScenes, ScanNet and SF-XL (paper, arXiv 2502.17237, Sec. 2); MSLS and ScanNet carry non-commercial terms. Only the weights licence (MIT) counts for the commercial flag.).

Licence evidence: https://github.com/gmberton/MegaLoc/blob/5fe0dd697c4a70ba3e23607f6716ab3c606b16db/LICENSE ; https://huggingface.co/gberton/MegaLoc/blob/a0f34722c4297ff787e022433799250180860af7/README.md

Input size

any H x W >= 32, padded to a multiple of 32 Tested up to (portable, fp16, RTX 5060 Ti 16 GB): megaloc 3000x4000 (0.9 GiB peak allocated, 0.9 reserved)

Speed and memory

Retrieval, synthetic, 480x640

model time (ms): original portable kernels kernels speed-up: vs original vs portable peak memory (MiB, allocated / reserved): original portable kernels
megaloc 9.68 5.29 4.26 2.3x 1.2x 1347 / 1368 483 / 508 485 / 508

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
megaloc 2.49 0.50 1.36 0.56 0.37 0.22

torch.compile and TensorRT

model input time: portable compile TensorRT fp16 kernels preparation: compile (cold first call) ONNX + engine build peak MiB (alloc / reserved): portable compile kernels TensorRT (engine + torch)
megaloc 480x640 5.29 ms 4.27 ms 3.21 ms 4.26 ms 13.2 s 51.1 s 483 / 508 518 / 530 485 / 508 937 / 964

Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).

Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.

Accuracy

On public datasets

Every query's descriptor against every database descriptor (cosine similarity, exact top-k on the GPU); a query counts as found at k when one of its k nearest database images is within 25 m (UTM positions of the file names), the standard visual place recognition protocol. Original = the original code named under Details, same checkpoint and protocol.

variant dataset original fp32 original fp16 portable kernels note
megaloc St Lucia, all 1464 queries against the 1549 database images, recall@1 / @5 % (25 m) 100.00 / 100.00 100.00 / 100.00 100.00 / 100.00
megaloc St Lucia, every 5th query (293) against the 1549 database images, recall@1 / @5 % (25 m) 100.00 / 100.00 100.00 / 100.00 100.00 / 100.00 100.00 / 100.00

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 84333525, 2026-11-13.

Parity with the original code

Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 8.8e-08 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 2.1 % and p99 <= 6.6 % of the reference's median |value| (absolute error of the output descriptor).

Usage

from fastforks import retrieval

model = retrieval.load("megaloc")  # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.descriptor  # [D] float32, unit norm
# fastforks.retrieval.top_k(queries, database, k=5): the nearest database images
result.backend  # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')

Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: megaloc.

Kernels backend

retrieval.load("megaloc", mode="kernels") runs our CUDA kernels (fastbb, dpt_fused). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Collection including fastforks/megaloc