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
- Paper BoQ: A Place is Worth a Bag of Learnable Queries CVPR 2024 · first released 12 May 2024
Checkpoint boq-dinov2
Paper 2024 Added in 0.2.0 Evaluated with 0.2.0
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)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original fp16.half() on 1 modules, fp16 inputs; amaralibey/Bag-of-Queriesa4965ea7dfd hubconf.py, 322 x 322 bicubic antialiased resize, normalisation | fp16 | 7.44 | – | 231 MiB/256 MiB | 1.3 | 0.02 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 5.73 | 1.3× | 231 MiB/254 MiB | 0.2 | 0.23 |
| Kernels | fp16 | 2.84 | 2.6× | 227 MiB/256 MiB | 1.1 | 0.13 |
| Portable + torch.compile | 3.89 | 1.9× | 269 MiB/274 MiB | 12 (build) | – | |
| TensorRT fp16 | fp16 | 2.73 | 2.7× | 202 MiBenginenot comparable | 46 (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
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | 63.7 | 1,448 MiB process | – | 480x640 |
| Portable | fp16 | 48.2 | 849 MiB process | matches | 480x640 | |
| Portable | fp32 | 57.2 | 987 MiB process | matches | 480x640 | |
| Kernels | fp16 | not 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
Our reading of the licences, not legal advice.
Weights
dinov2_12288.pth 381 MB· hosted on GitHubfastforks 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)
| Run | dtype | r1 ↑ | r5 ↑ | Δ r1 vs fp32 original | queries | ms / querie |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 99.86 | 100.00 | reference | 1464 | 13.6 |
| Original fp16 | not measured | |||||
| Portable fp32 | not measured | |||||
| Portable | fp16 | 99.86 | 100.00 | ±0.00 | 1464 | 4.57 |
| Kernels | fp16 | 99.86 | 100.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)
| Run | dtype | r1 ↑ | r5 ↑ | Δ r1 vs fp32 original | queries | ms / querie |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 99.66 | 100.00 | reference | 293 | 13.6 |
| Original fp16 | fp16 | 99.66 | 100.00 | ±0.00 | 293 | 7.64 |
| Portable fp32 | fp32 | 99.66 | 100.00 | ±0.00 | 293 | 13.6 |
| Portable | fp16 | 99.66 | 100.00 | ±0.00 | 293 | 5.60 |
| Kernels | fp16 | 99.66 | 100.00 | ±0.00 | 293 | 2.95 |
| Original .half() | fp16 | 99.66 | 100.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).
| Check | Tolerance | Measured |
|---|---|---|
| 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_kandpairsfind 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 backbonesdpt_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.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
boq-dinov2 | synthetic (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-dinov23000x4000 (0.6 GiB peak allocated, 0.6 reserved) boq-dinov2480x640, first call: portable + torch.compile 12 s (cold Inductor cache), TensorRT fp16 46 s (ONNX + engine).boq-dinov2original 480x640: .half() on 1 modules, fp16 inputs; amaralibey/Bag-of-Queriesa4965ea7dfd hubconf.py, 322 x 322 bicubic antialiased resize, normalisationboq-dinov2load / 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.
| variant | dataset | original fp32 | original fp16 | original half | portable | portable fp32 | 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 | 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
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).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
boq-dinov2 | 0.01726 / 0.05735 | RTX 5060 Ti, torch 2.14.1+cu130 | dpt_fused@48e0065bb7cf:sm_120, fastbb@7d058322634d:sm_120 |
Example output
No example rendered for this checkpoint yet.