BiRefNet

A bilateral-reference network that predicts a soft alpha matte separating a subject from its background. LibreYOLO ships inference and validation for BiRefNet's matte task.

Tasks
matte
Sizes
t, l at 1024 px
Install
pip install libreyolo
Support tier
Inference only, since v. Predict, validate and export only. Training features do not apply.
Upstream
BiRefNet by Nankai University, MIT. Paper, source
Licenses
Code MIT, weights MIT. Commercial use

Install

BiRefNet needs no optional extra. Everything it imports is in the base install.

bash
pip install libreyolo

Predict

Weights download from Hugging Face on first use and are cached locally.

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreBiRefNetl-matte.pt")result = model(SAMPLE_IMAGE, save=True) matte = result.matteprint(matte.array.shape, matte.array.dtype)
CLI
libreyolo predict model=LibreBiRefNetl-matte.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
Cutout
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreBiRefNetl-matte.pt")result = model(SAMPLE_IMAGE) # RGBA (H, W, 4) uint8: source RGB plus the matte as an alpha channel.rgba = result.cutout()result.save("subject.png")

A matte result carries no boxes; result.matte is a dense (H, W) float32 array in [0, 1], 1 fully foreground and 0 fully background. Unlike a binary mask, the soft matte keeps anti-aliased edge detail such as hair and fur. result.cutout() composites the source image with that alpha channel into an RGBA array, and result.save(path) (or save=True on the predict call) writes it straight to a transparent-background PNG. The model runs at a fixed native 1024x1024 canvas; a different resolution is not supported, because the Swin backbone's relative-position tables are tied to it, and a mismatch interpolates them badly rather than raising an error. See prediction for sources, streaming and result handling.

Variants

One published checkpoint, l, the Swin-L tier BiRefNet-general model and the quality default upstream. The family's code also supports a Swin-T lite tier, t, but no LibreYOLO conversion of it is published yet.

Validate

val() reports two metrics over a paired image/matte folder, both in [0, 1] and independent of resolution: MAE, the mean absolute error against the ground-truth alpha (lower is better), and S-measure (Fan et al., ICCV 2017), a structural similarity that credits preserving the subject's shape and holes, which pixel MAE alone misses (higher is better). Validation drives the model's own predict, so it uses the family's exact preprocessing.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreBiRefNetl-matte.pt") # A directory containing images/ and an auto-detected matte directory# (mattes/, matte/, gt/, masks/, mask/ or alpha/) also works in place# of a dataset YAML.metrics = model.val(data="my-matte-dataset/") print(metrics["metrics/MAE"])print(metrics["metrics/Smeasure"])

Validation is inference-only; fine-tuning is a documented follow-up rather than a shipped feature (see Predict for the exact resolution constraint that any future trainer would inherit).

Export

TaskONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
mattematte to ONNX: supported. matte to TorchScript: supported. matte to ExecuTorch: not supportedmatte to TensorRT: not supportedmatte to OpenVINO: not supportedmatte to Paddle: not supportedmatte to MNN: not supportedmatte to RKNN: not supportedmatte to ncnn: not supportedmatte to TFLite: not supportedmatte to CoreML: not supportedmatte to Core AI: not supported

An exported artifact loads back through LibreYOLO() on its file suffix, so a .onnx file behaves like a checkpoint and returns the same Results. TorchScript is the validated path; ONNX conversion runs but has not cleared the same parity bar. Export lists the arguments every format accepts and the extras a few of them add.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreBiRefNetl-matte.pt")model.export(format="onnx")
CLI
libreyolo export model=LibreBiRefNetl-matte.pt format=onnx
Use the exported file
from libreyolo import LibreYOLO, SAMPLE_IMAGE # The factory routes on the file suffix, so an exported artifact loads# like any checkpoint and returns the same Results object.model = LibreYOLO("LibreBiRefNetl-matte.onnx")result = model(SAMPLE_IMAGE) print(result.matte.array.shape)

Checkpoints

Every published weight file for this family.

FileInput (px)Weights license
matte
LibreBiRefNetl-matte.ptmit

Every file above exists in the LibreYOLO org today and downloads on first use.

Licensing

Check the license on the Hugging Face repository of the specific weights you download. Every checkpoint in the LibreYOLO org carries one, and they are not always the same across a family. That repository is the authoritative source; the summary below describes what applied when this page was last verified.

This is a description of the licenses involved, not legal advice. If the answer matters commercially, read the licenses yourself and take your own counsel.

Original work
BiRefNet, Nankai University
Upstream license
MIT
LibreYOLO code
MIT
Weights
MIT, republished at huggingface.co/LibreYOLO
Interpretation
MIT is a permissive license, so these weights can be used in commercial and closed-source products. The one standing obligation is to keep the license text and copyright notice with any copy you redistribute. It places no condition on your own application code. LibreYOLO's checkpoint is a format conversion of the official pretrained BiRefNet-general weights (the Swin-L, quality-default tier), with the learned parameters unchanged; fine-tuning is not wired into this library in v1, so there is no LibreYOLO-trained variant to license separately.

Citation

@article{zheng2024birefnet,
  title={Bilateral Reference for High-Resolution Dichotomous Image Segmentation},
  author={Zheng, Peng and Gao, Dehong and Fan, Deng-Ping and Liu, Li and Laaksonen, Jorma and Ouyang, Wanli and Sebe, Nicu},
  journal={CAAI Artificial Intelligence Research},
  volume = {3},
  pages = {9150038},
  year={2024}
}

Copied from the authors' citation block at github.com/ZhengPeng7/BiRefNet#citation.

Verified against LibreYOLO v1.5.0. Support tables, checkpoints and benchmark numbers on this page are generated from the released library and the published weights, not written by hand.