To install rembg for AI background removal, use Python 3.11, 3.12, or 3.13, create a virtual environment, then install the CPU command-line package with pip install "rembg[cpu,cli]". Run rembg i input.png output.png for your first cutout. The first run downloads a model automatically, so give it a minute and an internet connection. Rembg itself is MIT licensed, so the software licence fee is $0. One warning matters for business use: model weights carry their own licences, and the default bria-rmbg model needs a paid BRIA agreement for commercial use, so choose and check your model before you sell anything made with it.
Quick Answer
To install rembg for AI background removal, use Python 3.11, 3.12, or 3.13, create a virtual environment, then install the CPU command-line package with pip install "rembg[cpu,cli]". Run rembg i input.png output.png for your first cutout. The first run downloads a model automatically, so give it a minute and an internet connection. Rembg itself is MIT licensed, so the software licence fee is $0. One warning matters for business use: model weights carry their own licences, and the default bria-rmbg model needs a paid BRIA agreement for commercial use, so choose and check your model before you sell anything made with it.
In this article
- How we checked this guide
- Read this first: what rembg is, licence, and the model trap
- What rembg replaces, and what it does not
- Routes to install rembg for AI background removal
- Requirements before you install
- Step 1: install rembg for AI background removal
- Step 2: run your first cutout
- Step 3: batch a whole folder
- Step 4: fix edges with the right edge mode
- Step 5: use rembg as a library or local server
- First-run security steps you must not skip
- Backup and update routine
- Common errors and fixes
- Tips and tricks that save money
- The real cost maths
- When not to install rembg for AI background removal
- Pros and cons
- Our verdict
- FAQ
- Strategic Pivot
- Sources
How we checked this guide
We checked the official rembg GitHub repository on December 5, 2026. That covers the Python requirement, the CPU, GPU, and ROCm install commands, the command-line subcommands, the model list, Docker routes, and the licence notes.
We also checked the official Photoroom API pricing page on December 5, 2026. Every Photoroom figure below comes from that official page. No price in this guide comes from a roundup.
Read this first: what rembg is, licence, and the model trap
Rembg is an open-source tool that removes image backgrounds. It can run as a command-line tool, a Python library, an HTTP server, or a Docker container. You give it a photo. It returns the subject with a transparent background, ready to drop onto a white product card, a marketplace listing, or a design.

Rembg is not a hosted service with a dashboard. It is a program that runs on your own computer. That is the whole point: your product photos stay on your machine, and there is no per-image bill on the local route.
Rembg is licensed under the MIT License. In plain words, the rembg code is free to use, copy, and build into your own work, including commercial work, as long as you keep the copyright and licence notice. The software licence fee is $0.
Here is the trap that catches businesses. The rembg code and the model weights are two different things. The official repository states that model weights carry their own licences, independent of rembg's MIT licence. The default model, bria-rmbg, is released under a BRIA licence that requires a paid agreement for commercial use.
So the honest rule is simple. For personal tests, the default model is fine. For product photos you will sell with, read the model source licence first and pick a model whose terms fit your use, or sign the BRIA agreement. Do not discover this after you have processed ten thousand listing photos.
What rembg replaces, and what it does not
Rembg replaces the per-image background-removal bill. If your shop photographs fifty products a week, a hosted remover charges you for every single photo, every week, forever. Rembg turns that recurring bill into a one-time install on a computer you already own.
Rembg is best when the job is cutting out subjects: products on a table, a person for a profile card, a car for a listing, a shoe for a catalogue. It handles one photo, a whole folder, or a stream of frames, and it keeps the originals untouched when you write outputs to a separate folder.
Rembg does not replace a full photo studio. It will not relight your product, invent a lifestyle scene, or fix a blurry photo. It removes the background. What you place behind the subject is still your design decision.
Rembg also does not replace careful photography. A subject shot against a busy, same-coloured background is harder to cut out than the same subject against a plain wall. Five minutes of better lighting saves an hour of edge fixing.
If your real job is finding and boxing objects rather than cutting them out, use our YOLO guide. If your job is preparing frames and resizing images before any model sees them, use our OpenCV guide. If you need a precise mask from a point or box prompt, use our Segment Anything Model guide. Rembg sits in the middle of that family: it turns a photo into a clean cutout with one command.
Routes to install rembg for AI background removal
| Route | Best for | Skip if | What you use |
|---|---|---|---|
| CPU pip install with CLI | Most shops, laptops, and servers without a GPU | You process thousands of large photos hourly | pip install "rembg[cpu,cli]" in a virtual environment |
| NVIDIA GPU pip install | High-volume batches on a CUDA machine | Your CUDA or cuDNN setup is already fragile | pip install "rembg[gpu,cli]" after checking the ONNX Runtime matrix |
| AMD ROCm pip install | AMD GPU machines with ROCm working | ROCm is not installed and proven yet | pip install "rembg[rocm,cli]" after installing onnxruntime-rocm |
| Docker CPU image | Clean, repeatable runs without touching your Python | You hate Docker and want a simple script | docker run danielgatis/rembg with a mounted data folder |
| Python library | Developers building background removal into an app | You only need occasional cutouts | from rembg import remove with session reuse |
| Hosted remove-background API | Teams that want support, uptime, and no local upkeep | Your photos must stay on your own machine | A paid API such as Photoroom, priced below |
The CPU route is the right default for this guide. It installs cleanly, it runs on the computer you already own, and it is fast enough for product-photo batches. Move to a GPU only after you have measured a real batch and found the CPU too slow.
Choose one backend only. The official repository is explicit: pick one of the CPU, GPU, or ROCm backends based on your hardware. Installing two backends into the same environment is how people create conflicts they then blame on rembg.
Requirements before you install
You need Python 3.11 or newer, but below 3.14. The official repository states the requirement as python: >=3.11, <3.14. That range comes from ONNX Runtime compatibility, so respect it. Python 3.10 and Python 3.14 are both outside the supported range at the time of writing.
Create a virtual environment first. Rembg pulls in ONNX Runtime and image libraries, and a clean environment makes every failure readable. If the install fails inside a fresh environment, the problem is real. If it fails inside your everyday Python, the problem could be anything.
You also need disk space and a first-run internet connection. Local models download automatically on first use and are stored under ~/.rembg/models/. The default model is about 1.02 GB. Smaller models exist, and we cover that choice below.
For the Docker route, the CPU image is about 1.6 GB. The NVIDIA CUDA image is about 11 GB and must be built yourself. Start with pip unless you already run Docker daily.
Step 1: install rembg for AI background removal
Create a virtual environment in your project folder, activate it, upgrade pip, then install rembg with the CPU backend and the command-line tools:
python3 -m venv rembg_env
source rembg_env/bin/activate
python -m pip install --upgrade pip
pip install "rembg[cpu,cli]"
On Windows, activate the environment with rembg_env\Scripts\activate instead of the source line. Then prove the command exists before you process anything:
rembg --helpYou should see the subcommands listed: i for single files, p for folders, s for the HTTP server, b for binary streams, d to download models ahead of time, and m to migrate older model folders.
If rembg --help fails, fix the environment first. Confirm the virtual environment is active, confirm your Python version sits inside the supported range, and confirm pip installed into that environment. Do not debug a photo while the command itself is broken.
For an NVIDIA machine, first check the ONNX Runtime installation matrix linked from the repository, because onnxruntime-gpu, CUDA, and cudnn-devel must line up. Only then install the GPU backend:
pip install "rembg[gpu,cli]"The repository gives honest advice here: if the GPU route does not work and you cannot install CUDA or cudnn-devel, use the CPU backend with plain ONNX Runtime instead. A working CPU install beats a broken GPU install every time.
Step 2: run your first cutout
Pick one clear product photo. A shoe on a plain background is perfect. Run the single-file command:
rembg i path/to/input.png path/to/output.pngThe first run downloads the model automatically, so it takes longer than later runs. That pause is normal. Later runs reuse the downloaded model from ~/.rembg/models/.
Open the output and check three things. First, the subject should be complete: no missing corners, no eaten edges. Second, the background should be transparent, which most viewers show as a checkerboard. Third, the edges should be clean at full zoom, especially around straps, handles, and hair.
Always save the output as PNG. Transparency lives in the alpha channel, and JPEG cannot store it. Saving a cutout as JPEG throws away the very thing you just made.
If you omit the output path, rembg writes <input_stem>.out.png next to the input. That is handy for a quick test, but for real work, name your outputs yourself and keep them in a separate folder. Your originals should never be overwritten.
To choose a model explicitly, pass -m:
rembg i -m u2net path/to/input.png path/to/output.pngThe repository describes u2net as a pre-trained model for general use, and u2netp as its lightweight version. The default model produces softer edges but is the largest local model and carries the BRIA commercial-use condition. For business batches, decide the model on licence and edge quality together, not on habit.
To see only the mask rembg produced, add -om. The mask view is the fastest way to understand a bad cutout: if the mask is wrong, no edge trick will save it, and a different model or a better photo is the real fix.
Step 3: batch a whole folder
Single photos prove the install. Folders make the money. The p subcommand processes every image in an input folder and writes results to an output folder:
rembg p path/to/input path/to/output
Keep the input and output folders separate. The input folder is your untouched originals. The output folder is disposable: if a batch goes wrong, delete the outputs and run it again. That one habit prevents the worst accident in photo work, overwriting the only copy of a product shot.
Watch mode processes new or changed files automatically:
rembg p -w path/to/input path/to/outputWatch mode suits a studio corner where photos land in a folder all day. It is also a process that keeps running, so stop it deliberately at the end of the day and check its output before anything reaches a customer.
Before a big batch, run ten representative photos first: your best-lit product, your worst-lit product, a white product on a light background, a dark product, and anything with hair, fur, glass, or thin straps. Judge the batch on those ten. A model that handles your hardest photo will handle the easy ones.
Step 4: fix edges with the right edge mode
Most rembg complaints are edge complaints: a coloured halo, a stair-stepped outline, or hair that looks clipped. Rembg has three ways to turn a mask into a cutout, and they are alternatives, not layers. Pick one.
The default mode suits hard edges: products, cars, logos, and screenshots. There is nothing to correct, so extra processing buys nothing.
Use decontamination, -dc, when the cutout carries a coloured halo. A subject shot against green grass keeps a green rim; against a blue wall, a blue one. Decontamination estimates the true foreground colour and writes that instead. The repository calls the cost negligible, cheap enough to leave on for a whole batch:
rembg i -dc path/to/input.png path/to/output.pngUse alpha matting, -a, when the shape of the mask is wrong: the model cut through strands of hair or left a hard stair-stepped edge where the subject is genuinely soft. Alpha matting re-estimates coverage with a solver, and it is much slower. The solver can fail to converge on some images, in which case rembg falls back to a decontaminated cutout:
rembg i -a path/to/input.png path/to/output.pngViTMatte, -vm, solves the same problem with a network instead of a solver. It recovers more wispy detail, cannot fail to converge, and costs an extra download of about 110 MB on first use. It runs slower than alpha matting.
The repository's pairing advice is practical. Newer models such as birefnet-* and isnet-general-use already produce a soft, well-shaped alpha, so reach for -dc first. Older models such as u2net produce firmer, blockier edges and benefit most from -a on hair-heavy portraits. For portraits, birefnet-portrait with -dc is the suggested starting point.
For unattended batches, prefer -dc over -a: it is faster and cannot fail. Save the slow modes for the photos a human will inspect.
Step 5: use rembg as a library or local server
If you are building rembg into your own tool, import it as a library. The simplest form reads bytes in and writes bytes out:
from rembg import remove
with open('input.png', 'rb') as i:
with open('output.png', 'wb') as o:
output = remove(i.read())
o.write(output)For batches, reuse one session instead of reloading the model for every file. The repository recommends session reuse for performance:
from pathlib import Path
from rembg import remove, new_session
session = new_session()
for file in Path('path/to/folder').glob('*.png'):
output_path = str(file.parent / (file.stem + ".out.png"))
with open(file, 'rb') as i:
with open(output_path, 'wb') as o:
o.write(remove(i.read(), session=session))Rembg can also run as a local HTTP server:
rembg s --host 0.0.0.0 --port 7000 --log_level infoThe API documentation then lives at http://localhost:7000/api. A server suits a small team that wants one shared machine processing photos for everyone. It also creates a network surface you must protect, which the next section covers.
The Docker route replaces the rembg command with a container run and a mounted folder:
docker run -v .:/data danielgatis/rembg i /data/input.png /data/output.pngMount your model folder into the container if you run it often, so models are not re-downloaded. The repository suggests -v /path/to/models/:/root/.rembg for that purpose.
First-run security steps you must not skip
Run rembg locally first, on your own machine, with your own photos. The local routes send nothing anywhere: the model downloads once, then inference happens on your hardware. That privacy property is a reason to choose rembg, so do not give it away carelessly.
Treat the HTTP server as private by default. Binding to 0.0.0.0 exposes it to your network. Put it behind your own authentication or a reverse proxy before anyone outside your team can reach it, and never expose a raw rembg server to the public internet.
Notice the cloud-model guard. The server keeps cloud models off by default, because a request without its own API key would be billed to the key in the server environment. Only pass --allow-remote-models when you understand whose key pays for every request.
Keep API keys in environment variables, never in scripts you share. The cloud backends read keys such as WITHOUTBG_API_KEY from the environment. A key pasted into a public repository is a bill waiting for a stranger.
Finally, respect the photos themselves. Customer product photos are business assets. Keep originals backed up, process copies, and know which model produced which output before a cutout reaches a public listing.
Backup and update routine
Back up three things: your original photos, your rembg environment definition, and your model folder. The originals are irreplaceable. The environment can be rebuilt from one pip command if you record it. The model folder under ~/.rembg/models/ saves you a large re-download after a machine rebuild.
Record your working setup in a small note: Python version, the exact install command, the model name, and the edge mode. When an update changes behaviour, that note tells you what changed. Without it, you are guessing.
Update deliberately, not automatically. Upgrade rembg in a test environment, rerun your ten representative photos, and compare edges before the new version touches real listings. Model defaults and edge behaviour can shift between releases.
If you upgraded from an old rembg version, your models may still sit in the legacy ~/.u2net folder. Rembg still reads that folder, and rembg m migrates downloads into the new layout while leaving the originals in place. Run rembg m --dry-run first to see what would move.
Common errors and fixes
The install fails or rembg is not found. Check the Python version first: outside the range from 3.11 to below 3.14, ONNX Runtime compatibility is the usual cause. Then confirm the virtual environment is active and pip installed into it.
The GPU install fails. The repository is blunt about this: NVIDIA setups may require onnxruntime-gpu, CUDA, and cudnn-devel to line up. Check the ONNX Runtime installation matrix. If the matrix does not fit your system, install the CPU backend and move on. Chasing CUDA for a week costs more than the seconds a GPU saves.
The first run seems stuck. It is probably downloading a model. The default model is about 1.02 GB. Give the first run time and bandwidth, or pre-download models with the d subcommand on a fast connection before a deadline.
The output has no transparency. You saved a JPEG, or your viewer flattened the image. Save PNG and check the alpha channel. The cutout cannot survive a format that has no alpha.
A coloured halo rings the subject. That is background colour mixed into soft edge pixels. Run the photo again with -dc. If the mask shape itself is wrong, move to -a or -vm on that photo.
Hair looks clipped or blocky. Older models produce firmer edges. Try birefnet-portrait with -dc for portraits, and -vm when hair detail matters more than runtime.
A batch produced one bad result in a hundred. That is normal model behaviour, not a broken install. Keep a human spot-check in the workflow, and fix single failures with a different model or edge mode instead of rerunning the whole folder.
An interrupted download left strange files. Interrupted downloads leave tmp* files behind. The migration command's --clean-orphans option removes those leftovers.
Tips and tricks that save money
Photograph against a plain background with even light. Rembg is good, but a clean input beats every edge mode. A white wall and soft daylight will save more money than any setting in this guide.
Start with the CPU backend and measure. Time a real folder of fifty photos. If the batch finishes while you make tea, you do not need a GPU, and the money stays in the business.
Use -dc as the batch default and reserve -a and -vm for inspected photos. The cheap mode handles the common halo case, and the slow modes earn their time only where a customer will zoom in.
Keep one model per job. Product hard edges, portraits, and anime-style images are different problems, and the model list reflects that: u2net for general use, birefnet-portrait for portraits, isnet-anime for anime characters. Switching models per folder beats forcing one model through everything.
Write outputs to a dated folder per batch. When a listing looks wrong a month later, you can trace which model, mode, and original produced it.
The real cost maths
Rembg's licence fee is $0 under the MIT License. The honest comparison is against a hosted remove-background API that charges per image.
On the official Photoroom API pricing page, checked on December 5, 2026, the Remove Background API on the Basic plan costs $0.02 per image. The page gives the same maths in plan form: a $20 Basic API plan covers 1,000 images, and a $40 plan covers 2,000 images. Plans are monthly, unused images do not roll over, and a new account gets 10 free production calls to test quality.

Take a realistic small shop: 2,000 product photos a month across new stock and listing refreshes. On Photoroom Basic, that is $40 a month, $480 a year. On rembg running on a computer the shop already owns, the licence cost is $0, and the real costs are electricity, your setup time, and spot-checking.
The break-even line is $40 a month. If your time, electricity, and upkeep for the local route cost less than $40 a month, rembg wins. For most shops processing photos on an existing office PC, they do.
Volume flips the answer in both directions. At 200 photos a month, the hosted bill is about $4 a month, and paying it can be the sensible choice if nobody wants to maintain a Python environment. At 10,000 photos a month, the hosted bill reaches $200 a month, $2,400 a year, and the local route's savings pay for serious hardware.
Two honest caveats belong in the maths. First, the default bria-rmbg model needs a paid BRIA agreement for commercial use, so a business must either choose a model whose terms it has checked or budget for that agreement. Second, hosted APIs include uptime and support. Rembg includes neither. Price your own time like you would price a supplier's.
When not to install rembg for AI background removal
Do not install rembg when nobody on the team can run a Python environment. The route is a virtual environment, a pip install, a model download, and folder discipline. If that sentence already sounds like a support ticket, a hosted API is the honest choice.
Do not use the default model for commercial work without reading its licence. The BRIA condition is stated in the repository. A free tool with a paid model agreement is still a good deal when chosen knowingly, and a legal headache when chosen blindly.
Do not expect rembg to rescue bad photography at scale. Blurry, dark, same-coloured inputs produce weak masks. Fix the photo corner first, then automate.
Do not expose the HTTP server publicly without protection. A shared internal tool is useful. An open endpoint on the internet is an invitation.
Pros and cons
Pros
- $0 MIT software licence fee for the rembg code
- Runs locally, so product photos stay on your machine
- One command for single photos, folders, and watch mode
- CPU route works on ordinary office hardware
- Several models for products, portraits, and general use
- Edge modes for halos, hair, and soft subjects
- Python library and Docker routes for bigger workflows
- No per-image bill on the local route
Cons
- It is a tool, not a hosted dashboard with support
- Python version must sit in the supported range
- Model weights carry separate licences to check
- The default model needs a paid agreement for commercial use
- First run downloads a large model
- GPU setup can become a CUDA project of its own
- Edge quality still needs human spot-checks
- No vendor uptime or support desk
Our verdict
Install rembg for AI background removal when your real job is cutting out product and portrait photos on hardware you control, with someone who can run a Python environment. Start with the CPU backend, prove one cutout, then batch a folder with outputs kept separate from originals.
The maths favors rembg at steady volume: $0 in licence fees against $0.02 per image on Photoroom's Basic Remove Background API, which is $40 a month and $480 a year at 2,000 photos a month. The break-even line is $40 a month for your time, electricity, and upkeep.
Choose the model with your eyes open. The rembg code is MIT, but the default bria-rmbg model requires a paid BRIA agreement for commercial use. For business batches, check the model source licence first, use -dc as the batch default, and reserve the slow edge modes for photos a customer will inspect.
Choose a hosted API when volume is tiny, support matters, or nobody wants to own a Python environment. Choose rembg when the photos keep coming and the per-image bill has become a line item you resent.
FAQ
Is rembg free for a business?
The rembg code is MIT licensed, so the rembg software licence fee is $0, including for business use of the code. Model weights are separate: the repository states that weights carry their own licences, and the default bria-rmbg model requires a paid BRIA agreement for commercial use. Check your chosen model's source licence before commercial batches.
Do I need a GPU to install rembg?
No. The CPU backend installs with pip install "rembg[cpu,cli]" and runs on ordinary hardware. A GPU helps at high volume, but the NVIDIA route requires ONNX Runtime, CUDA, and cuDNN versions to line up. Measure a real CPU batch before buying hardware.
Why does the first rembg run take so long?
The first run downloads the model. Local models are fetched automatically on first use and stored under ~/.rembg/models/, and the default model is about 1.02 GB. Later runs reuse the downloaded model and start quickly.
Why does my cutout have a coloured halo?
Soft edge pixels mix foreground and background colour, so a green or blue background survives as a rim around hair and fine detail. Run the photo with -dc to decontaminate the edge colour. If the mask shape itself is wrong, use -a or -vm on that photo.
Is rembg enough, or do I need a hosted API?
Rembg is enough when you process steady photo volume on your own hardware and can spot-check results. A hosted API fits when volume is small, uptime and support matter, or nobody wants to maintain a Python environment. At 2,000 photos a month, the hosted maths is $40 a month; rembg's licence cost stays $0.
Strategic Pivot
Before you commit to a per-image bill for a year of product photos, run your own numbers. Our free AI Cost Calculator turns a per-image price and your monthly volume into a break-even line you can defend. Two minutes there can show whether $0.02 per image is cheap, expensive, or irrelevant next to the computer already sitting in your office.
Sources
- Rembg GitHub repository: https://github.com/danielgatis/rembg
- Photoroom API pricing: https://www.photoroom.com/api/pricing
- OpenCV guide: https://aitbizhub.com/install-opencv-for-computer-vision-projects/
- YOLO guide: https://aitbizhub.com/install-yolo-for-ai-object-detection-projects/
- Segment Anything Model guide: https://aitbizhub.com/use-segment-anything-model-for-image-segmentation/
Price note — updated December 5, 2026: Prices in this post were checked on December 5, 2026. When you are reading this, the price may be lower or higher. Check the official pricing page before you buy.
Pros
- $0 MIT software licence fee for the rembg code
- runs locally, so product photos stay on your machine
- one command for single photos, folders, and watch mode
- CPU route works on ordinary office hardware
- several models for products, portraits, and general use
- edge modes for halos, hair, and soft subjects
- Python library and Docker routes for bigger workflows
- no per-image bill on the local route
Cons
- it is a tool, not a hosted dashboard with support
- Python version must sit in the supported range
- model weights carry separate licences to check
- the default model needs a paid agreement for commercial use
- first run downloads a large model
- GPU setup can become a CUDA project of its own
- edge quality still needs human spot-checks
- no vendor uptime or support desk
Install rembg for AI background removal when your real job is cutting out product and portrait photos on hardware you control, with someone who can run a Python environment. Start with the CPU backend, prove one cutout, then batch a folder with outputs kept separate from originals. The maths favors rembg at steady volume: $0 in licence fees against $0.02 per image on Photoroom's Basic Remove Background API, which is $40 a month and $480 a year at 2,000 photos a month. The break-even line is $40 a month for your time, electricity, and upkeep. Choose the model with your eyes open. The rembg code is MIT, but the default bria-rmbg model requires a paid BRIA agreement for commercial use. For business batches, check the model source licence first, use -dc as the batch default, and reserve the slow edge modes for photos a customer will inspect. Choose a hosted API when volume is tiny, support matters, or nobody wants to own a Python environment. Choose rembg when the photos keep coming and the per-image bill has become a line item you resent.
