zero-shot-image-classification · text→image retrieval · WASM · ~606 MB
CLIP learns a shared space for images and text, so you can search a collection of pictures with a sentence. Fashion-CLIP is a CLIP model fine-tuned on fashion pairs. This demo embeds a small catalog once, then ranks it against your free-text query — every score is a real cosine similarity, computed on your device.
| Model | patrickjohncyh/fashion-clip |
|---|---|
| Task | zero-shot-image-classification — used here as text→image retrieval (CLIP) |
| Architecture | CLIP — BERT-style text encoder (512-d) + ViT-style vision encoder (768-d) with projection heads, fine-tuned on fashion pairs |
| Artifact / revision | onnx/model.onnx · fp32 · exactly 605,804,513 bytes (578 MiB) · immutable revision 7e3ba62ce16b… — pinned to the same revision as the FashionCLIP classification demo, so one download serves both |
| Backend | WebAssembly (CPU) — no GPU required |
| Download | ~578 MiB, cached after first load |
| License | MIT |
| Web APIs | Web Workers, Cache Storage (via Transformers.js), WebAssembly |
catalog ranked by similarity — green border = best match
Every image and every query becomes a vector (512-dim after projection). The rank is the cosine similarity between the query vector and each image vector — 1.0 means identical direction, 0 means unrelated. The scores below each card are that real number; nothing is faked. Because Fashion-CLIP was tuned on clothing pairs, fashion-y queries are its specialty — try "a formal outfit" and see what it does with this catalog.
Text→image retrieval is the engine behind visual search and media library tools. Running it on-device means a photo collection is searchable by description without uploading a single image.
import { AutoTokenizer, AutoProcessor, CLIPModel } from "@huggingface/transformers";
const tokenizer = await AutoTokenizer.from_pretrained(MODEL, { subfolder: "onnx" });
const processor = await AutoProcessor.from_pretrained(MODEL, { subfolder: "onnx" });
const model = await CLIPModel.from_pretrained(MODEL, { subfolder: "onnx", dtype: "fp32" });
const imageInputs = await processor(await Promise.all(urls.map(RawImage.read)));
const textInputs = await tokenizer([query], { padding: true, truncation: true });
const { image_embeds, text_embeds } = await model({ ...textInputs, ...imageInputs });
// rank = cosine(text_embeds[0], image_embeds[i]) for each catalog image
We embed the catalog once (it's cached in the worker), then each query is a single text pass + a cosine sweep — fast enough for interactive search. All of it runs in a Web Worker.