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
imageback models
ONNX builds of BiRefNet used by imageback, a C++ command-line tool that replaces the background of a photo with an image, a colour or transparency. They run on ONNX Runtime (CPU, CUDA or WebGPU) with no Python involved.
Nothing here was trained or fine-tuned by us. Each folder is derived from the ONNX export at onnx-community/BiRefNet-ONNX and stays under the original MIT licence.
| Folder | Size | Weights |
|---|---|---|
birefnet-fp16/ |
490 MB | Half precision. Best choice on a GPU (recommended download) |
birefnet-int8/ |
309 MB | 8-bit. Closest to full precision of the small ones |
birefnet-int4/ |
209 MB | 4-bit backbone, 8-bit elsewhere. Smallest |
birefnet-fp32/ |
973 MB | Full precision; the source for quantizing |
Each folder holds model.onnx and config.json (input size and normalisation).
hf download baker76/imageback-models --include "birefnet-fp16/*" --local-dir models
imageback replace photo.jpg -o cutout.png --model models/birefnet-fp16
Using the models elsewhere
Input input_image: float32 [1, 3, 1024, 1024], RGB scaled to 0-1 and normalised with the ImageNet
mean and standard deviation; the picture is stretched to 1024 x 1024. Output output_image: float32
[1, 1, 1024, 1024] logits; apply a sigmoid and resize to the picture's size to get the alpha matte.
Changes from the upstream export
- All folders:
Splitnodes with 16 or 32 outputs are replaced by two levels of smaller ones. WebGPU allows a shader 16 buffers, which the original nodes exceed. Results are unchanged. birefnet-int8,birefnet-int4: made from the fp32 graph. The Swin backbone'sMatMulweights (84% of the model) are stored as 8- or 4-bit blocks of 32 (ONNX RuntimeMatMulNBits). Convolution kernels and relative position biases are stored as 8-bit integers behindDequantizeLinear. Activations stay float32, so these are smaller than fp16 but not faster.
Accuracy
Difference between each model's alpha matte and the fp32 model's, on five test photos (people, a dog, a cat, a bicycle), with the CUDA provider:
| Model | Mean absolute difference | Pixels differing by more than 0.1 |
|---|---|---|
| fp16 | 0.00017 | 0.001% |
| int8 | 0.00011 | 0.000% |
| int4 | 0.00081 | 0.076% |
The scripts that produced these files are in the imageback repository under tools/export/.
Model tree for baker76/imageback-models
Base model
ZhengPeng7/BiRefNet