image-feature-extraction ยท vision ยท WASM ยท ~25 MB
DINOv2 turns any image into a 384-number descriptor with no labels โ but a plain vision transformer quietly hijacks a few background patches to stash global information, spiking their feature norms and muddying the local features used for dense tasks. This model adds a handful of dedicated register tokens that soak up that global state, so the patch features stay clean. Same descriptor, cleaner attention. Add a few images and watch it build a live similarity matrix; then look inside at the patch-norm map that tells the registers story. Nothing leaves your device.
| Model | onnx-community/dinov2-with-registers-small (ONNX build of facebook/dinov2-with-registers-small) |
|---|---|
| Task / pipeline | image-feature-extraction |
| Architecture | ViT-S/14 (22M params) + 4 register tokens โ 384-d image descriptor + per-patch features |
| The register idea | extra learnable tokens give the model somewhere to keep global scratch state, so patch tokens aren't hijacked (no high-norm "artifact" patches) โ Vision Transformers Need Registers, Darcet et al. 2023 |
| Training | Self-supervised (DINO + iBOT), no labels โ LVD-142M images |
| Descriptor | the [CLS] token vector (384-d), L2-normalized โ cosine = dot product |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~25 MB, cached after first load |
| License | Apache-2.0 (Meta AI) |
| Web APIs | WebAssembly, Web Workers, File API โ all Baseline widely available |
Distinct from the plain DINOv2-small demo: same task and descriptor size, but the register tokens change what the patch features look like โ compare the patch-norm maps on both pages.
Start with the sample set (two cats, two cars, a mountain, a flower) or add your own. The model embeds each image; the matrix shows the cosine similarity between every pair โ 1.00 down the diagonal, higher where two images look alike. Uploaded images never leave your browser.
The model splits the image into a grid of 14ร14-pixel patches and produces one feature vector per patch, plus a global [CLS] descriptor and 4 register tokens. Two heatmaps tell the story. Cosine-to-CLS shows which patches most define "what this image is" (the foreground). Patch norm is the punchline of the registers paper: in a plain ViT a few background patches spike to huge norms (the artifacts), but here โ with registers absorbing the global state โ the norms stay smooth. The register tokens themselves carry that global scratch state, which is why their norms sit well above a typical patch.
Register token norms (they hold the global scratch state, so they run high):
First 96 of the 384 descriptor dimensions (blue = positive, orange = negative, brighter = larger):
A general-purpose image descriptor is the vision equivalent of a text embedding โ and because DINOv2 is trained without labels, it isn't boxed into a fixed list of classes. The register variant matters wherever you rely on the local patch features, not just the global vector: cleaner patch features mean smoother attention, better dense correspondence, and fewer spurious hot-spots in background regions. At 25 MB it runs in a tab, so you can index and compare a user's own photos โ and line up regions between them โ without uploading a single one.
Two images in, one similarity number out โ plus the patch heatmap and artifact map for each.
Near-duplicate finder and reverse-image-search over a small on-device set.
Dense patch correspondence โ colour-match the same regions across two images with the clean patch features.
Retrieve the nearest image with DINOv2-registers, then label it with a ViT classifier.
The image-feature-extraction pipeline is the whole recipe; drop to the raw model for patch features:
import { pipeline, RawImage } from "@huggingface/transformers";
const extractor = await pipeline(
"image-feature-extraction",
"onnx-community/dinov2-with-registers-small",
); // downloads + caches ~25 MB once
// Simple path: one pooled 384-d descriptor per image.
const out = await extractor("cat.jpg", { pool: true });
const vec = out.tolist()[0]; // 384 numbers
// unit-normalize, then cosine similarity is just the dot product:
const norm = (v) => { const n = Math.hypot(...v); return v.map((x) => x / n); };
const sim = (a, b) => a.reduce((s, x, i) => s + x * b[i], 0);
// Deeper path: the raw model gives the per-TOKEN sequence โ [CLS] + registers + patches.
const image = await RawImage.read("cat.jpg");
const inputs = await extractor.processor(image);
const { last_hidden_state } = await extractor.model(inputs);
// last_hidden_state: [1, 1 + numRegisters + numPatches, 384].
// token 0 = [CLS]; tokens 1..numRegisters = registers; the rest = patch grid.
const nReg = extractor.model.config.num_register_tokens; // 4
This page asks the worker for the un-normalized [CLS] vector plus each patch token's norm and cosine-to-CLS, so "See inside" can show the real magnitudes and the artifact map. Inference runs in a Web Worker so building the matrix never janks the page.