← All models

image-classification Β· vision Β· WASM Β· ~23 MB

MobileViT β€” Apple's light-weight vision transformer for phones

Same 1,000-way ImageNet job as the ViT and ConvNeXt demos, but with a hybrid design: MobileViT-Small is a 5.6M-parameter network that interleaves MobileNetV2-style convolutions with transformer blocks that process unfolded patches β€” global attention where it counts, local convolutions where they're cheap, and no positional embeddings at all. Classify an image and read the real millisecond latency; the story here is transformer accuracy at a convolution footprint.

At a glance

ModelXenova/mobilevit-small (ONNX mirror of apple/mobilevit-small)
Task / pipelineimage-classification
ArchitectureMobileViT-Small β€” 5.6M params; MobileNetV2-style conv blocks + MobileViT blocks (unfold β†’ transformer over patches β†’ refold), no positional embeddings; 256Γ—256 input
LabelsImageNet-1k = 1,000 outputs
Quantizationfp32 (see note) β€” the canonical q8 export produced semantically broken labels in browser testing
BackendWebAssembly (runs without WebGPU)
Download~23 MB β€” vs ~29 MB (ConvNeXt) and ~88 MB (ViT)
LicenseApple sample code license (HF card: other) β€” exact Apple checkpoint
Web APIsWebAssembly, Web Workers, FileReader, getUserMedia (webcam demo) β€” all Baseline widely available
Why fp32 and not q8?

This repo prefers 8-bit weights, but the canonical q8 conversion failed semantic sanity in the exact browser probe: a rights-cleared fixture of two cats on a couch came back as jellyfish (18.1%) with a sea-creature top-5 (sturgeon, sea anemone, nautilus, sea lion). The canonical fp32 graph classified the same image as Egyptian cat (46.1%), tiger cat (16.2%), tabby (10.1%). fp32 is therefore the honest choice and is still only ~23 MB.

Run it

Pick or drop an image and hit Classify. Watch the latency read-out β€” MobileViT is built to be quick.

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

5 labels

See inside

MobileViT's final layer produces one raw logit per class, and a softmax turns those into probabilities. The table shows the top classes with their raw logit next to the softmax probability, plus the shape of the distribution: top-1 margin and normalised entropy.

Run a classification to see the raw numbers.

Size & latency: the mobile hybrid vs the heavier ones

Download size and parameter counts are fixed facts. The "latency here" cell fills in with a real measured run once you classify above.

ModelParamsDownloadOutputsLatency here
MobileViT-Small5.6M~23 MB1,000run above ↑
ConvNeXt-Tiny~28M~29 MB1,0005Γ— the params
ViT-B/16~86M~88 MB1,00015Γ— the params

Why it matters

MobileViT was Apple's answer to a simple question: can a phone get transformer-grade accuracy without transformer-grade cost? By folding global self-attention into an otherwise conventional convnet β€” and skipping positional embeddings entirely β€” it matches or beats comparable CNNs and light ViTs at a fraction of the size of ViT-B. When the constraint is battery, bandwidth, or latency β€” not the last point of accuracy β€” this hybrid is what you reach for.

Use cases

Basics

Classify a sample and read the top-k with a real latency read-out.

Practical

Real-time webcam tagging β€” the mobile use case: classify live camera frames.

Wild

Torture test: shrink and JPEG-crush an image and find where the small hybrid breaks.

Multi-model

Fast prefilter β†’ confirm: MobileViT triages, ViT double-checks only the uncertain ones.

How the API works

The convenience path is two lines with Transformers.js:

import { pipeline } from "@huggingface/transformers";

const classify = await pipeline(
  "image-classification",
  "Xenova/mobilevit-small",
  { dtype: "fp32" },
); // downloads + caches ~23 MB once

const output = await classify(imageURL, { top_k: 5 });
// β†’ [{ label: "Egyptian cat", score: 0.46 }, { label: "tiger cat", score: 0.16 }, …]

This page goes one level deeper for "See inside": instead of the pipeline it runs the model's own processor then model() in a single forward pass, so it can read the raw logits tensor (all 1,000 ImageNet classes) and compute the softmax, entropy, and margin itself. Inference runs in a Web Worker so the page remains responsive.

References