object-detection · vision WASM q8 · 44.33 MB discrete sampling · 300 queries Apache-2.0

RT-DETRv2 R50vd — Live Discrete-Sampling Object Detector

Baidu's RT-DETRv2 pairs a ResNet-50-vd backbone (depths [3, 4, 6, 3]) with a selective multi-scale discrete sampling decoder and a bag-of-freebies training recipe — replacing v1's grid_sample operator so the graph exports cleanly to ONNX and runs 80-class NMS-free COCO object detection entirely in your browser via CPU WebAssembly.

At a glance

Upstream model PekingU/rtdetr_v2_r50vd (Lv et al. 2024, arXiv:2407.17140)
Browser ONNX repo onnx-community/rtdetr_v2_r50vd-ONNX → onnx/model_quantized.onnx
Pipeline task object-detection (Transformers.js pipeline("object-detection", "onnx-community/rtdetr_v2_r50vd-ONNX"))
Architecture RtDetrV2ForObjectDetection (rt_detr_v2): ResNet-50-vd (depths: [3, 4, 6, 3]) → hybrid encoder (strides [8, 16, 32]) → 6-layer selective multi-scale discrete sampling decoder (3 levels, 4 points, 300 queries, 640×640 input)
Output shape Array of { label, score, box: { xmin, ymin, xmax, ymax } } in pixel coordinates (percentage: false) — NMS-free one-to-one set prediction
Quantization & size q8: 44.33 MB (44,326,915 B; fp16 86.48 MB · fp32 172.31 MB not used here)
Runtime & backend Shared lib/webai.js Transformers.js 3.7.5 · CPU WASM in a module Web Worker (no WebGPU required)
Labels 80 COCO classes, preserving checkpoint spellings (sofa, tvmonitor, diningtable, pottedplant, motorbike, aeroplane)
License Apache-2.0

Live detection lab

One forward pass collects every candidate scoring ≥ 0.15, so dragging the confidence slider or toggling class groups re-filters the cached detections immediately without re-running the worker.

Loading a curated zero-person scene…

Select a box to inspect its query rank, stride level, and pixel coordinates.

Backend / dtype–
Inference–
Candidates ≥ 0.15–
Shown–
Classes–
Same-class dupes (IoU > 0.5)–
Non-finite outputs–
Multi-scale query allocation across active boxes (S8 / S16 / S32)
Feature stride640×640 footprintActive boxesMean score
Run the detector to inspect feature-scale allocation.
Per-class counts above the threshold
ClassGroupCountBest scoreMean score
Run the detector to fill this table.
Query & scale inspector — every active box
Query rankClassScoreScale / strideBox [x1, y1, x2, y2]Size
No detections yet.

See inside — discrete sampling & selective multi-scale queries

In RT-DETR v1, deformable cross-attention relied on continuous bilinear grid_sample across encoder feature maps, which triggers custom-op fallbacks or precision drift in quantized ONNX runtimes. RT-DETRv2 replaces that operator with discrete sampling (disable_custom_kernels: true, decoder_n_levels: 3, decoder_n_points: 4) and tunes per-scale sampling point budgets across the ResNet-50-vd strides ([8, 16, 32]) together with a bag-of-freebies training recipe (dynamic augmentation and scale-adaptive hyperparameters).

Combined with one-to-one Hungarian matching across 300 queries, RT-DETRv2 keeps the exact same inference budget as RT-DETR R50vd (44.33 MB vs 45.46 MB q8) while improving small-object localisation and ONNX portability.

Show the code — epoch-guarded pipeline load in the Web Worker
Show the code — mapping each box to its RT-DETRv2 hybrid-encoder stride

Use-case ladder

How the API works

import { TRANSFORMERS_URL } from "/lib/webai.js"; // Transformers.js 3.7.5
const { pipeline } = await import(TRANSFORMERS_URL);

const detector = await pipeline("object-detection", "onnx-community/rtdetr_v2_r50vd-ONNX", {
  dtype: "q8",    // onnx/model_quantized.onnx, 44.33 MB
  device: "wasm", // CPU WebAssembly inside a module Worker
});

const boxes = await detector(image, { threshold: 0.15, percentage: false });
// → [{ label: "bed", score: 0.94, box: { xmin, ymin, xmax, ymax } }, …] — NMS-free

References