SAVRN
Search Contact SAVRN

Open-weight model · Image segmentation

BiRefNet_HR-matting

by Peng Zheng ZhengPeng7/BiRefNet_HR-matting

This repo is the official implementation of "Bilateral Reference for High-Resolution Dichotomous Image Segmentation" (CAAI AIR 2024). Visit our GitHub repo: https://github.com/ZhengPeng7/BiRefNet for more details -- codes, docs, and model zoo!

Parameters221M
Context
Weights444.5 MB
Licensemit
AccessOpen weights
Monthly Downloads41.4k

Runs On

What it takes to serve BiRefNet_HR-matting (221M parameters): the memory its weights need at each precision, and the cheapest way to rent enough data-center GPUs to hold them.

PrecisionWeightsMemory neededCheapest setupPer hourAlso fits
16-bit 0.4 GB 0.5 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00
8-bit 0.2 GB 0.3 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00
4-bit 0.1 GB 0.1 GB 1x MI300X (192 GB)
Vultr
$1.85 1x H100 $1.99 · 1x MI325X $2.00

Memory is the weights at that precision plus 20% for the runtime and a short context; a long context needs more. Prices are the lowest on-demand hourly rates in the SAVRN Index, read Sep 18, 2026.

Model Card

By Peng Zheng, published under mit, revision 5d6b6f8adcb5.

This repo is the official implementation of "Bilateral Reference for High-Resolution Dichotomous Image Segmentation" (CAAI AIR 2024). Visit our GitHub repo: https://github.com/ZhengPeng7/BiRefNet for more details -- codes, docs, and model zoo! This repo contains the weights of BiRefNet proposed in our paper, which has achieved the SOTA performance on three tasks (DIS, HRSOD, and COD). Go to my GitHub page for BiRefNet codes and the latest updates: https://github.com/ZhengPeng7/BiRefNet:) + Online Image Inference on Colab: + Online Inference with GUI on Hugging Face with adjustable resolutions: + Inference and evaluation of your given weights: + Many thanks to @freepik for their generous…

Read Peng Zheng's full model card

This BiRefNet was trained with images in 2048x2048 for higher resolution image matting with transparency.

Performance:

All tested in FP16 mode.

Dataset Method Resolution maxFm wFmeasure MAE Smeasure meanEm HCE maxEm meanFm adpEm adpFm mBA maxBIoU meanBIoU
TE-AM-2k BiRefNet_HR-matting-epoch_135 2048x2048 .974 .997 .989 .002 .998 .987 .988 .961 .981 .000 .879 .965 .893
TE-P3M-500-NP BiRefNet_HR-matting-epoch_135 2048x2048 .980 .996 .989 .002 .997 .987 .989 .880 .900 .000 .853 .947 .897
TE-AM-2k BiRefNet-matting-epoch_100 1024x1024 .973 .996 .990 .003 .997 .987 .989 .987 .991 .000 .846 .952 .890
TE-P3M-500-NP BiRefNet-matting-epoch_100 1024x1024 .979 .996 .990 .003 .997 .987 .989 .928 .951 .000 .830 .940 .891
TE-AM-2k BiRefNet-matting-epoch_100 2048x2048 .971 .996 .990 .003 .997 .987 .988 .990 .992 .000 .838 .941 .891
TE-P3M-500-NP BiRefNet-matting-epoch_100 2048x2048 .978 .995 .990 .003 .996 .987 .989 .955 .971 .000 .818 .931 .891

Bilateral Reference for High-Resolution Dichotomous Image Segmentation

Peng Zheng 1,4,5,6,  Dehong Gao 2,  Deng-Ping Fan 1*,  Li Liu 3,  Jorma Laaksonen 4,  Wanli Ouyang 5,  Nicu Sebe 6
1 Nankai University  2 Northwestern Polytechnical University  3 National University of Defense Technology  4 Aalto University  5 Shanghai AI Laboratory  6 University of Trento 
DIS-Sample_1 DIS-Sample_2

This repo is the official implementation of "Bilateral Reference for High-Resolution Dichotomous Image Segmentation" (CAAI AIR 2024).

Visit our GitHub repo: https://github.com/ZhengPeng7/BiRefNet for more details -- codes, docs, and model zoo!

How to use

0. Install Packages:

pip install -qr https://raw.githubusercontent.com/ZhengPeng7/BiRefNet/main/requirements.txt

1. Load BiRefNet:

Use codes + weights from HuggingFace

Only use the weights on HuggingFace -- Pro: No need to download BiRefNet codes manually; Con: Codes on HuggingFace might not be latest version (I'll try to keep them always latest).

# Load BiRefNet with weights
from transformers import AutoModelForImageSegmentation
birefnet = AutoModelForImageSegmentation.from_pretrained('ZhengPeng7/BiRefNet_HR-matting', trust_remote_code=True)
Use codes from GitHub + weights from HuggingFace

Only use the weights on HuggingFace -- Pro: codes are always latest; Con: Need to clone the BiRefNet repo from my GitHub.

# Download codes
git clone https://github.com/ZhengPeng7/BiRefNet.git
cd BiRefNet
# Use codes locally
from models.birefnet import BiRefNet

# Load weights from Hugging Face Models
birefnet = BiRefNet.from_pretrained('ZhengPeng7/BiRefNet_HR-matting')
Use codes from GitHub + weights from local space

Only use the weights and codes both locally.

# Use codes and weights locally
import torch
from utils import check_state_dict

birefnet = BiRefNet(bb_pretrained=False)
state_dict = torch.load(PATH_TO_WEIGHT, map_location='cpu')
state_dict = check_state_dict(state_dict)
birefnet.load_state_dict(state_dict)
Use the loaded BiRefNet for inference
# Imports
from PIL import Image
import matplotlib.pyplot as plt
import torch
from torchvision import transforms
from models.birefnet import BiRefNet

birefnet = ... # -- BiRefNet should be loaded with codes above, either way.
torch.set_float32_matmul_precision(['high', 'highest'][0])
birefnet.to('cuda')
birefnet.eval()
birefnet.half()

def extract_object(birefnet, imagepath):
    # Data settings
    image_size = (2048, 2048)
    transform_image = transforms.Compose([
        transforms.Resize(image_size),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])

    image = Image.open(imagepath)
    input_images = transform_image(image).unsqueeze(0).to('cuda').half()

    # Prediction
    with torch.no_grad():
        preds = birefnet(input_images)[-1].sigmoid().cpu()
    pred = preds[0].squeeze()
    pred_pil = transforms.ToPILImage()(pred)
    mask = pred_pil.resize(image.size)
    image.putalpha(mask)
    return image, mask

# Visualization
plt.axis("off")
plt.imshow(extract_object(birefnet, imagepath='PATH-TO-YOUR_IMAGE.jpg')[0])
plt.show()

2. Use inference endpoint locally:

You may need to click the deploy and set up the endpoint by yourself, which would make some costs.

import requests
import base64
from io import BytesIO
from PIL import Image


YOUR_HF_TOKEN = 'xxx'
API_URL = "xxx"
headers = {
    "Authorization": "Bearer {}".format(YOUR_HF_TOKEN)
}

def base64_to_bytes(base64_string):
    # Remove the data URI prefix if present
    if "data:image" in base64_string:
        base64_string = base64_string.split(",")[1]

    # Decode the Base64 string into bytes
    image_bytes = base64.b64decode(base64_string)
    return image_bytes

def bytes_to_base64(image_bytes):
    # Create a BytesIO object to handle the image data
    image_stream = BytesIO(image_bytes)

    # Open the image using Pillow (PIL)
    image = Image.open(image_stream)
    return image

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()

output = query({
    "inputs": "https://hips.hearstapps.com/hmg-prod/images/gettyimages-1229892983-square.jpg",
    "parameters": {}
})

output_image = bytes_to_base64(base64_to_bytes(output))
output_image

This BiRefNet for standard dichotomous image segmentation (DIS) is trained on DIS-TR and validated on DIS-TEs and DIS-VD.

This repo holds the official model weights of "Bilateral Reference for High-Resolution Dichotomous Image Segmentation" (CAAI AIR 2024).

This repo contains the weights of BiRefNet proposed in our paper, which has achieved the SOTA performance on three tasks (DIS, HRSOD, and COD).

Go to my GitHub page for BiRefNet codes and the latest updates: https://github.com/ZhengPeng7/BiRefNet :)

Try our online demos for inference:

  • Online Image Inference on Colab:
  • Online Inference with GUI on Hugging Face with adjustable resolutions:
  • Inference and evaluation of your given weights:

Acknowledgement:

  • Many thanks to @freepik for their generous support on GPU resources for training this model!

Citation

@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},
  volume = {3},
  pages = {9150038},
  year={2024}
}

Configuration

Architecture
BiRefNet

Identity and Version

Repository
ZhengPeng7/BiRefNet_HR-matting
Publisher
Peng Zheng
Task
Image segmentation
Modality
Image
Library
birefnet
Parameters
221M parameters
Languages
Not stated by the source
Revision
5d6b6f8adcb5b417c871b1d84ceaae9871355b7f
First published
2025-02-12
Last updated
2026-02-04

Files and Weights

8 files, 444.6 MB in total. The weights are 1 file totalling 444.5 MB in safetensors.

Weights1 file · 444.5 MB
Configuration4 files · 97.6 KB
Documentation1 file · 11.5 KB
Other1 file · 149 B
Repository1 file · 1.5 KB
Every file
FileTypeSizeSHA-256
model.safetensorsWeights444.5 MB a5a4de698739
BiRefNet_config.pyConfiguration298 B
birefnet.pyConfiguration92.1 KB
config.jsonConfiguration416 B
handler.pyConfiguration4.8 KB
README.mdDocumentation11.5 KB
requirements.txtOther149 B
.gitattributesRepository1.5 KB

License and Download

License
mit
Access
Open weights, no gate
Download size
444.5 MB
Download from Peng Zheng

Released by Peng Zheng through its official repository on Hugging Face. Read the license.

Built From

Memory Requirements

PrecisionWeights in memory
As published444.5 MB
16-bit0.4 GB
8-bit0.2 GB
4-bit0.1 GB

Weights only, from the published parameter count; the key-value cache and runtime add to this.

Questions About BiRefNet_HR-matting

How much GPU memory does BiRefNet_HR-matting need?

About 0.5 GB at 16-bit and 0.1 GB at 4-bit: the weights (221M parameters) plus a working margin. A long context needs more.

What is the cheapest GPU to run BiRefNet_HR-matting on?

At 16-bit, 1x MI300X from $1.85 an hour; at 4-bit, 1x MI300X from $1.85 an hour, at the lowest on-demand prices the SAVRN Index lists.

Can I use BiRefNet_HR-matting commercially?

Yes. BiRefNet_HR-matting is released under MIT License. The MIT License is a short permissive license. It permits commercial use, modification and redistribution, provided the copyright notice and permission notice are included.

Similar Models

Model · Image segmentation

BiRefNet

Peng Zheng

This repo is the official implementation of "Bilateral Reference for High-Resolution Dichotomous Image Segmentation" (CAAI AIR 2024). Visit our GitHub repo: https://github.com/ZhengPeng7/BiRefNet for more details -- codes, docs, and model zoo! This repo contains the weights of BiRefNet proposed in our paper, which has achieved the SOTA performance on three tasks (DIS, HRSOD, and COD). Go to my GitHub page for BiRefNet codes and the latest updates: https://github.com/ZhengPeng7/BiRefNet:) + Online Image Inference on Colab: + Online Inference with GUI on Hugging Face with adjustable resolutions: + Inference and evaluation of your given weights: + Many thanks to @Freepik for their generous…

Open weights mit 221M parameters birefnet

Model · Image segmentation

RMBG-2.0

BRIA AI

href="https://huggingface.co/briaai/FIBO" target="blank" rel="noopener" aria-label="Explore FIBO on Hugging Face" style=" src="https://huggingface.co/front/assets/huggingfacelogo-noborder.svg" alt="Hugging Face" width="18" height="18" style="display:block" RMBG v2.0 is our new state-of-the-art background removal model significantly improves RMBG v1.4. The model is designed to effectively separate foreground from background in a range of categories and image types. This model has been trained on a carefully selected dataset, which includes: general stock images, e-commerce, gaming, and advertising content, making it suitable for commercial use cases powering enterprise content creation at…

Access requested at publisher other 221M parameters transformers

Model · Image segmentation

BiRefNet_HR

Peng Zheng

This repo is the official implementation of "Bilateral Reference for High-Resolution Dichotomous Image Segmentation" (CAAI AIR 2024). Visit our GitHub repo: https://github.com/ZhengPeng7/BiRefNet for more details -- codes, docs, and model zoo! This repo contains the weights of BiRefNet proposed in our paper, which has achieved the SOTA performance on three tasks (DIS, HRSOD, and COD). Go to my GitHub page for BiRefNet codes and the latest updates: https://github.com/ZhengPeng7/BiRefNet:) + Online Image Inference on Colab: + Online Inference with GUI on Hugging Face with adjustable resolutions: + Inference and evaluation of your given weights: + Many thanks to @freepik for their generous…

Open weights mit 221M parameters birefnet

Model · Image segmentation

BiRefNet-portrait

Peng Zheng

Check the main BiRefNet model repo for more info and how to use it: https://huggingface.co/ZhengPeng7/BiRefNet/blob/main/README.md Also check the GitHub repo of BiRefNet for all things you may want: https://github.com/ZhengPeng7/BiRefNet + Many thanks to @fal for their generous support on GPU resources for training this BiRefNet for portrait matting.

Open weights mit 221M parameters birefnet

Model · Image segmentation

BiRefNet_dynamic

Peng Zheng

For performance of different epochs, check the evalresults-xxx folder for it on my google drive. This repo is the official implementation of "Bilateral Reference for High-Resolution Dichotomous Image Segmentation" (CAAI AIR 2024). Visit our GitHub repo: https://github.com/ZhengPeng7/BiRefNet for more details -- codes, docs, and model zoo! This repo contains the weights of BiRefNet proposed in our paper, which has achieved the SOTA performance on three tasks (DIS, HRSOD, and COD). Go to my GitHub page for BiRefNet codes and the latest updates: https://github.com/ZhengPeng7/BiRefNet:) + Online Image Inference on Colab: + Online Inference with GUI on Hugging Face with adjustable resolutions: +…

Open weights mit 221M parameters birefnet

Model · Image segmentation

BiRefNet-matting

Peng Zheng

Check the main BiRefNet model repo for more info and how to use it: https://huggingface.co/ZhengPeng7/BiRefNet/blob/main/README.md Also check the GitHub repo of BiRefNet for all things you may want: https://github.com/ZhengPeng7/BiRefNet + Many thanks to @freepik for their generous support on GPU resources for training this model!

Open weights mit 221M parameters birefnet