BoQ (fastforks)
BoQ, Bag-of-Queries (Ali-bey, Chaib-draa and Giguère, CVPR 2024): visual place recognition. A DINOv2 ViT-B/14 (last two blocks fine-tuned on GSV-Cities); its patch features are projected by a 3x3 convolution, refined by two transformer encoder layers and read out by two sets of 64 learned queries with cross-attention, then projected to a 12288-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/amaralibey/Bag-of-Queries at 1a4965ea7dfd.
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 |
|---|---|---|---|---|
boq-dinov2@1 |
dinov2_12288.pth | d72ee0ce899e |
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) (DINOv2 ViT-B/14 (LVD-142M) with its last two blocks and the aggregator trained on GSV-Cities at 320 x 320 (README, Training).).
Licence evidence: https://github.com/amaralibey/Bag-of-Queries/blob/1a4965ea7dfd9bd0dd846adf7a0e430f68101d12/LICENSE ; https://github.com/amaralibey/Bag-of-Queries/releases/tag/v1.0
Input size
any H x W >= 32, padded to a multiple of 32
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): boq-dinov2 3000x4000 (0.6 GiB peak allocated, 0.6 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 |
|---|---|---|---|---|---|---|---|---|
boq-dinov2 |
7.44 | 5.73 | 2.84 | 2.6x | 2.0x | 231 / 256 | 231 / 254 | 227 / 256 |
Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|---|---|---|---|---|---|---|
boq-dinov2 |
1.22 | 0.24 | 1.09 | 0.04 | 0.23 | 0.13 |
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) |
|---|---|---|---|---|---|---|---|---|---|---|---|
boq-dinov2 |
480x640 | 5.73 ms | 3.89 ms | 2.73 ms | 2.84 ms | 11.8 s | 46.4 s | 231 / 254 | 269 / 274 | 227 / 256 | 426 / 434 |
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 |
|---|---|---|---|---|---|---|
boq-dinov2 |
St Lucia, all 1464 queries against the 1549 database images, recall@1 / @5 % (25 m) | 99.86 / 100.00 | 99.86 / 100.00 | 99.86 / 100.00 | ||
boq-dinov2 |
St Lucia, every 5th query (293) against the 1549 database images, recall@1 / @5 % (25 m) | 99.66 / 100.00 | 99.66 / 100.00 | 99.66 / 100.00 | 99.66 / 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| <= 1e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 2.6 % and p99 <= 8.6 % of the reference's median |value| (absolute error of the output descriptor).
Usage
from fastforks import retrieval
model = retrieval.load("boq-dinov2") # 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: boq-dinov2.
Kernels backend
retrieval.load("boq-dinov2", 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.