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
File size: 2,719 Bytes
146ae88 fddd2c2 146ae88 fddd2c2 146ae88 fddd2c2 146ae88 fddd2c2 146ae88 fddd2c2 146ae88 fddd2c2 146ae88 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | ---
license: mit
library_name: onnx
pipeline_tag: image-segmentation
base_model: ZhengPeng7/BiRefNet_lite-2K
tags:
- background-removal
- dichotomous-image-segmentation
- onnx
- webgpu
- birefnet
---
# BiRefNet_lite-2K — ONNX fp16 (dynamic input size, low-memory graph)
ONNX export of [ZhengPeng7/BiRefNet_lite-2K](https://huggingface.co/ZhengPeng7/BiRefNet_lite-2K)
(Swin-T backbone, 44M params, trained for 2560×1440), made for in-browser inference with
[`birefnet-webgpu`](https://github.com/anudit/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 **`DeformConv`** op (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_blk1` branch) 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 `Gelu` op (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](https://github.com/ZhengPeng7/BiRefNet) (MIT).
Please check the upstream card for the training-data (DIS5K) terms before commercial use.
|