RE

Rembg

Remove image backgrounds automatically with AI

Self-Hosted AI ★ 24.8k stars Easy setup MIT

Rembg is a tool and library that removes the background from images using neural networks. It can run as a command-line tool, a Python library, or a local HTTP server for batch processing.

Key features

  • Automatic background removal
  • CLI, library, and server
  • Batch processing
  • Multiple models

Pros & cons

Strengths

  • Simple CLI and API
  • Runs fully offline
  • Batch processing support

Trade-offs

  • Models download on first run
  • Edge quality varies

Rembg replaces

Last reviewed Aug 26, 2026 · 757 words

pip install "rembg[cli]"
rembg i photo.jpg cutout.png

That is the entire product for most people: a 24,435-star, MIT-licensed Python tool that removes the background from an image on your own CPU, with no account, no upload, and no per-image fee, which is what remove.bg charges for. The first run downloads a model of about 170 MB into ~/.u2net and then everything is offline. The catalogue lists 2 GB of RAM and Easy, and both hold; the thing it does not list is that the result is only as good as the model you picked, and the default is not the best one.

Pick the model by subject, not by default

Rembg ships with a menu of ONNX models and picks u2net unless told otherwise. That one is a decent generalist from 2020 and it is the reason people say "the edges are fuzzy". For product photos, portraits, and anything with hair, isnet-general-use or one of the birefnet variants is noticeably cleaner; u2net_human_seg is tuned for people; isnet-anime exists for illustrations; u2netp is a small model for slow machines. Select with -m:

rembg i -m isnet-general-use photo.jpg cutout.png

Each model downloads once. Try three on a hard image before deciding, because the differences on hair, glass, and thin straps are large, and the "edge quality varies" con in the catalogue is really "you left it on u2net". Alpha matting (-a) refines edges further at a cost of a few seconds per image and occasional haloing.

Batch mode is where it earns a place on a server

rembg p input_dir output_dir processes a folder, and --watch keeps the process alive and handles new files as they land. That turns a directory on your NAS into a drop box: put product shots in, get transparent PNGs out. On a modern 4-core CPU a 12-megapixel image takes a few seconds; the rembg[gpu] extra uses CUDA through onnxruntime and brings that under a second, though for a few hundred images a week the CPU is fine. Add -om if you only want the mask, which is what a later compositing step usually asks for. This is the pattern I use rather than the server, because it needs no port and no auth, and a folder is the interface every other tool on the box already understands.

The HTTP server, and who should expose it

rembg s --host 0.0.0.0 --port 7000 starts a small FastAPI service with a Swagger page and two endpoints, one that takes an upload and one that fetches a URL. The Docker image danielgatis/rembg wraps the same thing:

docker run -d -p 7000:7000 -v rembg-models:/root/.u2net danielgatis/rembg s --host 0.0.0.0 --port 7000

Mount the model directory or it downloads again on every recreate. There is no authentication, so keep it on the LAN or behind your proxy's auth; a URL-fetching endpoint on the open internet is a request to become someone's proxy. The server is what makes rembg useful from other tools: an n8n workflow that cleans up listing photos, a shell script in a CI job, or a "remove background" button in a home-grown inventory app.

What it pairs with, and what it is not

Rembg is a single step, not an image editor. The natural neighbours are Upscayl for enlarging the cutout, and ComfyUI or another tool from the AI image generation category if you want to put the subject on a generated background, where rembg's mask becomes the inpainting mask. It does not do video, it does not refine masks interactively, and it will not beat a hand-cut path on a product shot destined for print. For the 95 percent case, a listing photo, an avatar, a logo someone sent as a JPEG, it is faster than opening an editor.

What I'd do

Install it with the CLI extra on the machine that already holds your photos, set -m isnet-general-use in a shell alias, and use the watch-folder mode rather than the server unless another app needs to call it. Give the models volume a name so the first-run download happens once. If a card is present, add the GPU extra; if not, do not buy one for this. It is the rare AI tool where "just run it" is the whole guide.

Similar self-hosted ai apps