ben2 / README.md
Flor's picture
card: update from fastforks 1cbf1671
aa284d2 verified
|
Raw History Blame Contribute Delete
6.19 kB
---
library_name: "fastforks"
pipeline_tag: "image-segmentation"
license: "mit"
tags:
- "matting"
- "background-removal"
- "dichotomous-image-segmentation"
- "cuda"
- "pytorch"
- "fastforks"
- "fastforks-card"
base_model:
- "PramaLLC/BEN2"
---
# BEN2 (fastforks)
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.
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/PramaLLC/BEN2> at `2c99a5da477b`.
Author weight repos: <https://huggingface.co/PramaLLC/BEN2>.
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`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/matting/models/ben2/card.toml).
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
| `ben2@1` | [ben2.safetensors](https://huggingface.co/PramaLLC/BEN2/resolve/e48a20765fb421d19dcdb0bf3cc61e802ca5ec8f/model.safetensors) | `ea8b7907176a` | MIT | yes |
## 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), 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.).
Licence evidence: https://huggingface.co/PramaLLC/BEN2/blob/e48a20765fb421d19dcdb0bf3cc61e802ca5ec8f/README.md ; https://github.com/PramaLLC/BEN2/blob/2c99a5da477b5523585bfa5c893888a6e818a8f6/LICENSE
## 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)
## 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 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `ben2` | 201 | 110 | 104 | 1.9x | 1.1x | 2466 / 2772 | 1681 / 1956 | 1430 / 1698 |
### Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
| --- | --- | --- | --- | --- | --- | --- |
| `ben2` | 2.29 | 13.95 | 1.12 | 0.93 | 0.92 | 0.43 |
### 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) |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `ben2` | 1080x1920 | 110 ms | 103 ms | 58.2 ms | 104 ms | 70.8 s | 140 s | 1681 / 1956 | 813 / 916 | 1430 / 1698 | 1280 / 1326 |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (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 |
|---|---|---|---|---|---|---|
| `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 | |
Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks a49aaba7, 2026-11-12.
### Parity with the original code
Every variant is checked against reference outputs of the original code at its pinned commit. 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`).
## Usage
```python
from fastforks import matting
model = matting.load("ben2") # 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: `ben2`.
## Kernels backend
`matting.load("ben2", mode="kernels")` runs our CUDA kernels (`cudnn_hacc`, `igev`, `cutlass_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.
<!-- staged from fastforks 1cbf1671 (2026-11-15) -->