Skip to content
image-classification Β· basics 4Γ—4 Patch β†’ 7Γ—7 Shifted Windows Β· 56β†’28β†’14β†’7 WASM q8 (32.32 MB) vs fp32/fp16 License: Apache-2.0

Inside Swin-Tiny: Shifted-Window Hierarchy, Occlusion Map & q8 vs fp32

Swin-Tiny splits a 224Γ—224 image into 4Γ—4 pixel patches (56Γ—56 tokens), merges 2Γ—2 patches between stages (56β†’28β†’14β†’7), and alternates regular vs shifted 7Γ—7 self-attention windows. Probe which spatial windows drive the top-1 class with a live 4Γ—4 occlusion sweep (16 real passes), then compare q8 against fp32 / fp16 weights on the exact same input.

1 Β· Hierarchical 7Γ—7 shifted-window pyramid (56 β†’ 28 β†’ 14 β†’ 7)

Exact stage geometry from Xenova/swin-tiny-patch4-window7-224/config.json: patch_size: 4, window_size: 7, depths: [2, 2, 6, 2], num_heads: [3, 6, 12, 24]. Each 56Γ—56 cell in our 4Γ—4 occlusion grid corresponds to one Stage-2 7Γ—7 window (and 4 Stage-1 7Γ—7 windows).

2 Β· Live 4Γ—4 regional occlusion sensitivity heatmap

Pick a starter photo or upload/drop/paste your own. Each pass masks one 56Γ—56 spatial cell of the 224Γ—224 input and runs Swin-Tiny to measure which window regions drive its top-1 prediction.

Initialising model loader…

Low impact Critical window (large score drop)

Click any cell after running to inspect that masked pass.

Target class–
Baseline score–
Peak patch drop–
Label flips (of 16)–
Mean pass ms–
NaN / invalid0

Selected cell details appear here after running.

4Γ—4 window occlusion sensitivity ranking (sorted by target-class probability drop)
Cell 56Γ—56 region Occluded score Score drop Occluded Top-1 Inspect
Run the 4Γ—4 occlusion sweep to populate window sensitivity scores.

3 Β· Live q8 vs fp32 / fp16 quantization comparison

Xenova/swin-tiny-patch4-window7-224 publishes onnx/model_quantized.onnx (q8, 32.32 MB), onnx/model_fp16.onnx (fp16, 59.41 MB), and onnx/model.onnx (fp32, 116.00 MB). Selecting a comparison downloads that ONNX variant only when you explicitly click the button below, runs both precisions on the current 224Γ—224 input, and returns the worker to q8.

Ready once q8 loads β€” comparison downloads only on click.

Top-1 agreement–
Target prob shift–
Top-5 L1 drift–
q8 vs alt latency–

Click "Compare q8 vs selected precision" above to benchmark real INT8 vs FP32/FP16 inference.

See inside the code

Show the code β€” swin-core.mjs: SWIN_STAGES (56β†’28β†’14β†’7 shifted-window hierarchy)
Show the code β€” swin-core.mjs: computeOcclusionGrid() & computeOcclusionSaliency()
Show the code β€” swin-core.mjs: compareQuantRuns() (q8 vs fp32/fp16 agreement & L1 drift)

References