Skip to main content

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
input cutout

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nobg-0.2.0.tar.gz (206.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nobg-0.2.0-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file nobg-0.2.0.tar.gz.

File metadata

  • Download URL: nobg-0.2.0.tar.gz
  • Upload date:
  • Size: 206.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for nobg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2457af9232b46ef281a35fcef6c25181887977c1e58dfab270c6f59e8ddc675b
MD5 1fe5454297ab176cc3b501ec6c59f3ee
BLAKE2b-256 0c233bbe8e62e9e9257c8b73733fe93d4bdec99006e989a4b79f678d7282988b

See more details on using hashes here.

File details

Details for the file nobg-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nobg-0.2.0-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

Hashes for nobg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db8321144f2219163f7b307f82542cc8811f29d2ecfade1ef4a04d655ef73ee0
MD5 4241334a6b03f2634188bb0ad949e225
BLAKE2b-256 7ad44012d83872ab6fd2e0673b039fb6d8d98722afd01356a93ddb3bffe1b4ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page