Introduction
What nobg is, what ships in it, and where to go next.
nobg is an open-source Python library for background removal and image matting. It packages
matting models, their image processors, the losses they were trained with and the metrics they are
evaluated on, behind one small API — and it reads from and writes to the HuggingFace Hub at both
ends.
from nobg import AutoModel
model = AutoModel.from_pretrained("feyninc/FeyNobg")
model.process("input.jpg").save("output.png")That is the whole thing: process loads the image, builds the processor the model's own config
implies, runs the forward pass under no_grad in eval mode, post-processes the logits into an alpha
matte at the original resolution, and composites an RGBA cutout.
The output contract
Every model in nobg returns the same thing: raw alpha-matte logits of shape (B, 1, H, W) under
the key logits. That is what makes the models interchangeable, and what lets one shared
post-processing path serve all of them:
| Piece | Role |
|---|---|
model(**inputs)["logits"] | Raw matte logits, not sigmoided |
processor.post_process_alpha_matting(outputs, target_sizes=...) | Logits → (H, W) mattes in [0, 1], one per image, each at its own target size |
processor.refine_foreground(image, alpha) | Unmixed foreground colors, to kill halo fringing |
processor.cutout(image, alpha) | RGBA cutout |
model.predict(processor, image) | All of the above in one call |
model.process(image) | predict with the processor it builds itself |
Models expose extra outputs on top of that contract — BiRefNet its intermediate_logits, SAM3 its
whole instance-detection head — but never instead of it.
What ships in the package
Models
FeyNobg (BiRefNet) and MultiMatte (SAM3), with the strengths of each.
Processors
Preprocessing, post-processing, foreground refinement and compositing.
Losses
BiRefNet's BCE+IoU+SSIM and SAM3's focal+dice objectives.
Metrics
MAE, S/F/E-measure, boundary IoU and the matting metrics, in pure torch.
Where to go next
Installation
uv, pip, torch and the ONNX extra.
Quickstart
Three lines to a cutout, then the pieces underneath.
Text prompts
Cut out a named subject, or one pointed at with a box.
Fine-tuning
Train on your own image/mask pairs with the HuggingFace Trainer.
Links
- GitHub — source, issues and the contributing guide
- PyPI — releases
- 🤗 FeyNobg — the default checkpoint
- 🤗 MultiMatte — the text-promptable one
- 🤗 Space — try it in the browser
License and citation
nobg is Apache-2.0. Meta's SAM weights are not redistributed: converting them with
Sam3.from_origin("facebook/sam3") downloads them from Meta's gated repo under Meta's own
SAM License.
@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},
}