This model has been pushed to the Hub using the PytorchModelHubMixin integration.

Library: nobg

how to load

pip install nobg

use the AutoModel class

from nobg import AutoModel
model = AutoModel.from_pretrained("nobg/FeyNobg")

or you can use the model class directly

from nobg import BiRefNet
model = BiRefNet.from_pretrained("nobg/FeyNobg")

Remove a background

Load the matching processor with AutoProcessor. It produces the normalized pixel_values the model expects and post-processes the raw logits (B, 1, 1024, 1024) into an alpha matte at the original resolution.

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")

Citation

If you use this model, please cite the original paper (https://arxiv.org/abs/2401.03407):

@article{zheng2024birefnet,
  title={Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
  author={Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and
          Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
  journal={CAAI Artificial Intelligence Research},
  year={2024}
}

Contributions

Any contributions are welcome at https://github.com/feyninc/nobg

Downloads last month
28
Safetensors
Model size
0.3B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Paper for nobg/FeyNobg