Instructions to use anudit/BiRefNet_lite-2K-ONNX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- BiRefNet
How to use anudit/BiRefNet_lite-2K-ONNX with BiRefNet:
# Option 1: use with transformers from transformers import AutoModelForImageSegmentation birefnet = AutoModelForImageSegmentation.from_pretrained("anudit/BiRefNet_lite-2K-ONNX", trust_remote_code=True)# Option 2: use with BiRefNet # Install from https://github.com/ZhengPeng7/BiRefNet from models.birefnet import BiRefNet model = BiRefNet.from_pretrained("anudit/BiRefNet_lite-2K-ONNX") - Notebooks
- Google Colab
- Kaggle
BiRefNet_lite-2K β ONNX fp16 (dynamic input size, low-memory graph)
ONNX export of ZhengPeng7/BiRefNet_lite-2K
(Swin-T backbone, 44M params, trained for 2560Γ1440), made for in-browser inference with
birefnet-webgpu.
| file | precision | input | output | size |
|---|---|---|---|---|
onnx/model_fp16.onnx |
fp16 weights, fp32 I/O | input_image [1,3,H,W] (ImageNet-normalised RGB) |
output_image [1,1,H,W] logits (apply sigmoid) |
~91 MB |
H and W are dynamic but must both be multiples of 64 (Swin patch merging, including the half-resolution
multi-scale path). Resize your image to such a size (the 2K model was trained at 2560Γ1440; birefnet-webgpu
buckets the long side to 512 / 1024 / 1536 / 2048 / 2560 and keeps the aspect ratio), run, then resize the mask back.
Verified against PyTorch at 512Β², 640Γ960, 1024Β², 1536Γ1024 and 1472Γ2560.
What is different from a plain torch.onnx.export
A naive export needs 11 GB of activations at 2560Γ1440, which is impossible in a browser tab.
This graph computes the same function with ~0.45 GB peak live activations at 2560Γ1472 (1.1 GB allocated on GPU in
the WebGPU engine; far less at smaller sizes):
- Deformable convolutions use the standard ONNX
DeformConvop (opset 19+) instead of an im2col gather chain. - The 5-branch ASPP concat (1280 ch) followed by a 1Γ1 conv is rewritten as a sum of five 1Γ1 convs.
- The full-resolution decoder tail (bilinear upsample β concat β 1Γ1 conv, and the
ipt_blk1branch) is algebraically collapsed into a 1Γ1 conv at low resolution plus one 5Γ5 conv on the input image, with the branch's bias response built exactly from a single-channel conv over a ones image. This is exact except for a ~1 px outer ring where zero-padding interacts with the folded convolutions (max logit difference β 0.64 there, β€ 7e-3 anywhere else). - GELU is exported as the
Geluop (opset 20).
fp32 graph IoU vs the original PyTorch model: β₯ 0.999997 on the test sizes; fp16 graph IoU 0.9995 (2560Γ1440, ORT CPU).
Requires a runtime that implements DeformConv and Gelu (verified with onnxruntime on CPU; the birefnet-webgpu
engine on WebGPU).
License / credits
Weights and architecture: Zheng Peng et al., BiRefNet (MIT). Please check the upstream card for the training-data (DIS5K) terms before commercial use.
Model tree for anudit/BiRefNet_lite-2K-ONNX
Base model
ZhengPeng7/BiRefNet_lite-2K