Models · Image retrieval

BoQ

BoQ, Bag-of-Queries (Université Laval, 2024): one descriptor per photo to find photos of the same place (place recognition, loop closure); DINOv2 ViT-B with learned queries that read out the image features. MIT code and weights.

experimental Fork of amaralibey/Bag-of-Queries@1a4965e · backends: portable, kernels

Checkpoint boq-dinov2

Paper 2024 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 2.84 ms 480x640, fp16
vs the faster original 2.6× original fp16: 7.44 ms
Peak memory 227 MiB original: 231 MiB
Accuracy vs original fp32 ±0.00 kernels r1, St Lucia (99.86 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install fastforks-core

from fastforks import retrieval

model = retrieval.load("boq-dinov2")  # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.descriptor
result.backend  # what ran: mode, device, dtype, kernels
fastforks bench boq-dinov2

Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.

Speed and memory

Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.

Input: synthetic, 480x640 (the task’s standard size)

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original fp16.half() on 1 modules, fp16 inputs; amaralibey/Bag-of-Queriesa4965ea7dfd hubconf.py, 322 x 322 bicubic antialiased resize, normalisationfp16 7.44–231 MiB/256 MiB1.30.02
Portable fp32fp32not measured ––––
Portablefp16 5.731.3×231 MiB/254 MiB0.20.23
Kernelsfp16 2.842.6×227 MiB/256 MiB1.10.13
Portable + torch.compile 3.891.9×269 MiB/274 MiB12 (build)–
TensorRT fp16fp16 2.732.7×202 MiBenginenot comparable46 (build)–

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.

Other devices

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp3263.7 1,448 MiB process–480x640
Portablefp1648.2 849 MiB processmatches480x640
Portablefp3257.2 987 MiB processmatches480x640
Kernelsfp16not implemented–480x640

CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.

Licence and weights

Commercial use allowed

Code
MIT LICENSE
Weights
MIT source
Training data

Our reading of the licences, not legal advice.

Weights

dinov2_12288.pth 381 MB· hosted on GitHub

fastforks downloads and checks these files on first use (fastforks download boq-dinov2).

Accuracy

The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.

St Lucia

all 1464 queries against the 1549 database images, recall@1 / @5 % (25 m)

Rundtyper1 ↑r5 ↑Δ r1 vs fp32 originalqueriesms / querie
Original fp32fp3299.86100.00 reference 1464 13.6
Original fp16not measured
Portable fp32not measured
Portablefp1699.86100.00 ±0.00 1464 4.57
Kernelsfp1699.86100.00 ±0.00 1464 2.88

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 authors’ code, same checkpoint and protocol. Measured on original fp32: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 84333525, 2026-11-13.

St Lucia

every 5th query (293) against the 1549 database images, recall@1 / @5 % (25 m)

Rundtyper1 ↑r5 ↑Δ r1 vs fp32 originalqueriesms / querie
Original fp32fp3299.66100.00 reference 293 13.6
Original fp16fp1699.66100.00 ±0.00 293 7.64
Portable fp32fp3299.66100.00 ±0.00 293 13.6
Portablefp1699.66100.00 ±0.00 293 5.60
Kernelsfp1699.66100.00 ±0.00 293 2.95
Original .half()fp1699.66100.00 ±0.00 293 5.66

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 authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16, original .half(): RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 84333525, 2026-11-13.

Closeness to the original

Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. 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).

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.00001 (relative)not recorded
GPU default dtypes, mean |diff|≤ 0.026 (relative)0.01726 (relative)
GPU default dtypes, p99 |diff|≤ 0.086 (relative)0.05735 (relative)

Recorded for boq-dinov2 on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: dpt_fusedfastbb

Details

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.

Input / output
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.
Input size
any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (637 MiB allocated)
Outputs
descriptor
CUDA kernels
  • fastbbfast backbone kernels: flash attention, window attention, instance norm and rotary embeddings for ViT and similar backbones
  • dpt_fusedfused fp16 matrix multiplies and convolutions for DINOv2 backbones and DPT depth heads
Apple (MPS)
fp32, fp16
Full reference, generated from the repository

BoQ, Bag-of-Queries (Université Laval, 2024): one descriptor per photo to find photos of the same place (place recognition, loop closure); DINOv2 ViT-B with learned queries that read out the image features. MIT code and weights.

Commercial use: yes.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
boq-dinov2synthetic (480x640)original
portable
kernels
portable + torch.compile
TensorRT fp16
7.44
5.73
2.84
3.89
2.73
231 / 256
231 / 254
227 / 256
269 / 274
426 / 434
Details
  • Original code: https://github.com/amaralibey/Bag-of-Queries at 1a4965ea7dfd
  • Code licence: MIT (permissive); files: LICENSE
  • Weights licence: MIT
  • Licence evidence: https://github.com/amaralibey/Bag-of-Queries/blob/1a4965ea7dfd9bd0dd846adf7a0e430f68101d12/LICENSE ; https://github.com/amaralibey/Bag-of-Queries/releases/tag/v1.0
  • 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).)
  • Kernel libraries: fastbb, dpt_fused
  • Variants: boq-dinov2
  • Outputs: descriptor
  • 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)
  • boq-dinov2 480x640, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 46 s (ONNX + engine).
  • boq-dinov2 original 480x640: .half() on 1 modules, fp16 inputs; amaralibey/Bag-of-Queriesa4965ea7dfd hubconf.py, 322 x 322 bicubic antialiased resize, normalisation
  • boq-dinov2 load / first call: original 1.22 s / 0.042 s, portable 0.24 s / 0.231 s, kernels 1.09 s / 0.134 s
  • Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5

Measured

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.

variantdatasetoriginal fp32original fp16original halfportableportable fp32kernelsnote
boq-dinov2St Lucia, all 1464 queries against the 1549 database images, recall@1 / @5 % (25 m)99.86 / 100.0099.86 / 100.0099.86 / 100.00
boq-dinov2St Lucia, every 5th query (293) against the 1549 database images, recall@1 / @5 % (25 m)99.66 / 100.0099.66 / 100.0099.66 / 100.0099.66 / 100.0099.66 / 100.0099.66 / 100.00

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

Parity

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).

variantkernels error vs original, mean / p99GPU, torchkernels used
boq-dinov20.01726 / 0.05735RTX 5060 Ti, torch 2.14.1+cu130dpt_fused@48e0065bb7cf:sm_120, fastbb@7d058322634d:sm_120

Example output

No example rendered for this checkpoint yet.