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
Dynamic H×W export (multiples of 64); remove 1024 variant
Browse files- README.md +16 -15
- onnx/model_fp16.onnx +2 -2
- onnx/model_fp16_1024.onnx +0 -3
README.md
CHANGED
|
@@ -11,7 +11,7 @@ tags:
|
|
| 11 |
- birefnet
|
| 12 |
---
|
| 13 |
|
| 14 |
-
# BiRefNet_lite-2K — ONNX fp16 (
|
| 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
|
|
@@ -19,30 +19,31 @@ ONNX export of [ZhengPeng7/BiRefNet_lite-2K](https://huggingface.co/ZhengPeng7/B
|
|
| 19 |
|
| 20 |
| file | precision | input | output | size |
|
| 21 |
|---|---|---|---|---|
|
| 22 |
-
| `onnx/model_fp16.onnx` | fp16 weights, fp32 I/O | `input_image` `[1,3,
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
to 2560×1440, run, then resize the mask back.
|
| 29 |
|
| 30 |
## What is different from a plain `torch.onnx.export`
|
| 31 |
|
| 32 |
-
A naive export needs ~11 GB of activations at
|
| 33 |
-
This graph computes the same function with ~0.45 GB peak live activations (~1.1 GB allocated on GPU in
|
| 34 |
-
the WebGPU engine):
|
| 35 |
|
| 36 |
* Deformable convolutions use the standard ONNX **`DeformConv`** op (opset 19+) instead of an im2col gather chain.
|
| 37 |
* The 5-branch ASPP concat (1280 ch) followed by a 1×1 conv is rewritten as a sum of five 1×1 convs.
|
| 38 |
* The full-resolution decoder tail (bilinear upsample → concat → 1×1 conv, and the `ipt_blk1` branch) is
|
| 39 |
-
algebraically collapsed into a 1×1 conv at low resolution plus one 5×5 conv on the input image
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 42 |
* GELU is exported as the `Gelu` op (opset 20).
|
| 43 |
|
| 44 |
-
|
| 45 |
-
Requires a runtime that implements `DeformConv` and `Gelu` (verified with onnxruntime on CPU; the `birefnet-webgpu`
|
|
|
|
| 46 |
|
| 47 |
## License / credits
|
| 48 |
|
|
|
|
| 11 |
- birefnet
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# BiRefNet_lite-2K — ONNX fp16 (dynamic input size, 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
|
|
|
|
| 19 |
|
| 20 |
| file | precision | input | output | size |
|
| 21 |
|---|---|---|---|---|
|
| 22 |
+
| `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 |
|
| 23 |
|
| 24 |
+
**H and W are dynamic but must both be multiples of 64** (Swin patch merging, including the half-resolution
|
| 25 |
+
multi-scale path). Resize your image to such a size (the 2K model was trained at 2560×1440; `birefnet-webgpu`
|
| 26 |
+
buckets the long side to 512 / 1024 / 1536 / 2048 / 2560 and keeps the aspect ratio), run, then resize the mask back.
|
| 27 |
+
Verified against PyTorch at 512², 640×960, 1024², 1536×1024 and 1472×2560.
|
|
|
|
| 28 |
|
| 29 |
## What is different from a plain `torch.onnx.export`
|
| 30 |
|
| 31 |
+
A naive export needs ~11 GB of activations at 2560×1440, which is impossible in a browser tab.
|
| 32 |
+
This graph computes the same function with ~0.45 GB peak live activations at 2560×1472 (~1.1 GB allocated on GPU in
|
| 33 |
+
the WebGPU engine; far less at smaller sizes):
|
| 34 |
|
| 35 |
* Deformable convolutions use the standard ONNX **`DeformConv`** op (opset 19+) instead of an im2col gather chain.
|
| 36 |
* The 5-branch ASPP concat (1280 ch) followed by a 1×1 conv is rewritten as a sum of five 1×1 convs.
|
| 37 |
* The full-resolution decoder tail (bilinear upsample → concat → 1×1 conv, and the `ipt_blk1` branch) is
|
| 38 |
+
algebraically collapsed into a 1×1 conv at low resolution plus one 5×5 conv on the input image, with the
|
| 39 |
+
branch's bias response built exactly from a single-channel conv over a ones image. This is exact except for a
|
| 40 |
+
~1 px outer ring where zero-padding interacts with the folded convolutions (max logit difference ≈ 0.64 there,
|
| 41 |
+
≤ 7e-3 anywhere else).
|
| 42 |
* GELU is exported as the `Gelu` op (opset 20).
|
| 43 |
|
| 44 |
+
fp32 graph IoU vs the original PyTorch model: ≥ 0.999997 on the test sizes; fp16 graph IoU 0.9995 (2560×1440, ORT CPU).
|
| 45 |
+
Requires a runtime that implements `DeformConv` and `Gelu` (verified with onnxruntime on CPU; the `birefnet-webgpu`
|
| 46 |
+
engine on WebGPU).
|
| 47 |
|
| 48 |
## License / credits
|
| 49 |
|
onnx/model_fp16.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:30359ab09268c342c71308f836db45485c5f8ac4f4b55c268dce99cf174bc25b
|
| 3 |
+
size 91435003
|
onnx/model_fp16_1024.onnx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:ab11fddbecb0bbb8b07aa698d07f8fe15771b2714c992404a90588d7df2dc028
|
| 3 |
-
size 93445455
|
|
|
|
|
|
|
|
|
|
|
|