Skip to content

Getting Started

Mehrdad Pajuhaan edited this page Oct 23, 2026 · 1 revision

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.

Prerequisites

  • 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.

1. Clone the repository

git clone https://github.com/selldone/bg-remove.git
cd bg-remove

2. Install dependencies

python -m venv .venv
# Windows: .venv\Scripts\activate
source .venv/bin/activate

pip install -r requirements.txt

requirements.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 torch package.

3. Download the model

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.pth

The final layout must be:

service/isnet/model/isnet-general-use.pth

4. Start the service

Run from the repository root, because the model paths are relative (./service/isnet/model):

uvicorn service.app:app --host localhost --port 8000

On 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.

5. Remove your first background

curl -X POST -F "file=@product.jpg" http://localhost:8000/remove-bg --output product.png -D -
  • product.png now contains the image with a transparent background.
  • -D - prints the response headers, including S-Processing-Time and S-Processing-Device.

You can also try the endpoint in the browser with FastAPI's interactive docs at http://localhost:8000/docs.

Next steps

Clone this wiki locally