object-detection Β· vision WASM q8 Β· 56.96 MB Pure ViT-Small Β· 100 [DET] tokens Apache-2.0

YOLOS-Small β€” Pure Vision Transformer Object Detector

You Only Look at One Sequence replaces both the CNN backbone and the Transformer decoder with a single 12-layer ViT-Small encoder: an image is sliced into 16Γ—16 patches, concatenated with 100 learnable [DET] tokens, and self-attended globally across 80 COCO classes. Everything runs on your device via Transformers.js (pipeline("object-detection"), CPU WASM q8).

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.

Backend / dtype–
Inference latency–
ViT patches (16Γ—16)–
Sequence tokens–
Candidates β‰₯ 0.15–
Shown–
Non-finite outputs–
Per-class counts above the threshold
ClassGroupCountBest scoreMean score
Run the detector to fill this table.
Every box shown (pixel coordinates of the analysed frame)
#ClassScoreBox [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

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", "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 } }, …]

References