Skip to content
image-classification Β· vision 7Γ—7 Shifted Windows Β· 56β†’28β†’14β†’7 WASM q8 Β· 32.32 MB License: Apache-2.0

Swin-Tiny β€” 32 MB Hierarchical Shifted-Window ImageNet-1k Classifier

Microsoft's Swin-Tiny replaces global ViT self-attention with hierarchical 7Γ—7 shifted windows starting from 4Γ—4 pixel patches (56Γ—56 β†’ 28Γ—28 β†’ 14Γ—14 β†’ 7Γ—7, ~28.3M params) β€” giving linear-time local attention with cross-window mixing in a fast 32.32 MB CPU WASM download (~170 ms per image).

At a glance

Swin-Tiny model specification and runtime grounding
Upstream model microsoft/swin-tiny-patch4-window7-224
Loaded ONNX repo Xenova/swin-tiny-patch4-window7-224 (onnx/model_quantized.onnx)
Pipeline task image-classification Β· { top_k: 3–10 } (1,000 ImageNet-1k classes)
Architecture SwinForImageClassification β€” ~28.3M params, 4Γ—4 patch partition, 7Γ—7 shifted windows, stages [2, 2, 6, 2], heads [3, 6, 12, 24], dims [96, 192, 384, 768]
Image processor ViTFeatureExtractor β€” 224Γ—224 bicubic resize, rescale 1/255, ImageNet mean [0.485, 0.456, 0.406], std [0.229, 0.224, 0.225]
Backend & size CPU WASM q8 β€” 32.32 MB (32,321,076 B) via shared @huggingface/transformers@3.7.5 in lib/webai.js (~170 ms typical CPU WASM latency)
License Apache-2.0 (upstream weights and ONNX export)

Live ImageNet-1k Classifier

Choose a multi-domain starter photo, upload or drop your own image, press Ctrl/Cmd+V to paste from clipboard, or capture a live webcam snapshot. Everything executes locally in a dedicated Web Worker.

Initialising model loader…

No photo selected yet.

Top-1 class–
Top-1 score–
Top-1 vs Top-2 margin–
Shannon entropy–
Latency–
Backend / dtypewasm Β· q8
NaN / invalid0
Raw pipeline output (exact ImageNet-1k label/score pairs)
[]

Why Swin-Tiny is distinct from ViT-Base, ConvNeXt V2, and ResNet-50

Standard Vision Transformers compute global self-attention across every 16Γ—16 patch at a single scale (quadratic complexity in token count). Swin-Tiny builds a true multi-scale feature pyramid like a ConvNet β€” starting at 56Γ—56 tokens (4Γ—4 patches) and merging 2Γ—2 neighborhoods at each stage (56β†’28β†’14β†’7) β€” while restricting self-attention to local 7Γ—7 windows and shifting windows by half a window (⌊7/2βŒ‹ = 3 tokens) every other block for cross-window connections.

Architectural comparison of browser ImageNet-1k classifiers
Architecture Core primitive Params WASM q8 footprint Spatial hierarchy
Swin-Tiny 4Γ—4 patches + 7Γ—7 shifted-window self-attention ~28.3M 32.32 MB 4-stage pyramid (56β†’28β†’14β†’7)
ViT-Base/16 16Γ—16 patch tokens + global self-attention 86.6M ~87 MB Single-scale 14Γ—14 token grid
ConvNeXt V2 Tiny 7Γ—7 depthwise conv + FCMAE + GRN 28.6M 29.54 MB 4-stage conv pyramid (56β†’28β†’14β†’7)
ResNet-50 3Γ—3 conv bottlenecks + BatchNorm 25.6M ~26 MB 5-stage conv pyramid

How the API works

Transformers.js runs Swin-Tiny through the standard image-classification pipeline inside a Web Worker. ViTFeatureExtractor resizes inputs to 224Γ—224 with bicubic interpolation and normalises ImageNet RGB channels:

import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.5";

const classifier = await pipeline("image-classification", "Xenova/swin-tiny-patch4-window7-224", {
  device: "wasm",
  dtype: "q8",
});
const results = await classifier(image, { top_k: 5 });

See inside the code

Inspect the exact ES modules powering this page β€” off-main-thread inference and pure ranking/entropy maths.

Show the code β€” worker.js: ensureLoaded() (shared 3.7.5 WASM q8 + epoch guards)
Show the code β€” worker.js: classifyImage() (white-flatten, top_k, real nanCount)
Show the code β€” swin-core.mjs: analyzeClassification() (ranking, margin, Shannon entropy)

Explore the 5-route use-case ladder

References & model card