Instructions to use CoderViking/birefnet-lite-onnx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- BiRefNet
How to use CoderViking/birefnet-lite-onnx with BiRefNet:
# Option 1: use with transformers from transformers import AutoModelForImageSegmentation birefnet = AutoModelForImageSegmentation.from_pretrained("CoderViking/birefnet-lite-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("CoderViking/birefnet-lite-onnx") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: onnx
|
| 4 |
+
tags:
|
| 5 |
+
- onnx
|
| 6 |
+
- image-segmentation
|
| 7 |
+
- background-removal
|
| 8 |
+
- birefnet
|
| 9 |
+
pipeline_tag: image-segmentation
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# BiRefNet_lite — browser-tuned ONNX export (static 1024², opset 17)
|
| 13 |
+
|
| 14 |
+
Custom ONNX export of **BiRefNet_lite** (bilateral reference network for
|
| 15 |
+
dichotomous image segmentation, Swin-v1-tiny backbone) from the official
|
| 16 |
+
[ZhengPeng7/BiRefNet_lite](https://huggingface.co/ZhengPeng7/BiRefNet_lite)
|
| 17 |
+
weights, re-hosted for [AllPrivate](https://allprivate.app) — where every model
|
| 18 |
+
runs in the visitor's browser and nothing is uploaded.
|
| 19 |
+
|
| 20 |
+
## Why a custom export
|
| 21 |
+
|
| 22 |
+
The community export ([onnx-community/BiRefNet_lite-ONNX](https://huggingface.co/onnx-community/BiRefNet_lite-ONNX))
|
| 23 |
+
throws `OrtRun std::bad_alloc` in ONNX Runtime Web on every EP (fp32/fp16 ×
|
| 24 |
+
wasm/webgpu, tested 2026-07 on an M-series MacBook): it is a dynamic-shape
|
| 25 |
+
trace whose deformable convolutions decompose into GatherND/ScatterND/Clip
|
| 26 |
+
chains that fall back to CPU on the WebGPU EP and materialize im2col tensors of
|
| 27 |
+
hundreds of MB inside the 32-bit wasm heap.
|
| 28 |
+
|
| 29 |
+
This export replaces `DeformableConv2d.forward` with a numerically identical
|
| 30 |
+
per-kernel-tap **GridSample** decomposition (one bilinear GridSample + 1×1 Conv
|
| 31 |
+
per tap, accumulated — peak extra memory is one `[1,C,H,W]` tensor per tap) and
|
| 32 |
+
traces with a **static** input shape, so all shape dynamism constant-folds
|
| 33 |
+
away. It runs to completion on both the wasm and WebGPU execution providers of
|
| 34 |
+
ONNX Runtime Web (verified 1.26-dev).
|
| 35 |
+
|
| 36 |
+
## Provenance
|
| 37 |
+
|
| 38 |
+
- Source weights: [`model.safetensors`](https://huggingface.co/ZhengPeng7/BiRefNet_lite/blob/main/model.safetensors)
|
| 39 |
+
at pinned revision [`7838f1c`](https://huggingface.co/ZhengPeng7/BiRefNet_lite/tree/7838f1c3472f827cd8ce13ab5ccc2ce48077360f)
|
| 40 |
+
- sha256: `4417d89795250e698c3cb0ae8df15743810065f646f48a694fdfa7ca052d0815`
|
| 41 |
+
- Exported with `torch.onnx.export` (PyTorch 2.8.0, TorchScript exporter),
|
| 42 |
+
opset 17, fp32, constant folding on, post-processed with onnxslim 0.1.94
|
| 43 |
+
(constant-folds the Swin attention-mask construction; Gemm fusion disabled)
|
| 44 |
+
plus a content-hash initializer dedupe (the backbone is traced twice for the
|
| 45 |
+
multi-scale 'cat' input) — see [`export_birefnet_lite.py`](./export_birefnet_lite.py)
|
| 46 |
+
for the exact reproducible script
|
| 47 |
+
- I/O: `input_image` `[1, 3, 1024, 1024]` (NCHW, RGB, float32, ImageNet
|
| 48 |
+
normalization: `(x/255 - mean) / std`, mean `[0.485, 0.456, 0.406]`, std
|
| 49 |
+
`[0.229, 0.224, 0.225]`) → `output_image` `[1, 1, 1024, 1024]` **logits**;
|
| 50 |
+
apply sigmoid for the [0,1] matte
|
| 51 |
+
- Graph ops: `Add, BatchNormalization, Concat, Conv, Div, Erf, Gather,
|
| 52 |
+
GlobalAveragePool, GridSample, LayerNormalization, MatMul, Mul, Pad, Relu,
|
| 53 |
+
Reshape, Resize, Shape, Sigmoid, Slice, Softmax, Transpose, Unsqueeze` —
|
| 54 |
+
no GatherND, no ScatterND, no Clip
|
| 55 |
+
- Validated against the unpatched PyTorch reference (torchvision
|
| 56 |
+
`deform_conv2d`): GridSample decomposition max abs dev `3.1e-5` vs
|
| 57 |
+
torchvision; full-model ONNX (onnxruntime CPU) max abs logits dev `1.0e-4`,
|
| 58 |
+
max post-sigmoid dev `1.3e-9`
|
| 59 |
+
- File sha256: `50a57872cc739192446da2a934159f957c81af8b5a161dfda8e3daa51660ca67`
|
| 60 |
+
|
| 61 |
+
## License
|
| 62 |
+
|
| 63 |
+
MIT, inherited from [BiRefNet](https://github.com/ZhengPeng7/BiRefNet/blob/main/LICENSE)
|
| 64 |
+
(© Zheng Peng et al.). This repo only re-packages the officially released
|
| 65 |
+
weights in ONNX form.
|
| 66 |
+
|
| 67 |
+
## Citation
|
| 68 |
+
|
| 69 |
+
```bibtex
|
| 70 |
+
@article{BiRefNet,
|
| 71 |
+
title = {Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
|
| 72 |
+
author = {Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
|
| 73 |
+
journal = {CAAI Artificial Intelligence Research},
|
| 74 |
+
year = {2024}
|
| 75 |
+
}
|
| 76 |
+
```
|