Models · Matting

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

Checkpoint ben2

Paper 2025 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 104 ms 1080x1920, fp16
vs the faster original 1.9× original fp16: 201 ms
Peak memory 1,430 MiB original: 2,466 MiB
Accuracy vs original fp32 ±0.0000 kernels mae, DIS5K validation (DIS-VD) (0.0421 original)

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)

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original fp16the authors' mixed-precision option (float16); PramaLLC/BEN2@2c99a5da477b BEN2.py, bicubic resize / normalisation / bilinear back / min-maxfp16 201–2,466 MiB/2,772 MiB0.80.32
Portable fp32fp32not measured ––––
Portablefp16 1101.8×1,681 MiB/1,956 MiB0.70.48
Kernelsfp16 1041.9×1,430 MiB/1,698 MiB0.80.35
Portable + torch.compile 1031.9×813 MiB/916 MiB71 (build)–
TensorRT fp16fp16 58.23.4×998 MiBenginenot comparable140 (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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-12Originalfp3210380 6,959 MiB process–1080x1920
Portablefp321148 6,252 MiB processmatches1080x1920
Kernelsfp16not 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

Our reading of the licences, not legal advice.

Weights

ben2.safetensors 381 MB· hosted on Hugging Face

fastforks 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

Rundtypemae ↑max_fbeta ↑imagesms / image
Original fp32not measured
Original fp16not measured
Portable fp32not measured
Portablenot measured
Kernelsfp160.04030.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

Rundtypemae ↑max_fbeta ↑Δ mae vs fp32 originalimagesms / image
Original fp32fp320.04210.8919 reference 235 320
Original fp16fp160.04210.8919 ±0.0000 235 202
Portable fp32fp320.04210.8919 ±0.0000 235 328
Portablefp160.04210.8919 ±0.0000 235 183
Kernelsfp160.04210.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).

CheckToleranceMeasured
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 gates
  • cutlass_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.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
ben2synthetic (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): ben2 3000x4000 (1.8 GiB peak allocated, 2.7 reserved)
  • ben2 1080x1920, first call: portable + torch.compile 71 s (cold Inductor cache), TensorRT fp16 140 s (ONNX + engine).
  • ben2 original 1080x1920: the authors' mixed-precision option (float16); PramaLLC/BEN2@2c99a5da477b BEN2.py, bicubic resize / normalisation / bilinear back / min-max
  • ben2 load / 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.

variantdatasetoriginal fp32original fp16portableportable fp32kernelsnote
ben2DIS5K validation (DIS-VD), all 470 images, MAE / max F-beta0.0403 / 0.9000
ben2DIS5K validation (DIS-VD), every 2nd image (235), MAE / max F-beta0.0421 / 0.89190.0421 / 0.89190.0421 / 0.89190.0421 / 0.89190.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).

variantkernels error vs original, mean / p99GPU, torchkernels used
ben22e-05 / 0.00017RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, igev@f075827d68c6:sm_120

Example output

No example rendered for this checkpoint yet.