Instructions to use baker76/imageback-models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- BiRefNet
How to use baker76/imageback-models with BiRefNet:
# Option 1: use with transformers from transformers import AutoModelForImageSegmentation birefnet = AutoModelForImageSegmentation.from_pretrained("baker76/imageback-models", 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("baker76/imageback-models") - Notebooks
- Google Colab
- Kaggle
Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: onnx
|
| 3 |
+
license: mit
|
| 4 |
+
pipeline_tag: image-segmentation
|
| 5 |
+
tags:
|
| 6 |
+
- onnx
|
| 7 |
+
- birefnet
|
| 8 |
+
- background-removal
|
| 9 |
+
- image-segmentation
|
| 10 |
+
base_model:
|
| 11 |
+
- ZhengPeng7/BiRefNet
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# imageback models
|
| 15 |
+
|
| 16 |
+
ONNX builds of [BiRefNet](https://github.com/ZhengPeng7/BiRefNet) used by imageback, a C++
|
| 17 |
+
command-line tool that replaces the background of a photo with an image, a colour or transparency.
|
| 18 |
+
They run on ONNX Runtime (CPU, CUDA or WebGPU) with no Python involved.
|
| 19 |
+
|
| 20 |
+
Nothing here was trained or fine-tuned by us. Each folder is derived from the ONNX export at
|
| 21 |
+
[onnx-community/BiRefNet-ONNX](https://huggingface.co/onnx-community/BiRefNet-ONNX) and stays under
|
| 22 |
+
the original MIT licence.
|
| 23 |
+
|
| 24 |
+
| Folder | Size | Weights |
|
| 25 |
+
| --- | --- | --- |
|
| 26 |
+
| `birefnet-fp16/` | 467 MB | Half precision. Best choice on a GPU (recommended download) |
|
| 27 |
+
| `birefnet-int8/` | 295 MB | 8-bit. Closest to full precision of the small ones |
|
| 28 |
+
| `birefnet-int4/` | 199 MB | 4-bit backbone, 8-bit elsewhere. Smallest |
|
| 29 |
+
| `birefnet-fp32/` | 928 MB | Full precision; the source for quantizing |
|
| 30 |
+
|
| 31 |
+
Each folder holds `model.onnx` and `config.json` (input size and normalisation).
|
| 32 |
+
|
| 33 |
+
```sh
|
| 34 |
+
hf download baker76/imageback-models --include "birefnet-fp16/*" --local-dir models
|
| 35 |
+
imageback replace photo.jpg -o cutout.png --model models/birefnet-fp16
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## Using the models elsewhere
|
| 39 |
+
|
| 40 |
+
Input `input_image`: float32 `[1, 3, 1024, 1024]`, RGB scaled to 0-1 and normalised with the ImageNet
|
| 41 |
+
mean and standard deviation; the picture is stretched to 1024 x 1024. Output `output_image`: float32
|
| 42 |
+
`[1, 1, 1024, 1024]` logits; apply a sigmoid and resize to the picture's size to get the alpha matte.
|
| 43 |
+
|
| 44 |
+
## Changes from the upstream export
|
| 45 |
+
|
| 46 |
+
- All folders: `Split` nodes with 16 or 32 outputs are replaced by two levels of smaller ones.
|
| 47 |
+
WebGPU allows a shader 16 buffers, which the original nodes exceed. Results are unchanged.
|
| 48 |
+
- `birefnet-int8`, `birefnet-int4`: made from the fp32 graph. The Swin backbone's `MatMul` weights
|
| 49 |
+
(84% of the model) are stored as 8- or 4-bit blocks of 32 (ONNX Runtime `MatMulNBits`). Convolution
|
| 50 |
+
kernels and relative position biases are stored as 8-bit integers behind `DequantizeLinear`.
|
| 51 |
+
Activations stay float32, so these are smaller than fp16 but not faster.
|
| 52 |
+
|
| 53 |
+
## Accuracy
|
| 54 |
+
|
| 55 |
+
Difference between each model's alpha matte and the fp32 model's, on five test photos (people, a dog,
|
| 56 |
+
a cat, a bicycle), with the CUDA provider:
|
| 57 |
+
|
| 58 |
+
| Model | Mean absolute difference | Pixels differing by more than 0.1 |
|
| 59 |
+
| --- | --- | --- |
|
| 60 |
+
| fp16 | 0.00017 | 0.001% |
|
| 61 |
+
| int8 | 0.00011 | 0.000% |
|
| 62 |
+
| int4 | 0.00081 | 0.076% |
|
| 63 |
+
|
| 64 |
+
The scripts that produced these files are in the imageback repository under `tools/export/`.
|