image-segmentation Β· matting Β· vision Β· WebGPU (fp32) / WASM (q8) Β· ~7 MB
Removing a background is easy until you reach the hair. MODNet is a matting network: instead of a hard in/out decision it predicts a soft alpha value for every pixel, so flyaway strands, fur and soft edges survive the cut. Give it a portrait and it returns a matte you can drop onto transparency, a colour, or a new scene β entirely on your device.
| Model | Xenova/modnet |
|---|---|
| Task / pipeline | image-segmentation β a single soft foreground alpha matte |
| Architecture | MODNet β trimap-free portrait matting (one network, three branches: semantics, detail, fusion) |
| Input | Dynamic resolution (any aspect ratio) β no fixed 1024Β² crop |
| Precision | fp32 on WebGPU; q8 (8-bit) on the WASM fallback |
| Backend | WebGPU (fp32) when available; falls back to WebAssembly (q8) everywhere else |
| Download | ~7 MB (q8) / ~26 MB (fp32) β tiny; cached after first load |
| License | Apache-2.0 (MODNet / ZHKKKe); the ONNX export is by Xenova |
| Web APIs | Web Workers, Canvas 2D, FileReader β all Baseline; WebGPU is used opportunistically and the page falls back honestly without it |
Pick or drop a photo (portraits work best β it's trained on people), then pull the matte. Drag the slider to wipe between the original and the cut-out on a transparency checkerboard.

MODNet never sees "a person" β it outputs an alpha matte: a number from 0 (background) to 255 (subject) for every pixel. What makes a matting model different from a plain background remover is the middle of that range: the grey, half-transparent band along hair and fur where it hedges. Those in-between values are exactly what a hard segmentation throws away β and what makes a composite look real. The histogram below should show mass at both ends and a spread in between; the soft-edge view isolates that band.
| matte resolution | β |
|---|---|
| foreground coverage | β |
| soft-edge (partial-alpha) pixels | β |
There are two jobs hiding inside "remove the background". RMBG-1.4 answers where is the subject with a confident, general-purpose mask. MODNet answers the harder question β exactly how opaque is each pixel β which is what you need whenever the edge is soft:
Matte vs. mask β see MODNet's soft edges next to RMBG's hard cut on the same photo.
Headshot studio β drop your portrait onto a brand colour or backdrop, hair intact.
Edge stress test β flyaway hair, fur and glass, with a matte-quality score.
Matte β caption: cut the subject out, then a VLM describes just what's left.
MODNet uses a custom architecture, so the model card's path loads the model and processor directly and reads the matte tensor:
import { AutoModel, AutoProcessor, RawImage } from "@huggingface/transformers";
const model = await AutoModel.from_pretrained("Xenova/modnet", {
device: "webgpu", dtype: "fp32", config: { model_type: "custom" },
});
const processor = await AutoProcessor.from_pretrained("Xenova/modnet");
const image = await RawImage.read(imageURL);
const { pixel_values } = await processor(image);
const { output } = await model({ input: pixel_values }); // the ONNX input is named "input"
// output is a [1,1,H,W] soft alpha map in 0β1. Scale to 0β255 and resize to the original photo:
const matte = (await RawImage.fromTensor(output[0].mul(255).to("uint8")))
.resize(image.width, image.height);
// then copy `matte` into the image's alpha channel β the cut-out
This page runs that in a Web Worker and stamps the matte into the photo's alpha on a canvas, so
the interface stays responsive and the composite (transparency, colour, or a new scene) is all
client-side. The input tensor's name (input) is read off the live ONNX session β no
invented signature.