← All models

mask-generation · vision · WASM · ~40 MB

SlimSAM — click a point, get its exact mask

Segment Anything, slimmed to 77M parameters and running on your device. Point at anything in an image — a cat, a lamp, a single book — and SlimSAM returns a pixel-perfect mask of just that thing. The heavy vision encoder runs once; every extra click is near-instant.

At a glance

ModelXenova/slimsam-77-uniform
Task / pipelinemask-generation (SAM) via SamModel + point prompt
ArchitectureViT vision encoder (pruned to 77M) + prompt encoder + mask decoder
PromptOne or more points (foreground / background); returns 3 candidate masks + IoU scores
Quantizationq8 vision encoder, fp32 mask decoder (crisper masks)
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~40 MB, cached after first load
LicenseApache-2.0 (SlimSAM / Meta SAM)
Web APIsWebAssembly, Web Workers, Canvas, FileReader — all Baseline widely available

Run it

Load the model, pick an image (embedding runs once), then click anywhere on the picture — or use the point buttons / arrow keys — to get the mask of whatever's under the point.

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

Keyboard: focus the image, move the crosshair with arrow keys, press Enter to segment. Or jump to a preset point:

See inside

For one point SAM predicts three candidate masks at different scales (the part, the thing, the whole region) and rates each with a predicted IoU — its own guess of how good the mask is. The page shows the highest-scoring one. Below are the raw numbers: the point you prompted with, all three IoU scores, which mask won, and its pixel area.

Click a point to see the raw mask numbers.

Why it matters

Selecting exactly one object out of a photo used to mean tedious manual masking or a round-trip to a segmentation API. SlimSAM makes "click the thing I mean" a local, interactive operation — the building block under smart selection, cut-out, and annotation tools.

Use cases

Basics

One click, one mask — feel point-prompted segmentation first-hand.

Practical

Click-to-cutout: lift the object onto transparency and download the PNG.

Wild

Magic background swap — keep what you click, blur or recolour the rest.

Multi-model

DETR detects → click a box → SlimSAM returns its exact mask.

How the API works

Point-prompted SAM uses SamModel directly. Encode the image once, then decode per click:

import { SamModel, AutoProcessor, RawImage, Tensor } from "@huggingface/transformers";

const model = await SamModel.from_pretrained("Xenova/slimsam-77-uniform");
const processor = await AutoProcessor.from_pretrained("Xenova/slimsam-77-uniform");

// 1. Encode the image ONCE (the expensive part) and cache the embeddings:
const image = await RawImage.read(imageURL);
const imageInputs = await processor(image);
const embeddings = await model.get_image_embeddings(imageInputs);

// 2. Per click, decode a mask from a point (scaled into the model's input space):
const [rH, rW] = imageInputs.reshaped_input_sizes[0];
const input_points = new Tensor("float32", [nx * rW, ny * rH], [1, 1, 1, 2]);
const input_labels = new Tensor("int64", [1n], [1, 1, 1]); // 1 = foreground
const out = await model({ ...embeddings, input_points, input_labels });

const masks = await processor.post_process_masks(
  out.pred_masks, imageInputs.original_sizes, imageInputs.reshaped_input_sizes,
); // masks[0]: [1, 3, H, W] bool — pick the one with the best out.iou_scores

This page runs all of that in a Web Worker and caches the embeddings, so the first click pays for the vision encoder and every click after is just the lightweight mask decoder.

References