Downloads · 30 days
0
onnx-community/BiRefNet_dynamic-1024x1024-ONNX-CUDA
BiRefNet_dynamic-1024x1024-ONNX-CUDA is a image segmentation model from onnx-community. Use it for the image segmentation task on the model card, and read the license before you ship it in a product. It is set up for onnxruntime. The card lists the license as mit.
<h1 align="center"Bilateral Reference for High-Resolution Dichotomous Image Segmentation</h1
Downloads · 30 days
0
Access
Public
Updated Sep 4, 2026
Repo size
467 MB
Likes
0
Public
Click a slice to open those files.
.onnx467 MB · 100%
From the Hugging Face model README
| DIS-Sample_1 | DIS-Sample_2 |
|---|---|
| <img src="https://drive.google.com/thumbnail?id=1ItXaA26iYnE8XQ_GgNLy71MOWePoS2-g&sz=w400" /> | <img src="https://drive.google.com/thumbnail?id=1Z-esCujQF_uEa_YJjkibc3NUrW4aR_d4&sz=w400" /> |
This repository provides FP16 ONNX weights for ZhengPeng7/BiRefNet_dynamic, exported for ONNX Runtime CUDA and NVIDIA Triton. For Transformers.js and WebGPU, use onnx-community/BiRefNet_dynamic-1024x1024-ONNX.
For more information about BiRefNet, see the official repository.
| Name | Data type | Shape | |
|---|---|---|---|
| Input | IMAGE | FP16 | [batch, 3, 1024, 1024] |
| Output | ALPHA | FP16 | [batch, 1, height, width] |
The batch axis is dynamic. The spatial input size is fixed at 1024 × 1024, and the output spatial size follows the input. ALPHA is a foreground probability in [0, 1]; sigmoid is included in the graph.
The model uses ONNX opset 19 and standard ONNX DeformConv operators. Use a CUDA-enabled ONNX Runtime build that supports FP16 DeformConv.
Install the dependencies:
pip install huggingface_hub numpy onnxruntime-gpu pillow
Run inference and save the foreground mask:
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from PIL import Image
model_path = hf_hub_download(
"onnx-community/BiRefNet_dynamic-1024x1024-ONNX-CUDA",
"onnx/model.onnx",
)
image = Image.open("input.png").convert("RGB")
resized = image.resize((1024, 1024), Image.Resampling.BILINEAR)
pixel_values = np.asarray(resized, dtype=np.float32) / 255.0
mean = np.asarray([0.485, 0.456, 0.406], dtype=np.float32)
std = np.asarray([0.229, 0.224, 0.225], dtype=np.float32)
pixel_values = (pixel_values - mean) / std
pixel_values = np.transpose(pixel_values, (2, 0, 1))[None].astype(np.float16)
session = ort.InferenceSession(
model_path,
providers=["CUDAExecutionProvider"],
)
alpha = session.run(["ALPHA"], {"IMAGE": pixel_values})[0][0, 0]
mask = Image.fromarray((np.clip(alpha, 0, 1) * 255).astype(np.uint8))
mask.resize(image.size, Image.Resampling.BILINEAR).save("mask.png")
Do not apply sigmoid to the output again.
Place the ONNX file at birefnet_dynamic/1/model.onnx in the Triton model repository and use:
name: "birefnet_dynamic"
platform: "onnxruntime_onnx"
max_batch_size: 1
input [
{ name: "IMAGE" data_type: TYPE_FP16 dims: [ 3, 1024, 1024 ] }
]
output [
{ name: "ALPHA" data_type: TYPE_FP16 dims: [ 1, -1, -1 ] }
]
instance_group [
{ kind: KIND_GPU count: 1 }
]
Configure dynamic batching and queue limits according to the serving workload.
ZhengPeng7/BiRefNet_dynamic at revision 280306042f57b7a33854319da62fd86aaa89ec4c1.4735e-50.004486Artifact details and checksums are available in manifest.json.
@article{BiRefNet,
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}
}