BiRefNet (fastforks)

BiRefNet (Zheng et al., CAAI AIR 2024): bilateral reference network for high-resolution dichotomous image segmentation and background removal. A Swin Transformer v1 encoder at full and half resolution feeds a decoder with deformable ASPP blocks, image patches as reference and gradient attention; one foreground mask per image. rmbg-2.0: BRIA's RMBG-2.0 weights for this network (non-commercial, gated).

This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: https://github.com/kleinicke/fastforks. Kernels for the kernels backend: https://huggingface.co/fastforks/kernels. Original code: https://github.com/ZhengPeng7/BiRefNet at f7079632d681.

Author weight repos: https://huggingface.co/ZhengPeng7/BiRefNet, https://huggingface.co/ZhengPeng7/BiRefNet_lite, https://huggingface.co/briaai/RMBG-2.0.

Task: matting. Tier: experimental. Outputs: alpha. Backends: portable, kernels.

Input: one RGB image (trimap-guided models also a trimap: background / unknown / foreground). Output: an alpha matte [H, W] in [0, 1] at the input size: 1 = foreground (background removal, dichotomous / salient object segmentation).

Variants

Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in card.toml.

variant weights (author link) SHA-256 weights licence commercial use
birefnet@1 birefnet.safetensors 9ab37426bf4d MIT yes
birefnet-lite@1 birefnet_lite.safetensors 4417d8979525 MIT yes
rmbg-2.0@1 rmbg-2.0.safetensors 566ed80c3d95 CC-BY-NC-4.0 no

Licence

Original-code strings, recorded as they are (research-use package; check them before any other use). Code: MIT. Licence files: LICENSE.

Training data: DIS5K (dichotomous image segmentation), DUTS (salient object detection), HRSOD (high-resolution salient object detection), UHRSD (ultra-high-resolution salient object detection), HRS10K (high-resolution salient object detection), P3M-10k (privacy-preserving portrait matting) (General-use checkpoints: DIS5K-TR, DIS-TEs, DUTS-TR/TE, HRSOD-TR/TE, UHRSD-TR/TE, HRS10K-TR/TE, TR-P3M-10k, TE-P3M-500-NP, TE-P3M-500-P, TR-humans (HF model card). Some of these sets carry research-only terms; only the weights licence (MIT) counts for the commercial flag.).

Licence evidence: https://huggingface.co/ZhengPeng7/BiRefNet/blob/e2bf8e4460fc8fa32bba5ea4d94b3233d367b0e4/README.md ; https://huggingface.co/ZhengPeng7/BiRefNet_lite/blob/aa62cd87eafb9cc43056d08ef3615a14628b831d/README.md ; https://github.com/ZhengPeng7/BiRefNet/blob/f7079632d681ecf12161fcea8905682934e59e51/LICENSE

Input size

any H x W >= 32, padded to a multiple of 32 Tested up to (portable, fp16, RTX 5060 Ti 16 GB): birefnet 3000x4000 (1.7 GiB peak allocated, 2.8 reserved); birefnet-lite 3000x4000 (0.9 GiB peak allocated, 1.8 reserved); rmbg-2.0 3000x4000 (1.7 GiB peak allocated, 2.6 reserved)

Speed and memory

Matting, synthetic, 1080x1920

model time (ms): original portable kernels kernels speed-up: vs original vs portable peak memory (MiB, allocated / reserved): original portable kernels
birefnet 234 131 121 1.9x 1.1x 1666 / 1930 1660 / 1908 1674 / 1916
birefnet-lite 75.1 58.0 48.1 1.6x 1.2x 913 / 974 810 / 952 754 / 960
rmbg-2.0 149 132 121 1.2x 1.1x 1672 / 1990 1660 / 1908 1674 / 1936

Startup and first call

model load (s): original portable kernels first call (s): original portable kernels
birefnet 3.60 0.46 13.58 0.39 0.56 0.37
birefnet-lite 8.04 0.67 0.20 1.10 0.42 0.47
rmbg-2.0 6.42 0.94 0.64 0.94 0.49 0.47

torch.compile and TensorRT

model input time: portable compile TensorRT fp16 kernels preparation: compile (cold first call) ONNX + engine build peak MiB (alloc / reserved): portable compile kernels TensorRT (engine + torch)
birefnet 1080x1920 131 ms 138 ms 87.8 ms 121 ms 93.8 s 201 s 1660 / 1908 1874 / 1932 1674 / 1916 1753 / 1814
birefnet-lite 1080x1920 58.0 ms 50.2 ms 49.0 ms 48.1 ms 75.1 s 156 s 810 / 952 1469 / 1552 754 / 960 874 / 934
rmbg-2.0 1080x1920 132 ms 110 ms 88.1 ms 121 ms 82.9 s 219 s 1660 / 1908 1874 / 1932 1674 / 1936 1723 / 1784

Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).

Hardware, protocol and caveats: benchmarks (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or (fp32) where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.

Accuracy

On public datasets

Each image at its own size against its binary mask: MAE of the alpha, max F-beta (beta^2 = 0.3) over 256 thresholds (BiRefNet's evaluation). Original = the original code named under Details, same checkpoint and protocol.

variant dataset original fp32 original fp16 portable kernels note
birefnet DIS5K validation (DIS-VD), all 470 images, MAE / max F-beta 0.0325 / 0.9074
birefnet DIS5K validation (DIS-VD), every 2nd image (235), MAE / max F-beta 0.0338 / 0.9037 0.0338 / 0.9037 0.0338 / 0.9037 0.0338 / 0.9037
birefnet-lite DIS5K validation (DIS-VD), every 2nd image (235), MAE / max F-beta 0.0446 / 0.8620 0.0446 / 0.8619 0.0446 / 0.8620 0.0446 / 0.8620
rmbg-2.0 DIS5K validation (DIS-VD), every 2nd image (235), MAE / max F-beta 0.0205 / 0.9324 0.0206 / 0.9324 0.0205 / 0.9326 0.0205 / 0.9326

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 45b1fe90 / a49aaba7, 2026-11-12 to 2026-11-14.

Parity with the original code

Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 7.8e-05 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 6e-06 and p99 <= 2.1e-05 (absolute error of the output alpha).

Usage

from fastforks import matting

model = matting.load("birefnet")  # mode="auto": the preferred backend from recorded measurements
result = model("photo.jpg")
result.alpha  # [H, W] float32 in [0, 1], input resolution
result.backend  # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')

Install with pip install fastforks (see https://github.com/kleinicke/fastforks). Other variants: birefnet, birefnet-lite, rmbg-2.0.

Kernels backend

matting.load("birefnet", mode="kernels") runs our CUDA kernels (deform_conv). It needs a prebuilt kernel for your GPU architecture (downloaded from https://huggingface.co/fastforks/kernels on first use) and a recent NVIDIA driver; if there is none it raises BackendUnavailableError with the reason and never falls back silently. mode="auto" picks kernels when it can run and logs the choice.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for fastforks/birefnet

Finetuned
(9)
this model

Collection including fastforks/birefnet