โ† All models

image-feature-extraction ยท vision ยท WASM ยท ~24 MB

DINOv2-small โ€” turn any image into a vector you can compare

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.

At a glance

ModelXenova/dinov2-small (ONNX build of facebook/dinov2-small)
Task / pipelineimage-feature-extraction
ArchitectureViT-S/14 vision transformer (22M params) โ†’ 384-d image descriptor + per-patch features
TrainingSelf-supervised (DINO + iBOT), no labels โ€” LVD-142M images
Descriptorthe [CLS] token vector (384-d), L2-normalized โ†’ cosine = dot product
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~24 MB, cached after first load
LicenseApache-2.0 (Meta AI)
Web APIsWebAssembly, Web Workers, File API โ€” all Baseline widely available

Run it โ€” image similarity matrix

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.

See inside โ€” the descriptor & the patch-feature grid

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.

Embed some images to inspect their features.

Why it matters

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.

Use cases

Basics

Two images in, one similarity number out โ€” plus the patch heatmap for each.

Practical

Near-duplicate finder and reverse-image-search over a small on-device set.

Wild

Odd-one-out and gallery clustering โ€” group a pile of images by look, no labels.

Multi-model

DINOv2 image vectors beside MiniLM text vectors โ€” two modalities, one similarity idea.

How the API works

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.

References