Skip to content
mask-generation · basics 3-Mask Ambiguity · +1/−1 Trace · 1× Encode : N× Decode WASM q8 · 106.0 MB License: Apache-2.0

Basics: Multi-Mask Ambiguity, Click Refinement & Latency Budget

See why SAM ViT-Base predicts 3 nested masks from a single ambiguous click, trace how adding a positive (+1) refinement point and a negative (0) exclusion point reshapes mask IoU and area, and measure the exact 1× vision encode : N× prompt decode amortization curve locally in your browser.

1 · Two-stage ViT-B/16 + Two-Way Transformer pipeline

Exact geometry from facebook/sam-vit-base/config.json: the ViT-B/16 image encoder runs once per photo into a cached [1, 256, 64, 64] tensor; the 4.90 MB mask decoder runs per prompt.

2 · Multi-mask ambiguity explorer (Sub-part / Part / Whole)

Pick a starter photo, upload/drop/paste your own, or capture a webcam snapshot. Click anywhere on the prompt photo (or run the default prompt) to inspect all 3 multimask outputs side-by-side.

Initialising model loader…

Click anywhere on this photo to inspect SAM's 3 nested mask outputs at that point.

Encode ms–
Decode ms–
Winner tier–
IoU spread–
Area ratio (W/S)–
NaN / invalid0

Sub-part

Awaiting segmentation…

Part

Awaiting segmentation…

Whole

Awaiting segmentation…

3 · Positive (+1) vs Negative (0) click refinement trace

Reuses the cached ViT-B/16 embedding to run a live 3-step prompt trajectory: Step 1: initial +1 foreground click → Step 2: add second +1 foreground point → Step 3: add 0 negative exclusion point.

Ready once SAM ViT-Base loads.

Step 1 → Step 3 IoU Δ–
Coverage Δ–
Mean decode ms–
Positive vs negative click refinement steps (live cached decoder)
Step Prompt set Winner tier Predicted IoU Area (Coverage %) Compactness Decode ms
Run the refinement trace to measure live IoU and area deltas.

4 · Image-encoder vs prompt-decoder latency budget (1× Encode : N× Decode)

Runs 5 distinct prompt clicks against the cached [1, 256, 64, 64] ViT-B/16 embedding (yielding cleanly with yieldToMain()) to measure real amortization speedup vs re-encoding on every click.

Ready once SAM ViT-Base loads.

1× Vision encode–
Mean prompt decode–
Encode / Decode ratio–
5-click total (cached)–
Time saved vs uncached–

See inside the code

Show the code — worker.js: buildOverlayBitmap() (off-thread RGBA fill + 1px boundary edge)
Show the code — sam-base-core.mjs: labelAmbiguityMasks() (Sub-part / Part / Whole ordering)
Show the code — sam-base-core.mjs: summarizeLatencyBudget() (1× encode : N× decode amortization)

References