BEN2
BEN2 (Prama LLC, 2025): cuts the foreground out of a photo as a soft mask (background removal); a Swin Transformer looks at the whole image and at four full-resolution patches and merges the views. MIT code and weights.
experimental Fork of PramaLLC/BEN2@2c99a5d · backends: portable, kernels
- Paper BEN: Using Confidence-Guided Matting for Dichotomous Image Segmentation arXiv · first released 8 Jan 2025
Checkpoint ben2
Paper 2025 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import matting
model = matting.load("ben2") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.alpha
result.backend # what ran: mode, device, dtype, kernels fastforks bench ben2 Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
Input: synthetic, 1080x1920 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original fp16the authors' mixed-precision option (float16); PramaLLC/BEN2@2c99a5da477b BEN2.py, bicubic resize / normalisation / bilinear back / min-max | fp16 | 201 | – | 2,466 MiB/2,772 MiB | 0.8 | 0.32 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 110 | 1.8× | 1,681 MiB/1,956 MiB | 0.7 | 0.48 |
| Kernels | fp16 | 104 | 1.9× | 1,430 MiB/1,698 MiB | 0.8 | 0.35 |
| Portable + torch.compile | 103 | 1.9× | 813 MiB/916 MiB | 71 (build) | – | |
| TensorRT fp16 | fp16 | 58.2 | 3.4× | 998 MiBenginenot comparable | 140 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-12 to 2026-11-15. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-12 | Original | fp32 | 10380 | 6,959 MiB process | – | 1080x1920 |
| Portable | fp32 | 1148 | 6,252 MiB process | matches | 1080x1920 | |
| Kernels | fp16 | not implemented | – | 1080x1920 | ||
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- MIT LICENSE
- Weights
- MIT source
- Training data
-
- DIS5K (dichotomous image segmentation) noncommercial, non-commercial
- Prama LLC proprietary segmentation data not stated
Our reading of the licences, not legal advice.
Weights
ben2.safetensors 381 MB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download ben2).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
DIS5K validation (DIS-VD)
all 470 images, MAE / max F-beta
| Run | dtype | mae ↑ | max_fbeta ↑ | images | ms / image |
|---|---|---|---|---|---|
| Original fp32 | not measured | ||||
| Original fp16 | not measured | ||||
| Portable fp32 | not measured | ||||
| Portable | not measured | ||||
| Kernels | fp16 | 0.0403 | 0.9000 | 470 | 176 |
The original code was not run on this dataset, so the table cannot show the distance to it.
Measured on RTX 5060 Ti, torch 2.14.1+cu130, fastforks a49aaba7, 2026-11-12.
DIS5K validation (DIS-VD)
every 2nd image (235), MAE / max F-beta
| Run | dtype | mae ↑ | max_fbeta ↑ | Δ mae vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 0.0421 | 0.8919 | reference | 235 | 320 |
| Original fp16 | fp16 | 0.0421 | 0.8919 | ±0.0000 | 235 | 202 |
| Portable fp32 | fp32 | 0.0421 | 0.8919 | ±0.0000 | 235 | 328 |
| Portable | fp16 | 0.0421 | 0.8919 | ±0.0000 | 235 | 183 |
| Kernels | fp16 | 0.0421 | 0.8919 | ±0.0000 | 235 | 177 |
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 authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-12; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks a49aaba7, 2026-11-12.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 3.5e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 2.4e-05 and p99 <= 0.00026 (absolute error of the output alpha).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.0000035 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.000024 | 0.00002 |
| GPU default dtypes, p99 |diff| | ≤ 0.00026 | 0.00017 |
Recorded for ben2 on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-12, with these kernels: cudnn_hacccutlass_convigev
Details
BEN2 (Prama LLC, 2025): background erase network for dichotomous image segmentation and background removal. A Swin Transformer v1 Base encoder sees the image at half resolution and as four full-resolution quarter patches; multi-view cross-attention (MVANet-style) merges them, a convolutional head upsamples to one foreground mask per image.
- Input / output
- 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). - Input size
- any H x W >= 32, padded to a multiple of 32; tested up to 3000x4000 (1,797 MiB allocated)
- Outputs
alpha- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)igevIGEV stereo: convolution epilogues, correlation lookups, GRU gatescutlass_convCUTLASS convolutions with the recurrent update (GRU) fused in
- Apple (MPS)
- fp32
Full reference, generated from the repository
BEN2 (Prama LLC, 2025): cuts the foreground out of a photo as a soft mask (background removal); a Swin Transformer looks at the whole image and at four full-resolution patches and merges the views. MIT code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
ben2 | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 201 110 104 103 58.2 | 2466 / 2772 1681 / 1956 1430 / 1698 813 / 916 1280 / 1326 |
Details
- Original code: https://github.com/PramaLLC/BEN2 at
2c99a5da477b - Code licence: MIT (permissive); files:
LICENSE - Weights licence: MIT
- Licence evidence: https://huggingface.co/PramaLLC/BEN2/blob/e48a20765fb421d19dcdb0bf3cc61e802ca5ec8f/README.md ; https://github.com/PramaLLC/BEN2/blob/2c99a5da477b5523585bfa5c893888a6e818a8f6/LICENSE
- Training data: DIS5K (dichotomous image segmentation), Prama LLC proprietary segmentation data (BEN2 card: "BEN2 was trained on the DIS5k and our 22K proprietary segmentation dataset"; it implies DIS-VD stayed out of training ("RMBG 2.0 did not preserve the DIS 5k validation dataset"). Only the weights licence (MIT) counts for the commercial flag.)
- Kernel libraries:
cudnn_hacc,igev,cutlass_conv - Variants:
ben2 - Outputs: alpha
- Input size: any H x W >= 32, padded to a multiple of 32
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
ben23000x4000 (1.8 GiB peak allocated, 2.7 reserved) ben21080x1920, first call: portable + torch.compile 71 s (cold Inductor cache), TensorRT fp16 140 s (ONNX + engine).ben2original 1080x1920: the authors' mixed-precision option (float16); PramaLLC/BEN2@2c99a5da477b BEN2.py, bicubic resize / normalisation / bilinear back / min-maxben2load / first call: original 2.29 s / 0.926 s, portable 13.95 s / 0.919 s, kernels 1.12 s / 0.435 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
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 | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
ben2 | DIS5K validation (DIS-VD), all 470 images, MAE / max F-beta | 0.0403 / 0.9000 | |||||
ben2 | DIS5K validation (DIS-VD), every 2nd image (235), MAE / max F-beta | 0.0421 / 0.8919 | 0.0421 / 0.8919 | 0.0421 / 0.8919 | 0.0421 / 0.8919 | 0.0421 / 0.8919 |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks a49aaba7, 2026-11-12.
Parity
CPU, float32: max |diff| <= 3.5e-06 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 2.4e-05 and p99 <= 0.00026 (absolute error of the output alpha).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
ben2 | 2e-05 / 0.00017 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, igev@f075827d68c6:sm_120 |
Example output
No example rendered for this checkpoint yet.