# BEN2
BEN2 predicts a soft foreground alpha matte for background removal.
Tasks: Background removal. Install: pip install libreyolo.
Verified against LibreYOLO v1.6.0.

## Install

```bash
pip install "libreyolo"
```

## Predict

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreBEN2b-matte.pt", device="cpu")
result = model(SAMPLE_IMAGE)
print(result.matte.array.shape)
result.save("cutout.png")
```

Prediction uses a fixed 1024-pixel canvas. Native prediction accepts batches; exports require batch 1. `result.save()` writes a transparent cutout. Training is not supported.


## Validate

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreBEN2b-matte.pt", device="cpu")
# data: a matte dataset YAML, or a folder with images/ and mattes/ (grayscale alpha, same file stems)
metrics = model.val(data="path/to/your/matte_dataset.yaml", workers=0)
print(metrics)
```

Use the dataset format for this task. [Validation](/docs/train/validation) explains the dataset requirements and returned metrics.

## Export

| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Background removal | yes | yes | yes | yes | yes |  |  |  | yes |  |  |  |

A "yes" means the export is supported. An empty cell means the exporter refuses that combination.

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreBEN2b-matte.pt", device="cpu")
model.export(format="onnx")
```

[Export setup](/docs/export) lists format dependencies and loading exported artifacts.

## Checkpoints

| File | Input (px) | Task | Weights license |
| --- | --- | --- | --- |
| `LibreBEN2b-matte.pt` |  | Background removal | mit |

## Licensing

Check the license on the Hugging Face repository of the specific weights you download. That repository is authoritative and licenses are not always uniform across a family. This is a description of the licenses involved, not legal advice.

- Original work: BEN2, Prama LLC
- Upstream license: MIT
- Upstream source: https://github.com/PramaLLC/BEN2
- LibreYOLO code: MIT
- Weights: MIT, republished at https://huggingface.co/LibreYOLO
- Interpretation: The publisher declares MIT for the source and pretrained model.


## BEN2 architecture

- Base: [SVG](/diagrams/models/ben2/b-matte.svg), [interactive diagram](/diagrams/models/ben2/b-matte.html)
