Skip to main content
Support

Browse by category

All categories
← All posts
ReviewJul 3, 2026 · 7 min read

Browser background-removal models reviewed — MODNet vs BiRefNet

How MODNet, U2-Net, RMBG, and BiRefNet hold up running on-device via ONNX Runtime Web and transformers.js — edge quality, size, speed.

By Khine1,362 wordsExtractable lead
Browser background-removal models reviewed — MODNet vs BiRefNet — hero illustration

Cutting a subject out of its background used to mean a round trip to a server. You uploaded the image, a GPU somewhere ran a model, and a PNG with an alpha channel came back. The privacy cost was implicit: your photo sat, however briefly, on someone else’s machine. Over the past few years the models that do this work have shrunk and the browser runtimes that host them have matured, to the point where a respectable cutout can now be produced entirely on-device. No upload, no account, no server log.

This is a review of where that on-device state of the art actually stands. The interesting question is not whether browser matting works — it does — but how close it gets to the commercial cloud services, and which model you should reach for given the tradeoffs.

Two problems wearing one name

“Background removal” hides two distinct tasks. The first is segmentation: deciding, per pixel, whether something belongs to the foreground. The output is effectively binary, and the hard cases are objects with ambiguous extent. The second is matting: estimating a continuous alpha value, between fully opaque and fully transparent, for the soft boundary regions — hair, fur, motion blur, the fringe of a translucent fabric. Matting is the harder problem, because the ground truth itself is fractional. A single strand of hair covers maybe thirty percent of a pixel, and a model that only ever predicts zero or one will produce a hard, cut-out-with-scissors edge that reads as fake.

The models below sit at different points on this spectrum, and most of the perceived quality gap between them comes down to how they handle that fractional boundary.

The portrait-era models: MODNet and U2-Net

MODNet (Ke et al., AAAI 2022) was built specifically for portraits. Its design decomposes the matting objective into sub-tasks — semantic estimation, detail prediction, and fusion — and trains them together under explicit constraints, which is what lets it skip the trimap (the hand-drawn three-region map older matting methods required). It is genuinely fast: the authors report 67 frames per second on a 1080Ti, and the network is small enough to run smoothly in a browser. The catch is in the name. MODNet is a portrait model. Point it at a product shot, a pet, or a piece of furniture and the semantic head, trained almost entirely on people, loses its footing.

U2-Net (Qin et al., 2020) comes at the problem from salient-object detection rather than matting. Its nested U-structure — U-blocks inside a larger U — captures context at several scales without a pretrained classification backbone, and it became the default engine behind the widely used rembg library. It generalises past portraits in a way MODNet does not. Two sizes ship: a full model around 176 MB and a lightweight variant of roughly 4.7 MB. The small one is remarkable for its size but visibly coarse on fine edges; the full one is more than most browser sessions want to download. And because U2-Net is fundamentally a saliency segmenter, its alpha channel is closer to a hard mask than a true matte. Hair is where this shows.

BRIA AI’s RMBG-1.4 belongs to this same generation — it is built on the IS-Net architecture and trained on a large licensed dataset. Its practical importance is the deployment story. An 8-bit quantised build is about 45 MB, which Xenova packaged into a transformers.js demo that runs the whole thing locally in a web worker, with no image leaving the page. For a long time that demo was the reference point for “background removal in the browser,” and on ordinary photos with clean silhouettes it remains a sensible default. Note the licensing: RMBG-1.4 and 2.0 are released for non-commercial use, which matters if you plan to build a product on them rather than just experiment.

The dichotomous-segmentation jump: BiRefNet

BiRefNet (Zheng Peng et al., CAAI AIR 2024) is the model that moved the bar. It targets high-resolution dichotomous image segmentation, and the two words that matter are “high-resolution.” Most of its predecessors quietly downscale the input to something like 320 or 1024 pixels, segment that, then upscale the mask — which is precisely why thin structures dissolve. BiRefNet’s bilateral reference mechanism keeps a high-resolution view in play: it works from global context down to local detail and then feeds the refined edges back to the larger view, and it has been run at native sizes up to 2048×2048 without the tiling seams that plague patch-based approaches. The visible result is edges — hair, foliage, fenced railings, the legs of an insect — that hold together where older models smear them into a halo.

The code is MIT-licensed, which is more permissive than the RMBG weights. RMBG-2.0, confusingly, is built on the BiRefNet architecture with BRIA’s own dataset and training scheme, and it outputs a proper single-channel 8-bit alpha matte rather than a hard mask — but it carries the non-commercial license again. So the architecture and the best-known weights trained on it sit under different terms. Worth keeping straight before you commit.

Running them in the browser

Three pieces of plumbing make on-device matting possible.

ONNX Runtime Web executes models exported to the ONNX format, choosing a backend — WebAssembly on the CPU, or WebGPU where the browser and hardware allow. transformers.js sits a layer above it, wrapping models from the Hugging Face hub in a familiar pipeline API and using ONNX Runtime underneath; the background-removal pipeline is a few lines of code. WebGPU is the accelerator that makes the heavier models tolerable, giving the GPU access that WebGL never cleanly exposed for general compute.

The honest constraint is memory. RMBG-1.4 at 45 MB quantised is comfortable, and runs even on phones. BiRefNet-class models are another matter — the BRIA team’s own notes flag RMBG-2.0 as memory intensive enough to trigger out-of-memory errors under WebGPU, with support still being smoothed out. So the quality leader and the deployment-friendly model are, for now, not the same model. You trade download size and peak memory for edge fidelity, and on a mid-range laptop a single high-resolution BiRefNet pass is a couple of seconds of visible work, not the instant result a portrait model gives.

The gap to the cloud

It is narrower than it was, and on a large class of images it has effectively closed. For a person or product on a contrasting background, a local BiRefNet-derived model produces a cutout I would not bother sending to a paid API. Where the commercial services — the ones with their own labelled datasets and post-processing — still pull ahead is the long tail: wispy flyaway hair against a busy background, semi-transparent glass, fine smoke, the cases where even the ground truth is contestable. They also fold in refinement passes and colour-decontamination steps that an out-of-the-box model skips, and that polish is exactly what you are paying for. (I keep a folder of frizzy-hair test shots specifically because they expose this; the worst one has yet to be cleanly cut by anything that runs locally.)

Verdict

If you want one default that runs anywhere and respects the device, RMBG-1.4 through transformers.js is still the pragmatic pick — small, quantised, fast, and proven in the browser, even if its edges are a half-generation behind. If edge quality is the point and you can spend the megabytes and the memory, BiRefNet is the clear technical state of the art for on-device matting, and the visible jump on hair and thin structures is real rather than marketing. MODNet remains a fine, fast choice when you know every input is a portrait, and a poor one the moment that assumption breaks. U2-Net is the dependable generalist whose lightweight build still earns its place where download size dominates.

The larger point is that the question has changed. On-device matting is no longer a compromise you accept for privacy; for most images it is simply good. The remaining gap to the cloud is a tail of genuinely hard cases and a layer of commercial polish — and for work that shouldn’t leave your machine, that is a trade many people will take.

References

  1. MODNet: Real-Time Trimap-Free Portrait Matting via Objective Decomposition — arXiv (Ke et al., AAAI 2022) (accessed 2026-05-29)
  2. U2-Net: Going Deeper with Nested U-Structure for Salient Object Detection — arXiv (Qin et al.) (accessed 2026-05-29)
  3. BiRefNet: Bilateral Reference for High-Resolution Dichotomous Image Segmentation — GitHub (Zheng Peng et al., CAAI AIR 2024) (accessed 2026-05-29)
  4. RMBG-1.4 model card — BRIA AI / Hugging Face (accessed 2026-05-29)
  5. RMBG-2.0 model card — BRIA AI / Hugging Face (accessed 2026-05-29)
  6. Remove Background Web — in-browser background removal with transformers.js — Hugging Face (Xenova) (accessed 2026-05-29)