Repository navigation
Getting Started
This page gets the background removal service running on your machine and shows your first request. It takes a few minutes, most of it downloading PyTorch and the model weights.
-
Python 3 and
pip. - Enough free disk space for PyTorch and the model weights.
- Optional: an NVIDIA GPU with CUDA. The IS-Net app uses it automatically when PyTorch can see it; otherwise it runs on CPU.
- Optional but recommended: a virtual environment.
git clone https://github.com/selldone/bg-remove.git
cd bg-removepython -m venv .venv
# Windows: .venv\Scripts\activate
source .venv/bin/activate
pip install -r requirements.txtrequirements.txt installs torch, torchvision, numpy, pillow, uvicorn, fastapi, aiofiles, python-multipart, scikit-image and gdown.
For GPU inference, install a CUDA-enabled PyTorch build that matches your driver (see pytorch.org) before or instead of the default
torchpackage.
The IS-Net weights file isnet-general-use.pth is not stored in Git. Download it from Google Drive and put it in service/isnet/model/.
With gdown (installed by requirements.txt):
mkdir -p service/isnet/model
gdown 1XHIzgTzY5BQHw140EDIgwIb53K659ENH -O service/isnet/model/isnet-general-use.pthThe final layout must be:
service/isnet/model/isnet-general-use.pth
Run from the repository root, because the model paths are relative (./service/isnet/model):
uvicorn service.app:app --host localhost --port 8000On start-up the engine prints the device it uses, for example Device: cuda or Device: cpu.
To use the older U²-Net model instead, see Models.
curl -X POST -F "file=@product.jpg" http://localhost:8000/remove-bg --output product.png -D --
product.pngnow contains the image with a transparent background. -
-D -prints the response headers, includingS-Processing-TimeandS-Processing-Device.
You can also try the endpoint in the browser with FastAPI's interactive docs at http://localhost:8000/docs.
- API Reference — full request and response details.
- Client Examples — call the service from Python, JavaScript or PHP.
- Models — IS-Net vs U²-Net.
- Deployment — run it on a server.
- FAQ