From: ZhengPeng7 <huggingface.co/ZhengPeng7>Newsgroups: alt.freeweights.visionSubject:

BiRefNet

Date: 2026-11-15Commit: e2bf8e4Signed: 2DC28CC7B26A283B ✓

Image segmentation model with 221M parameters. Safetensors weights, 445 MB in all. Published by ZhengPeng7 under MIT.

221M params445MBBiRefNetsafetensorspermissive
FactsParams221MSize445 MBFormatssafetensorsTaskimage segmentationLicenseMITFrom sourcepermissive
$ fw get ZhengPeng7/BiRefNet
# manifest sha256 eae1fb466986… · 445 MB · 9 files
$ fw verify ./BiRefNet ZhengPeng7/BiRefNet
From sourceHosted (signed)ZhengPeng7/BiRefNetLast check: 2026-11-15 02:26 UTC

Get help: custom fine-tune or private deploy. We review your setup before we quote.

Works with

Runs with

Ranked by fit to this model (safetensors), then by GitHub stars.

Overview

Size
445 MB
Weights
444 MB (safetensors)
Parameters
221M
Formats
safetensors
Task
image segmentation
License
MIT (permissive)
Files
9, each with a sha256
Publisher
ZhengPeng7
Added
2026-11-15
Section
alt.freeweights.vision
Lineage

Original release from the publisher.

Where these bytes come from
Publisher at the pinned commit→You

Sources are tried in order. A file counts only when its size and sha256 match the manifest. Sources are checked when you ask for them, not on a timer.

Sources
BadgeHostLast checkResult
From sourcehuggingface.co2026-11-15 02:26 UTCpassed

Model card

From the publisher at commit e2bf8e4. Shown as plain text with links; images open at the publisher.

Bilateral Reference for High-Resolution Dichotomous Image Segmentation#

Peng Zheng 1,4,5,6,&thinsp; Dehong Gao 2,&thinsp; Deng-Ping Fan 1*,&thinsp; Li Liu 3,&thinsp; Jorma Laaksonen 4,&thinsp; Wanli Ouyang 5,&thinsp; Nicu Sebe 6

1 Nankai University&ensp; 2 Northwestern Polytechnical University&ensp; 3 National University of Defense Technology&ensp; 4 Aalto University&ensp; 5 Shanghai AI Laboratory&ensp; 6 University of Trento&ensp;

https://www.sciopen.com/article/pdf/10.26599/AIR.2024.9150038.pdf&ensp; https://arxiv.org/pdf/2401.03407&ensp; https://drive.google.com/file/d/1aBnJ_R9lbnC2dm8dqD0-pzP2Cu-U1Xpt/view?usp=drive_link&ensp; https://www.birefnet.top&ensp; https://drive.google.com/drive/folders/1s2Xe0cjq-2ctnJBR24563yMSCOu4CcxM&ensp; LICENSE&ensp; https://huggingface.co/spaces/ZhengPeng7/BiRefNet_demo&ensp; https://huggingface.co/ZhengPeng7/BiRefNet&ensp; https://colab.research.google.com/drive/14Dqg7oeBkFEtchaHLNpig2BcdkZEogba?usp=drive_link&ensp; https://colab.research.google.com/drive/1MaEiBfJ4xIaZZn0DqKrhydHB8X97hNXl#scrollTo=DJ4meUYjia6S&ensp;

DIS-Sample_1DIS-Sample_2
Image: imageImage: image

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', 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')
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 = (1024, 1024)
    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:#

Image: image

Acknowledgement:#

  • Many thanks to @Freepik for their generous support on GPU resources for training higher resolution BiRefNet models and more of my explorations.
  • Many thanks to @fal for their generous support on GPU resources for training better general BiRefNet models.
  • Many thanks to @not-lain for his help on the better deployment of our BiRefNet model on HuggingFace.

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

Files

9 files · 445 MBWeights 444 MB (safetensors). Sizes and sha256 from the signed manifest.
Hide all 9 files with their sha256
FileSizesha256
.gitattributes1.52 KB11ad7efa24975ee4b0c3c3a38ed18737f0658a5f75a0a96787b576a78a023361
.gitignore1.91 KB32c2a6d082cb35dcec4af9517742b093e3d4fa7e27208fc0d0cbbdfed859bf19
BiRefNet_config.py298 Be7b8c2a74f6cea6a59553d517f71d47f2c1d90e670a13416af17c25fe2f3dc52
README.md9.96 KBceac4a1bb69b807eac5510bff80ff5599f606ef7458bee3b54b68d866e868532
birefnet.py91.9 KB208771ae626f653d64128fbf2d6ac9f8e645c5cc5e286258a73ec3322bbfe5ef
config.json405 Bc97ea21569daf66b205491a4635147dd3bc42c7c168b89d7d75b53f67ef548ae
handler.py4.76 KBb95f5806bfcd575ccff2a9f08816ae0e5d4df1e81b48797f9997f68b531404a5
model.safetensors444 MB9ab37426bf4de0567af6b5d21b16151357149139362e6e8992021b8ce356a154
requirements.txt149 Bbdfdd83a090d31a2acf64f7350653fa63cd8b5d9d6e0ff3e135bea7ce3786341
VersionsEach time the pinned upstream commit or file list changed in this repo. Newest first.
Upstream commitDateContents
e2bf8e4460 pinned now2026-11-15 02:26 UTC9 files · 445 MB

Use it

$ fw get ZhengPeng7/BiRefNet
# manifest sha256 eae1fb466986… · 445 MB · 9 files
$ fw verify ./BiRefNet ZhengPeng7/BiRefNet
fw.pyChecks the signature and every sha256, tries each source in order, resumes.
$ python3 fw.py get https://freeweights.allternit.com/manifests/ZhengPeng7/BiRefNet.json --dir ./BiRefNet $ python3 fw.py verify ./BiRefNet ./ZhengPeng7__BiRefNet.json
hfThe Hugging Face CLI with one setting. Same repo id.
$ HF_ENDPOINT=https://freeweights.allternit.com hf download ZhengPeng7/BiRefNet --revision e2bf8e4460fc8fa32bba5ea4d94b3233d367b0e4 --local-dir ./BiRefNet

License

Name
MIT License
Id
MIT
Class
Permissive
Redistribution
yes
Listing
Hosted (signed)
Decided
License as declared by the publisher. No person read it. 2026-11-15
Text in
README.md
Text sha256
ceac4a1bb69b807eac5510bff80ff5599f606ef7458bee3b54b68d866e868532
Terms gate
No extra terms beyond the license.

Read the license text

Licenses are checked against the license table. A custom license passes only after a person reads it.

Provenance

From: ZhengPeng7 <huggingface.co/ZhengPeng7>Newsgroups: alt.freeweights.visionSubject: BiRefNetDate: 2026-11-15Commit: e2bf8e4Signed: 2DC28CC7B26A283B ✓
Upstream
ZhengPeng7/BiRefNet
Pinned commit
e2bf8e4460fc8fa32bba5ea4d94b3233d367b0e4
Manifest
BiRefNet.json · .minisig
Manifest sha256
eae1fb466986524bb23190b7f8fc7d26bd42b57e0d3fe12351a9741d6c825631
Signature
minisign, Ed25519, key 2DC28CC7B26A283B
Created
2026-11-15 02:26 UTC
Generator
freeweights-manifest/0.1.0
Takedowns
None.

How to verify

$ curl -O https://freeweights.allternit.com/manifests/ZhengPeng7/BiRefNet.json $ curl -O https://freeweights.allternit.com/manifests/ZhengPeng7/BiRefNet.json.minisig $ minisign -Vm BiRefNet.json -P RWQ7KGqyx4zCLXtUFOqvfv8L3g+8fpKJ1FsuxPyOYMF+4KufbUxKq1Oq $ shasum -a 256 <file> # compare with the Files tab

A manifest whose signature fails must be rejected. A file whose size or sha256 does not match must be discarded. Verify a download

Model tree

2 models in the catalog name this one as their parent.

Fine-tunes
1
Quantizations
1
Fine-tunes 1
Quantizations 1
Get it
Download
$ HF_ENDPOINT=https://freeweights.allternit.com hf download ZhengPeng7/BiRefNet
Open in Freeweights Studio

Pull, verify and run it in the Allternit app on Desktop, web or phone.

Signed manifest
minisign, key 2DC28CC7B26A283B. BiRefNet.json. Provenance. Takedown history: none.

Variants

1 quantized or adapter build of BiRefNet. Each has its own license check and page.

From: dima806 <huggingface.co/dima806>Subject: ai_vs_real_image_detection
From: legekka <huggingface.co/legekka>Subject: AI-Anime-Image-Detector-ViT
From: onnx-community <huggingface.co/onnx-community>Subject: AI-Anime-Image-Detector-ViT-ONNX
From: AICodexLab <huggingface.co/AICodexLab>Subject: answerdotai-ModernBERT-base-ai-detector
From: onnx-community <huggingface.co/onnx-community>Subject: answerdotai-ModernBERT-base-ai-detector-ONNX
From: onnx-community <huggingface.co/onnx-community>Subject: bart-large-cnn-ONNX