← All models

zero-shot-image-classification · vision + language · WASM · ~66 MB

MobileCLIP — zero-shot image classification, built for speed

MobileCLIP is Apple's mobile-optimised CLIP. Same trick as the CLIP page — score an image against any labels you invent — but with a vision tower engineered to encode an image fast on everyday hardware. Give it an image and a few made-up labels and watch it rank them, entirely on your device, with the real encode time on screen.

At a glance

ModelXenova/mobileclip_s0
Task / pipelinezero-shot-image-classification (two-tower, loaded by hand)
ArchitectureMobileCLIP-S0: a fast hybrid CNN/transformer vision tower + text transformer → shared 512-d space
Quantizationvision fp16, text q8 — quantising the vision tower to q8 measurably flips the ranking, so it stays fp16 (see "How the API works")
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~66 MB (vision ~23 MB + text ~43 MB), cached after first load
LicenseApple ML Research (MobileCLIP), Apache-2.0 export
Web APIsWebAssembly, Web Workers, FileReader — all Baseline widely available

Run it

Pick or drop an image, type comma-separated labels, and hit Classify. The bars are a softmax over MobileCLIP's cosine similarity between the image and each label. Watch the vision vs text encode latency.

Drop an image here, or click to choose
Two cats sleeping on a pink couch A cozy sunlit bedroom with a bookshelf A riverside at golden hour with a swan
Selected image preview

See inside

MobileCLIP turns your image into one 512-number vector and each label into its own 512-number vector, then measures the cosine similarity between the image vector and every label vector. Those similarities are scaled by CLIP's temperature (×100) into logits, and a softmax turns them into the percentages above. The interesting number here is the vision encode time — that's where MobileCLIP's mobile-tuned architecture earns its name versus a full ViT.

Run a classification to see the raw numbers.

Why it matters

Zero-shot image understanding is powerful, but a full CLIP vision encoder is heavy — too heavy to run on every frame or every thumbnail on a phone. MobileCLIP keeps the "label set is an input" superpower while making the image encode cheap enough to actually ship at scale, on device.

Use cases

Basics

One image, your labels, the encode latency — feel fast zero-shot classification first-hand.

Practical

Batch tagging & moderation triage — score many images against a fixed label set, fast.

Wild

Live webcam "vibe check" — classify the camera against moods in real time.

Multi-model

Speed race — run MobileCLIP and the full CLIP on the same image and compare encode times.

How the API works

MobileCLIP's Transformers.js repo ships the two towers separately, so we load them by hand and compute the cosine ourselves:

import {
  AutoTokenizer, AutoProcessor,
  CLIPVisionModelWithProjection, CLIPTextModelWithProjection, RawImage,
} from "@huggingface/transformers";

const id = "Xenova/mobileclip_s0";
const tokenizer = await AutoTokenizer.from_pretrained(id);
const processor = await AutoProcessor.from_pretrained(id);
const vision = await CLIPVisionModelWithProjection.from_pretrained(id, { dtype: "fp16" });
const text   = await CLIPTextModelWithProjection.from_pretrained(id, { dtype: "q8" });

const { image_embeds } = await vision(await processor(await RawImage.read(url)));
const { text_embeds }  = await text(tokenizer(labels,
  { padding: "max_length", max_length: 77, truncation: true })); // fixed 77-token context
// cosine(image_embeds, text_embeds[i]) → similarity per label; softmax(×100) → the bars

Two honest details this page bakes in: the text tower needs a fixed 77-token context (OpenCLIP positional embeddings), and the vision tower runs fp16, not q8 — 8-bit quantising the vision tower measurably flips the ranking on the reference image, so only the larger text tower is quantised. Inference runs in a Web Worker so the page never janks.

References