image-feature-extraction ยท vision ยท WASM ยท ~24 MB
No labels, no text, no prompt. DINOv2 is a self-supervised vision transformer: it learned to describe images just by looking at millions of them. Feed it a picture and it returns a 384-number descriptor where visually-and-semantically similar images sit close together. Add a few images below and watch it build a live similarity matrix. Nothing leaves your device.
| Model | Xenova/dinov2-small (ONNX build of facebook/dinov2-small) |
|---|---|
| Task / pipeline | image-feature-extraction |
| Architecture | ViT-S/14 vision transformer (22M params) โ 384-d image descriptor + per-patch features |
| 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 | ~24 MB, cached after first load |
| License | Apache-2.0 (Meta AI) |
| Web APIs | WebAssembly, Web Workers, File API โ all Baseline widely available |
Start with the sample set (two cats, two cars, a mountain, a flower) or add your own. DINOv2 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.
DINOv2 splits the image into a grid of 14ร14-pixel patches and produces one feature vector per patch, plus a global [CLS] descriptor. The heatmap overlays each patch's cosine similarity to that global descriptor โ bright patches are the regions that most define "what this image is", which is why DINOv2 features segment the foreground object without ever being told what it is.
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. Once an image is a vector, "do these look alike?" is a distance you can compute, with no training and no server. At 24 MB it runs in a tab, so you can index and compare a user's own photos without uploading a single one.
Two images in, one similarity number out โ plus the patch heatmap for each.
Near-duplicate finder and reverse-image-search over a small on-device set.
Odd-one-out and gallery clustering โ group a pile of images by look, no labels.
DINOv2 image vectors beside MiniLM text vectors โ two modalities, one similarity idea.
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",
"Xenova/dinov2-small",
); // downloads + caches ~24 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-PATCH grid too (this page uses it for "See inside").
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 + numPatches, 384] โ token 0 is [CLS], the rest are patches.
This page asks the worker for the un-normalized [CLS] vector so "See inside" can show the real pre-normalization magnitude, then normalizes in JS. Inference runs in a Web Worker so building the matrix never janks the page.