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
Add BiRefNet_lite-2K fp16 ONNX (static 2560x1440, low-memory graph)
Browse files- README.md +47 -0
- onnx/model_fp16.onnx +3 -0
README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: onnx
|
| 4 |
+
pipeline_tag: image-segmentation
|
| 5 |
+
base_model: ZhengPeng7/BiRefNet_lite-2K
|
| 6 |
+
tags:
|
| 7 |
+
- background-removal
|
| 8 |
+
- dichotomous-image-segmentation
|
| 9 |
+
- onnx
|
| 10 |
+
- webgpu
|
| 11 |
+
- birefnet
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# BiRefNet_lite-2K — ONNX fp16 (static 2560×1440, low-memory graph)
|
| 15 |
+
|
| 16 |
+
ONNX export of [ZhengPeng7/BiRefNet_lite-2K](https://huggingface.co/ZhengPeng7/BiRefNet_lite-2K)
|
| 17 |
+
(Swin-T backbone, 44M params, trained for 2560×1440), made for in-browser inference with
|
| 18 |
+
[`birefnet-webgpu`](https://github.com/anudit/birefnet-webgpu).
|
| 19 |
+
|
| 20 |
+
| file | precision | input | output | size |
|
| 21 |
+
|---|---|---|---|---|
|
| 22 |
+
| `onnx/model_fp16.onnx` | fp16 weights, fp32 I/O | `input_image` `[1,3,1440,2560]` (ImageNet-normalised RGB) | `output_image` `[1,1,1440,2560]` logits (apply sigmoid) | ~99 MB |
|
| 23 |
+
|
| 24 |
+
The input size is **fixed**: resize (stretch, no aspect preservation — this matches training) your image
|
| 25 |
+
to 2560×1440, run, then resize the mask back.
|
| 26 |
+
|
| 27 |
+
## What is different from a plain `torch.onnx.export`
|
| 28 |
+
|
| 29 |
+
A naive export needs ~11 GB of activations at this resolution, which is impossible in a browser tab.
|
| 30 |
+
This graph computes the same function with ~0.45 GB peak live activations (~1.1 GB allocated on GPU in
|
| 31 |
+
the WebGPU engine):
|
| 32 |
+
|
| 33 |
+
* Deformable convolutions use the standard ONNX **`DeformConv`** op (opset 19+) instead of an im2col gather chain.
|
| 34 |
+
* The 5-branch ASPP concat (1280 ch) followed by a 1×1 conv is rewritten as a sum of five 1×1 convs.
|
| 35 |
+
* The full-resolution decoder tail (bilinear upsample → concat → 1×1 conv, and the `ipt_blk1` branch) is
|
| 36 |
+
algebraically collapsed into a 1×1 conv at low resolution plus one 5×5 conv on the input image.
|
| 37 |
+
This is exact except for a ~1 px outer ring where zero-padding interacts with the folded convolutions
|
| 38 |
+
(≤ 3e-5 sigmoid difference on a test image).
|
| 39 |
+
* GELU is exported as the `Gelu` op (opset 20).
|
| 40 |
+
|
| 41 |
+
Validated against the original PyTorch model on a 2560×1440 image: fp32 graph IoU 0.999996, fp16 graph IoU 0.9995 (ORT CPU).
|
| 42 |
+
Requires a runtime that implements `DeformConv` and `Gelu` (verified with onnxruntime on CPU; the `birefnet-webgpu` engine on WebGPU).
|
| 43 |
+
|
| 44 |
+
## License / credits
|
| 45 |
+
|
| 46 |
+
Weights and architecture: Zheng Peng et al., [BiRefNet](https://github.com/ZhengPeng7/BiRefNet) (MIT).
|
| 47 |
+
Please check the upstream card for the training-data (DIS5K) terms before commercial use.
|
onnx/model_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5d03dc5de5f3295dfcf4b84829fbbcd52bc3adfac890965c7316b99d40739a02
|
| 3 |
+
size 98728016
|