image-feature-extraction Β· ViTModel (vit) Β· CPU WASM q8 (87.45 MB) Β· Apache-2.0

ViT-Base Patch16-224 IN21k β€” 768-d ImageNet-21k Representation Lab

Google Research's Dosovitskiy et al. (ICLR 2021) ViT-B/16 base encoder (86.4M params, 87.45 MB q8 WASM, pretrained on ImageNet-21k β€” 14M images across 21,843 classes, without an ImageNet-1k classification head). Each forward pass emits [1, 197, 768]: a global [CLS] descriptor plus 14Γ—14 spatial 16Γ—16-pixel patch tokens ready for k-NN transfer, clustering, and patch probing.

At a glance

Verified model card and ONNX Hub metadata for ViT-Base Patch16-224 IN21k
Upstream model google/vit-base-patch16-224-in21k (Google Research β€” Dosovitskiy et al., ICLR 2021 / arXiv:2010.11929, ImageNet-21k pretraining)
Browser ONNX repo Xenova/vit-base-patch16-224-in21k (onnx/model_quantized.onnx 87,453,205 B + configs 848 B = 87,454,053 B / 87.45 MB)
License Apache-2.0 (permissive open-source commercial & research use)
Task & architecture image-feature-extraction Β· ViTModel (vit, 86.4M params, 12 layers, 768-d hidden, 12 attention heads, 3072 MLP, GELU, QKV bias, 224Γ—224 bilinear resize, mean/std [0.5, 0.5, 0.5], patch 16, 0 register tokens)
Output tensor shape last_hidden_state shape [1, 197, 768] (151,296 floats; no pooler_output in ONNX): index 0 = [CLS] (1Γ—768) Β· indices 1..196 = 14Γ—14 = 196 spatial patch tokens (196Γ—768)
Distinct from ViT-1k & DINOv2 Unlike ViT Image Classification (which attaches a fixed 1,000-class ImageNet-1k head), this in21k base checkpoint outputs raw 768-d representations for custom categories, clustering, and retrieval β€” and contrasts supervised 21k pretraining (14Γ—14 grid) with self-supervised DINOv2-Base (16Γ—16 patch-14 grid).
Runtime & backend Shared Transformers.js pin (../../lib/webai.js, @huggingface/transformers@3.7.5) Β· CPU WASM q8 (87.45 MB, universal; off-main-thread Web Worker in worker.js)

1. Live 14Γ—14 Patch Cosine Explorer

Drop an image anywhere in this box, paste from clipboard (Ctrl/⌘+V), capture from webcam, or pick a curated photo below.

Initialise ViT-Base IN21k above, then click or arrow-key any 14Γ—14 cell to inspect patch cosine similarity.

Photo: – Click or arrow-key any 14Γ—14 cell to probe patch cosine

Live [1, 197, 768] Tensor Anatomy

ViT-Base IN21k emits 197 tokens (no 1k head, 0 registers): index 0 is the global [CLS] token and indices 1..196 map to the 14Γ—14 patch grid.

Index 0 [CLS] (1Γ—768)
Indices 1..196 14Γ—14 Patches (196Γ—768) Β· 0 Registers

Patch norm spread & top cosine matches will appear here after the forward pass.

Backend–
Tensor Shape–
Infer Latency–
[CLS] L2 Norm–
Patch Norm Spread–
Selected Patch(7, 7)
Patches β‰₯ 0.60 Cos–
Tensor NaN Count–

Why ViT-Base IN21k matters

Before a Vision Transformer is fine-tuned onto ImageNet-1k's 1,000 classes, its ImageNet-21k backbone learns broad semantic structure over 14 million images and 21,843 concepts. At 87.45 MB under Apache-2.0 and universal CPU WASM, vit-base-patch16-224-in21k unlocks:

Use-case ladder

How the API works

Load Xenova/vit-base-patch16-224-in21k once via the shared Transformers.js image-feature-extraction pipeline on WASM q8, then run pipe.processor(image) + pipe.model(inputs) inside a dedicated Web Worker to unpack last_hidden_state ([1, 197, 768]).

Show the code β€” worker.js: extractFeatures() ([1, 197, 768] unpacking + real nanCount)

References