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.2.tar.gz (206.1 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.2-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

Hashes for nobg-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c4570b8d71240ccd0f90089853a2c090c8ca5006c6b710442d5e872e9ef33ca5
MD5 e8df05877f1c8e134706145faedd9a2c
BLAKE2b-256 314ac247c3e2c736f45fde909526b200b30fdbf95fc1e4303e34b7fa70d9186a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nobg-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e52e72b93f03541b958657b9b852bbfe5df55839c3566b96482335aa2e294480
MD5 7da0ff1bb5a8b90a9707d24f1ed8b614
BLAKE2b-256 fd458083d380a178c2ae5f5211d21abebc84628cd7a89a35f33038bb72a8d74f

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