Add BiRefNet Dynamic ONNX Runtime CUDA model
Browse files- README.md +74 -0
- manifest.json +54 -0
- onnx/model.onnx +3 -0
README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: onnxruntime
|
| 3 |
+
pipeline_tag: image-segmentation
|
| 4 |
+
license: mit
|
| 5 |
+
base_model: ZhengPeng7/BiRefNet_dynamic
|
| 6 |
+
tags:
|
| 7 |
+
- onnx
|
| 8 |
+
- onnxruntime
|
| 9 |
+
- cuda
|
| 10 |
+
- triton
|
| 11 |
+
- birefnet
|
| 12 |
+
- background-removal
|
| 13 |
+
- mask-generation
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# BiRefNet Dynamic ONNX Runtime CUDA
|
| 17 |
+
|
| 18 |
+
This repository contains a CUDA-oriented FP16 ONNX conversion of [`ZhengPeng7/BiRefNet_dynamic`](https://huggingface.co/ZhengPeng7/BiRefNet_dynamic), pinned to revision `280306042f57b7a33854319da62fd86aaa89ec4c`.
|
| 19 |
+
|
| 20 |
+
It is packaged for ONNX Runtime CUDA and NVIDIA Triton. It is not the Transformers.js/WebGPU conversion; use [`onnx-community/BiRefNet_dynamic-ONNX`](https://huggingface.co/onnx-community/BiRefNet_dynamic-ONNX) for that runtime family.
|
| 21 |
+
|
| 22 |
+
## Model contract
|
| 23 |
+
|
| 24 |
+
| | Name | Type | Shape |
|
| 25 |
+
|---|---|---|---|
|
| 26 |
+
| Input | `IMAGE` | FP16 | `[batch, 3, 1024, 1024]` |
|
| 27 |
+
| Output | `ALPHA` | FP16 | `[batch, 1, 1024, 1024]` at the fixed input size |
|
| 28 |
+
|
| 29 |
+
The upstream model variant is named *Dynamic*, but this exported graph has a fixed 1024 × 1024 spatial input and a dynamic batch axis. `ALPHA` is the foreground probability: sigmoid is already part of the graph, so do not apply it again.
|
| 30 |
+
|
| 31 |
+
## Preprocessing and postprocessing
|
| 32 |
+
|
| 33 |
+
1. Apply image orientation and convert to sRGB/RGB.
|
| 34 |
+
2. Resize to 1024 × 1024.
|
| 35 |
+
3. Scale RGB values to `[0, 1]`, normalize with ImageNet mean `(0.485, 0.456, 0.406)` and standard deviation `(0.229, 0.224, 0.225)`, then convert to NCHW FP16.
|
| 36 |
+
4. Run the model and resize `ALPHA` back to the original image dimensions.
|
| 37 |
+
5. If the source image already has alpha, multiply it by the predicted alpha.
|
| 38 |
+
|
| 39 |
+
## ONNX Runtime CUDA
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import onnxruntime as ort
|
| 43 |
+
|
| 44 |
+
session = ort.InferenceSession(
|
| 45 |
+
"onnx/model.onnx",
|
| 46 |
+
providers=["CUDAExecutionProvider"],
|
| 47 |
+
)
|
| 48 |
+
alpha = session.run(["ALPHA"], {"IMAGE": normalized_nchw_fp16})[0]
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
The graph uses 20 standard ONNX `DeformConv` nodes and requires a runtime build that implements them. It has been validated with ONNX Runtime CUDA and NVIDIA Triton 26.08; CPU and browser runtimes are not validation targets for this artifact.
|
| 52 |
+
|
| 53 |
+
## Integrity and validation
|
| 54 |
+
|
| 55 |
+
- File: `onnx/model.onnx`
|
| 56 |
+
- Size: `466586004` bytes
|
| 57 |
+
- SHA-256: `1fefe02158d58b32d589cc4bdd7c2be938cd49171316e4a6ed5da485ccf39b19`
|
| 58 |
+
- ONNX IR: 9; opset: 19; no external tensor data
|
| 59 |
+
- `onnx.checker`: passed
|
| 60 |
+
- ONNX Runtime CUDA FP16 vs. source PyTorch FP16: mean absolute error `1.4735e-5`, maximum absolute error `0.004486`
|
| 61 |
+
- End-to-end NVIDIA Triton 26.08 validation: passed
|
| 62 |
+
|
| 63 |
+
Machine-readable conversion and validation details are recorded in [`manifest.json`](./manifest.json).
|
| 64 |
+
|
| 65 |
+
## Citation
|
| 66 |
+
|
| 67 |
+
```bibtex
|
| 68 |
+
@article{zheng2024birefnet,
|
| 69 |
+
title={Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
|
| 70 |
+
author={Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
|
| 71 |
+
journal={CAAI Artificial Intelligence Research},
|
| 72 |
+
year={2024}
|
| 73 |
+
}
|
| 74 |
+
```
|
manifest.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"source": {
|
| 4 |
+
"repo_id": "ZhengPeng7/BiRefNet_dynamic",
|
| 5 |
+
"revision": "280306042f57b7a33854319da62fd86aaa89ec4c",
|
| 6 |
+
"license": "MIT"
|
| 7 |
+
},
|
| 8 |
+
"artifact": {
|
| 9 |
+
"path": "onnx/model.onnx",
|
| 10 |
+
"bytes": 466586004,
|
| 11 |
+
"sha256": "1fefe02158d58b32d589cc4bdd7c2be938cd49171316e4a6ed5da485ccf39b19",
|
| 12 |
+
"external_data": false
|
| 13 |
+
},
|
| 14 |
+
"onnx": {
|
| 15 |
+
"ir_version": 9,
|
| 16 |
+
"producer_name": "pytorch",
|
| 17 |
+
"producer_version": "2.6.0",
|
| 18 |
+
"opset": 19,
|
| 19 |
+
"input": {
|
| 20 |
+
"name": "IMAGE",
|
| 21 |
+
"dtype": "float16",
|
| 22 |
+
"shape": [
|
| 23 |
+
"batch_size",
|
| 24 |
+
3,
|
| 25 |
+
1024,
|
| 26 |
+
1024
|
| 27 |
+
]
|
| 28 |
+
},
|
| 29 |
+
"output": {
|
| 30 |
+
"name": "ALPHA",
|
| 31 |
+
"dtype": "float16",
|
| 32 |
+
"shape": [
|
| 33 |
+
"batch_size",
|
| 34 |
+
1,
|
| 35 |
+
"SigmoidALPHA_dim_2",
|
| 36 |
+
"SigmoidALPHA_dim_3"
|
| 37 |
+
]
|
| 38 |
+
},
|
| 39 |
+
"dynamic_axes": [
|
| 40 |
+
"batch"
|
| 41 |
+
],
|
| 42 |
+
"output_semantics": "foreground_alpha_probability_sigmoid_in_graph",
|
| 43 |
+
"deform_conv_nodes": 20,
|
| 44 |
+
"gather_nd_nodes": 0
|
| 45 |
+
},
|
| 46 |
+
"validation": {
|
| 47 |
+
"onnx_checker": true,
|
| 48 |
+
"onnxruntime_cuda_vs_pytorch_fp16": {
|
| 49 |
+
"mean_absolute_error": 1.4735e-05,
|
| 50 |
+
"max_absolute_error": 0.004486
|
| 51 |
+
},
|
| 52 |
+
"triton": "26.08"
|
| 53 |
+
}
|
| 54 |
+
}
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1fefe02158d58b32d589cc4bdd7c2be938cd49171316e4a6ed5da485ccf39b19
|
| 3 |
+
size 466586004
|