nobg

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:

PieceRole
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

Where to go next

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},
}

On this page