At a glance
| Upstream model | hustvl/yolos-small (HUST Vision Lab, Fang et al. 2021) |
|---|---|
| Browser ONNX repo | Xenova/yolos-small β onnx/model_quantized.onnx |
| Pipeline task | object-detection (Transformers.js pipeline("object-detection", "Xenova/yolos-small")) |
| Architecture | YolosForObjectDetection (yolos): pure ViT-Small encoder (384d, 6 heads, 12 layers, 30.7M params), 16Γ16 patches + 1 [CLS] + 100 [DET] tokens β no CNN backbone, no decoder |
| Preprocessor & scaling | YolosFeatureExtractor resizes shortest edge to 800 px (longest β€ 1333 px), generating ~3,000β4,100 patches with O(NΒ²) global self-attention |
| Quantization & size | q8: 56.96 MB (fp16 61.75 MB Β· fp32 123.02 MB not loaded here) |
| Runtime & backend | Shared lib/webai.js Transformers.js 3.7.5 Β· CPU WASM in a module Web Worker |
| License | Apache-2.0 |
Live ViT object detector
Honest CPU WASM latency: at its default 800 px short-edge input, YOLOS-Small self-attends
globally across ~3,300+ patches + 100 [DET] tokens in all 12 layers, which typically takes
~12β17 s per frame on CPU WebAssembly (far heavier than CNN/hybrid detectors like D-FINE or
YOLOS-Tiny). One forward pass caches all candidates β₯ 0.15 so threshold and class filters update
instantly; try the Wild O(NΒ²) Lab to measure downscaled speeds live.
Loading a sample photoβ¦
Select a box to see its exact coordinates and patch coverage.
| Class | Group | Count | Best score | Mean score |
|---|---|---|---|---|
| Run the detector to fill this table. | ||||
| # | Class | Score | Box [x1, y1, x2, y2] | Size |
|---|---|---|---|---|
| No detections yet. | ||||
See inside β pure ViT sequence with 100 [DET] tokens
DETR and RT-DETR rely on a convolutional ResNet backbone to shrink an image into a compact feature grid, then
cross-attend a Transformer decoder over those features. YOLOS-Small drops both stages: it
splits the 800 px short-side image directly into βW/16β Γ βH/16β non-overlapping 16Γ16 RGB
patches, appends 100 learned [DET] embeddings to the end of the sequence, and runs
12 standard ViT-Small self-attention blocks.
Because every patch and every [DET] token attends to every other token in all 12 layers, compute
scales quadratically as O((1 + Npatches + 100)Β²) β which is why YOLOS-Small takes
~12β17 s at 800 px on CPU WASM yet finishes in ~1.2 s when downscaled to 320 px.
Show the code β epoch-guarded YOLOS-Small pipeline load in the Web Worker
Show the code β ViT 16Γ16 patch grid and O(NΒ²) token sequence math
Why YOLOS-Small matters
- Architectural purity β proves a vanilla ImageNet-pretrained ViT-Small encoder can localise 80 COCO classes with zero convolutions and zero decoder layers.
- Stronger accuracy than YOLOS-Tiny β 384d / 6 heads / 30.7M params improves small-object recall and localisation over the 6.5M Tiny checkpoint while staying 56.96 MB in
q8. - Transparent scaling trade-off β inspecting patch count vs WASM latency makes the real quadratic cost of global ViT attention visible on your own hardware.
Use-case ladder
Basics
Explore the 16Γ16 patch grid, 100 [DET] tokens, threshold calibration, and greedy-NMS overlap audit.
Practical
Queue a batch of photos, track a target-class checklist and scene density, and export formula-safe CSV or COCO JSON.
Wild
Measure the live O(NΒ²) latency curve across 320β800 px and stress-test detections under low light, blur, and crop.
Multi-model
Chain YOLOS-Small + Depth Anything v2 Small to rank every detected object from foreground to background.
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", "Xenova/yolos-small", {
dtype: "q8", // onnx/model_quantized.onnx, 56.96 MB
device: "wasm", // CPU WebAssembly inside a Web Worker
});
const boxes = await detector(image, { threshold: 0.15, percentage: false });
// β [{ label: "bed", score: 0.94, box: { xmin, ymin, xmax, ymax } }, β¦]