At a glance
| 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.
Camera frames stay strictly on your device. Approve permission when prompted, then capture a frame.
Camera idle.
Initialising model loaderβ¦
No photo selected yet.
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.
| 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
Basics: Shifted Windows & q8 vs fp32
Inspect 7Γ7 window hierarchy (56β28β14β7), sweep a 4Γ4 occlusion heatmap, and compare q8 vs fp32/fp16 live.
Practical: Stock Photo Auto-Tagger
Auto-tag multi-file photo batches sequentially with tag filter, confidence histogram, Cancel, and CSV/JSON export.
Wild: Robustness & Synset Lab
Stress-test rotation, center crop, blur, low-light, mirror, and contrast plus audit top-5 ImageNet synset ambiguity.
Multi-model: D-FINE 365 β Swin-Tiny
Detect coarse Objects365 boxes (11.33 MB) and refine every crop into 1,000 ImageNet classes (43.6 MB total).