This project is a lightweight web server built with FastAPI that wraps the powerful rembg library, allowing you to remove image backgrounds through simple API calls.
It has been tested and confirmed to run smoothly on a server with 2 CPU cores and 2GB of RAM.
We have also developed a companion browser extension, Banana Peel, which allows you to right-click on any image on a webpage to remove its background. Feel free to try it out.
You can install and run this service in one of two ways.
- Clone this repository to your local machine:
git clone https://github.com/Yorick-Ryu/rembg-server.git cd rembg-server - Install the required dependencies:
pip install "rembg[cpu,cli]" - Start the server:
The server will start on port
python main.py
7001by default.
-
Pull the pre-built Docker image from
ghcr.io:docker pull ghcr.io/yorick-ryu/rembg-server:latest
-
Run the Docker container:
docker run -d --name rembg-service -p 7001:7001 ghcr.io/yorick-ryu/rembg-server:latest
If you need to use a custom port (e.g.,
8080), you can run it like this:docker run -d -p 8080:8080 -e PORT=8080 --name rembg-service ghcr.io/yorick-ryu/rembg-server:latest
The server uses a models.json file to manage and configure the available AI models.
- models: An array of model configurations. Each configuration includes the model's
name,desc(description), andenabledstatus. - default_model: This model will be used when an API request does not specify one.
Example models.json:
{
"models": [
{
"name": "u2net",
"desc": "General-purpose model",
"enabled": false
},
{
"name": "silueta",
"desc": "Lightweight general-purpose model",
"enabled": true
},
{
"name": "isnet-general-use",
"desc": "General-purpose model",
"enabled": true
},
{
"name": "isnet-anime",
"desc": "Model for anime-style images",
"enabled": true
}
],
"default_model": "silueta"
}Note: Only models with enabled set to true will be loaded and accessible via the API.
For a more convenient experience, you can use our browser extension, Banana Peel.
- Visit the Banana Peel project page and follow the instructions to install the extension.
- After installation, click the extension icon in your browser's toolbar and enter your server address in the settings (e.g.,
http://127.0.0.1:7001).
Once configured, you can right-click on any image on any webpage to quickly remove its background.
After starting the server, you can access interactive API documentation, automatically generated by FastAPI, by visiting the /docs or /redoc paths.
This endpoint is used to check if the server is running correctly. It returns a welcome message.
- Method:
GET - URL:
/
{
"message": "Welcome to the rembg background removal server."
}Retrieves a list of all currently enabled models.
- Method:
GET - URL:
/models
curl http://your-server-ip:7001/models{
"models": [
{
"name": "silueta",
"desc": "Lightweight general-purpose"
},
{
"name": "isnet-general-use",
"desc": "General-purpose"
},
{
"name": "isnet-anime",
"desc": "Anime"
}
]
}This project supports all models from the rembg library (15+), catering to various needs. For a complete list of models, their descriptions, and performance comparisons, please visit the official rembg documentation:
Here are some popular models:
u2net- A general-purpose background removal model.silueta- A lightweight model for faster processing (only 43MB).isnet-anime- A high-precision model optimized for anime and cartoon-style images.birefnet-portrait- A model designed specifically for portrait segmentation.sam- A powerful, advanced model suitable for various complex scenarios.
This is the core endpoint for background removal.
- Method:
POST - URL:
/remove - Content-Type:
multipart/form-data - Form Data:
file: The image file to be processed (required).model: The name of the model to use (optional, defaults to the one specified indefault_model). The model must be enabled inmodels.json.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file |
File | Yes | - | Image file (e.g., JPG, PNG, WebP) |
model |
String | No | silueta |
The name of the model to use |
- Success: Returns the processed image in PNG format.
- Failure: Returns a JSON object with an error message.
1. Using the default model (silueta):
curl -X POST
-F "file=@/path/to/your/image.jpg"
http://your-server-ip:7001/remove
-o output.png2. Specifying the isnet-anime model for an anime image:
curl -X POST
-F "file=@/path/to/your/anime-image.jpg"
-F "model=isnet-anime"
http://your-server-ip:7001/remove
-o output_anime.png3. Using the isnet-general-use model for a general image:
curl -X POST
-F "file=@/path/to/your/image.jpg"
-F "model=isnet-general-use"
http://your-server-ip:7001/remove
-o output_general.pngIf you request an invalid or disabled model, the server will return an error similar to this:
{
"detail": "Model 'invalid-model' is not available or not enabled. Available models: ['silueta', 'isnet-general-use', 'isnet-anime']"
}This project is built upon the excellent rembg library created by @danielgatis. We extend our sincere gratitude to the author and all contributors of rembg for making powerful AI image processing technology accessible to everyone.
🙏 Special thanks to:
- danielgatis/rembg - The core background removal library.
- The
rembgcommunity and all its contributors. - The researchers behind all the AI models that support this project (e.g., U²-Net, IS-Net, BiRefNet, SAM).