cd /news/computer-vision/how-i-made-a-background-remover-that… · home › topics › computer-vision › article
[ARTICLE · art-172401] src=dev.to ↗ pub= topic=computer-vision verified=true sentiment=· neutral

How I made a background remover that runs entirely in the browser

A developer built Free Background Remover, a browser-based tool that runs image segmentation entirely client-side using Transformers.js and onnxruntime-web, so photos are never uploaded to a server. The site forks addyosmani/bg-remove and defaults to the MIT-licensed BiRefNet 512x512 ONNX model, downloading roughly 473 MB of fp16 weights on first visit and falling back to fp32, with an optional WebGPU MODNet path for non-iOS browsers. The developer notes the large cold-start download and the 512x512 mask resolution as the main trade-offs, warning that hair, glass and thin straps remain weak spots.

recommendation

Enable the ONNX WASM proxy for browser-side BiRefNet inference to move heavy work off the main thread, and budget for a ~473 MB first-load model download with fp32 fallback.

more in playbook: Inference and self-hosting
by read5 min views6 publishedNov 19, 2026

Most “free background remover” sites work the same way: you upload a photo, a server runs a segmentation model, and a PNG comes back. That is convenient, and it is also a privacy problem. A CV portrait, a product shot, or a scan of a document should not have to sit on a stranger’s GPU for a simple cut-out.

I wanted a tool that does the same job in the browser tab. The result is Free Background Remover. It is a free, ad-supported site. Your photo is not sent to our servers for processing. This post describes how the page is put together, what it borrows, and where the trade-offs are.

I did not train a new model, and I did not write a new inference engine. The site is a fork of addyosmani/bg-remove (MIT), which itself follows the Hugging Face Transformers.js background-removal demo.

The useful parts of that codebase were already in the right place:

@huggingface/transformers My work was to ship it as a small public site: branding, a privacy page that states the model download clearly, a few how-to guides, and ads to keep the tool free. The application code is MIT. The repository is web-free-site/free-background-remover.

License matters as much as quality if the site shows ads. I did not use BRIA RMBG models, which are limited to non-commercial use, and I did not pull in an AGPL background-removal library.

The default model is onnx-community/BiRefNet_512x512-ONNX (MIT). It is an ONNX export of ZhengPeng7/BiRefNet. On a first visit the tries fp16 weights, which are about 473 MB. If that load fails, it falls back to fp32.

If the browser exposes WebGPU, and the visitor is not on iOS, there is an optional second model: Xenova/modnet (Apache-2.0), run with device: "webgpu". If that initialization fails, the page falls back to BiRefNet in WebAssembly. iOS is steered to the WASM path on purpose.

Inference uses onnxruntime-web under Transformers.js. The photo itself never goes to Hugging Face. What does go to Hugging Face, on first use, is the model: the browser fetches the weights directly, not through our application servers. Later visits can reuse the cached files. I set env.allowLocalModels = false because the weights are not bundled with the site; they are too large to ship as a Cloudflare Worker static asset.

That first download is the main trade-off. A 473 MB model is a long wait on a slow connection. I would rather say that up front than pretend the tool is instant and fully offline on a cold visit.

Once the model and processor are in memory, a chosen file is read locally (RawImage.fromURL on an object URL). The processor produces a tensor; for BiRefNet that input is 512×512. The model returns a mask. In the BiRefNet path the mask is passed through a sigmoid, scaled to 0–255, and cast to uint8. The mask is then resized to the original width and height.

A canvas draws the original image, the mask is copied into the alpha channel of the pixel data, and the result is exported as a PNG (name-no-bg.png). The original file is not uploaded, and the PNG is created in the tab.

Because the network sees a 512×512 input, a 4,000-pixel portrait does not get a 4,000-pixel “understanding” of the edge. The alpha channel is only an upscaled mask. Hair, glass, and thin straps are the usual weak spots. I would zoom in before using the file on a CV or a product listing. Automatic removal is a starting point, not a guarantee of a perfect cut-out.

Transformers.js talks to onnxruntime-web. For the BiRefNet WASM path I turn the ONNX WASM proxy on, so the heavy work can sit in a worker rather than on the main thread. For the optional MODNet WebGPU path the proxy is turned off, the page asks for a GPU adapter, and the model is constructed with device: "webgpu" and a small config that names the MODNet architecture. If navigator.gpu is missing, or requestAdapter() returns nothing, that path is skipped.

The load and the prediction are ordinary async functions. In simplified form, the default path looks like this:

state.model = await AutoModel.from_pretrained(DEFAULT_MODEL_ID, { dtype: "fp16" });
state.processor = await AutoProcessor.from_pretrained(DEFAULT_MODEL_ID);

const img = await RawImage.fromURL(URL.createObjectURL(image));
const { pixel_values } = await state.processor(img);
const { output_image } = await state.model({ input_image: pixel_values });
const maskTensor = output_image[0].sigmoid().mul(255).to("uint8");

The mask is then resized with RawImage.fromTensor(maskTensor).resize(img.width, img.height), drawn into the canvas alpha channel, and saved with canvas.toBlob(..., "image/png"). There is also a processImages() helper that runs that function over a list of files, so a few portraits can be queued one after another in the same tab.

None of this requires a backend of our own for inference. The site is a static front end. The large pieces that must still come from the network are the JavaScript bundle, the ads, and — on first use — the model weights.

It does not store the photo on our servers. It does not require an account. It does not claim a user count I cannot defend. Standard host logs (IP address, user agent, URL) and third-party ad cookies can still exist — the privacy page says so. Advertising is how the tool stays free.

On a technical level it is also not a custom training setup and not a new architecture. The interesting part is packaging: a large ONNX model, a WASM or WebGPU runtime, and a canvas composite, all inside a static front end.

Open https://free-background-remover.web-free.site/, wait for the model on the first visit, and drop in a photo. If you only need the idea, the upstream projects above are the right place to start.

── more in #computer-vision 4 stories · sorted by recency
── more on @free background remover 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-i-made-a-backgro…] indexed:0 read:5min 2026-11-19 · —