Open source background removal models for image matting
Project description
nobg
A library for image and video matting with HuggingFace Hub integration.
Installation
pip install nobg
Usage
AutoModel
Automatically detect and load the correct model architecture from a HuggingFace repo:
from nobg import AutoModel
model = AutoModel.from_pretrained("nobg/BiRefNet")
Load a specific model
from nobg import AutoModel
model = AutoModel.from_pretrained("nobg/BiRefNet")
AutoProcessor
AutoProcessor loads the matching image processor for a repo. It handles the
resize + ImageNet normalization on the way in, and turns raw model logits back
into an alpha matte at the original resolution on the way out.
from nobg import AutoProcessor
processor = AutoProcessor.from_pretrained("nobg/FeyNobg")
Remove a background with FeyNobg
nobg/FeyNobg is the strongest published model. The processor produces the
normalized pixel_values the model expects and post-processes the raw logits
(B, 1, 1024, 1024) into an alpha matte you can composite onto the image.
import torch
from loadimg import load_img
from nobg import AutoModel, AutoProcessor
model = AutoModel.from_pretrained("nobg/FeyNobg").eval()
processor = AutoProcessor.from_pretrained("nobg/FeyNobg")
image = load_img("input.jpg").convert("RGB")
inputs = processor(image, return_tensors="pt")
with torch.no_grad():
outputs = model(pixel_values=inputs["pixel_values"])
# Alpha matte in [0, 1] resized back to the original image size
alpha = processor.post_process_alpha_matting(
outputs, target_sizes=[(image.height, image.width)]
)[0]
# Composite the cutout onto a transparent background
processor.cutout(image, alpha).save("output.png")
| Input | Output |
|---|---|
Push to HuggingFace Hub
model.push_to_hub("your-username/model-name")
Citation
@software{nobg,
title={nobg: Open Source Background Removal Models for Image and Video Matting},
author={Hichri, Hafedh},
year={2026},
url={https://github.com/feyninc/nobg},
license={Apache-2.0},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nobg-0.2.1.tar.gz.
File metadata
- Download URL: nobg-0.2.1.tar.gz
- Upload date:
- Size: 206.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
366417c3de4aa922622c04403c8ddd1e9c6a6064737d52e2920afcd86849db20
|
|
| MD5 |
b032048991cb22057df1a3027a039979
|
|
| BLAKE2b-256 |
be01825de4867bb11f0c54f04c0a99fab9aa9e4037d8f928b62dfb376ad8d04b
|
File details
Details for the file nobg-0.2.1-py3-none-any.whl.
File metadata
- Download URL: nobg-0.2.1-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f99798f8146bc6632879b41813ad2852855186aa0ab619681d3098a381b2b85
|
|
| MD5 |
517ae8720a0dbd061d2f3a6d068a21a1
|
|
| BLAKE2b-256 |
dd6d805134a7cfc0daf737fae50aeb46dd7496bc461b19b14decab6344fdc2b2
|