At a glance
| Upstream model | laion/CLIP-ViT-B-32-laion2B-s34B-b79K (MIT) |
|---|---|
| ONNX export |
onnx-community/CLIP-ViT-B-32-laion2B-s34B-b79K-ONNX
(onnx/model_quantized.onnx)
|
| Task / pipeline |
zero-shot-image-classification (local @huggingface/transformers@4.3.0
pin in worker.js β 3.7.5 WASM lacks ConvInteger(10) for
/vision_model/embeddings/patch_embedding/Conv_quant)
|
| Architecture |
CLIPModel β 12-layer ViT-B/32 vision tower (768d, 12 heads, 224Γ224,
32Γ32 patches = 7Γ7 = 49 spatial tokens + [CLS]) + 12-layer text
transformer (512d, 8 heads, max 77 tokens, vocab 49,408) β 512-d projection
|
| Benchmark & data | 66.6% ImageNet-1k zero-shot top-1 Β· OpenCLIP on LAION-2B English (34B samples seen) |
| Quantisation & size | q8 INT8 (152.71 MB / 152,708,043 B) + tokenizer.json (3.64 MB / 3,642,073 B) |
| Backend | WebAssembly (wasm) β runs on laptop or desktop CPU without WebGPU |
| Web APIs | Web Workers, Cache Storage, Canvas 2D, Clipboard, MediaDevices (all Baseline) |
Run it β Live Open-Vocabulary Classifier
Loading starter photoβ¦
See inside CLIP ViT-B/32 LAION-2B
The ViT-B/32 tower divides a 224Γ224 center-cropped image into 7Γ7 = 49 coarse
32Γ32 patches plus a [CLS] token, projecting to a unit-normalized
512-d embedding. Logits scale cosine similarities by the learned
logit_scale (initialized at exp(2.6592) β 14.29Γ and trained toward
~100Γ). Below are the exact cosines, scaled logits, softmax probabilities, and the
pairwise cosine similarity matrix across your text prompts.
| # | Label | Wrapped prompt | Cosine sim | Raw logit | Softmax % |
|---|---|---|---|---|---|
| Run a classification above to inspect raw logits and cosines. | |||||
| Run a classification above to compute the 512-d pairwise prompt cosine matrix. |
Show the code β Worker coalesced load & epoch-guarded pipeline initialization
Show the code β Off-thread zero-shot classification, logits, image/text embeddings
Show the code β computePairwisePromptMatrix() 512-d prompt cosine matrix
Why CLIP ViT-B/32 LAION-2B matters
Unlike proprietary OpenAI CLIP checkpoints trained on closed WebImageText-400M, LAION-2B ViT-B/32 is fully reproducible on open web-crawled image-text pairs and still hits 66.6% ImageNet-1k zero-shot accuracy:
- Auditable open-data priors β test directly in the browser where LAION-2B aligns with or diverges from OpenAI WIT CLIP.
- Coarse 32Γ32 patch speed β 49 spatial patches vs 196 in ViT-B/16 gives 4Γ fewer self-attention tokens in the vision backbone.
- Private zero-shot search & triage β organize local photo libraries by natural language without uploading a single frame.
- Transparent failure probing β inspect typographic attacks, tight crops, and prompt-similarity crowding locally.
Use-case ladder
Basics: 7Γ7 Patches & Calibration
Inspect the 7Γ7=49 coarse 32Γ32 patch grid with real patch occlusion, template sensitivity sweep, and temperature calibration.
Practical: NL Library Organizer
Cancellable FIFO media-library organizer with natural-language search filter and OWASP CSV/JSON/Markdown exports.
Wild: Adversarial & Degradation Lab
Typographic stickers, tight crops, blur, low light, grayscale, and near-synonym distractors with mid-suite Cancel.
Multi-model: LAION-2B B/32 vs OpenAI B/16
Side-by-side dataset-prior and patch-granularity diffing against OpenAI WIT CLIP ViT-B/16 in dual Web Workers.
How the API works
CLIP ViT-B/32 LAION-2B runs via the Transformers.js zero-shot-image-classification
pipeline inside a Web Worker pinned locally to @huggingface/transformers@4.3.0 so ORT-Web
executes the quantized ConvInteger(10) patch-embedding convolution cleanly:
import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.0";
const classifier = await pipeline(
"zero-shot-image-classification",
"onnx-community/CLIP-ViT-B-32-laion2B-s34B-b79K-ONNX",
{ device: "wasm", dtype: "q8" },
);
const scores = await classifier(image, ["a dog on grass", "a pizza on a plate"], {
hypothesis_template: "a photo of {}",
});
// β [{ label: "a dog on grass", score: 0.99 }, ...]