# FeyNobg
A background-removal model from Feyn Inc. that deepens BiRefNet's architecture and retrains it. LibreYOLO ships inference and validation for FeyNobg's matte task.
Tasks: Background removal. Install: pip install libreyolo.
Verified against LibreYOLO v1.5.0.

## Install

FeyNobg needs no optional extra. Everything it imports is in the base
install.

```bash
pip install libreyolo
```

## Predict

The checkpoint downloads from the LibreYOLO organization on Hugging Face on
first use and is cached locally, the same as any other family, though it is
not yet listed in the Checkpoints table on this page.

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreFeyNobgl-matte.pt")
result = model(SAMPLE_IMAGE, save=True)

matte = result.matte
print(matte.array.shape, matte.array.dtype)
```

**CLI**

```bash
libreyolo predict model=LibreFeyNobgl-matte.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
```

**Cutout**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

model = LibreYOLO("LibreFeyNobgl-matte.pt")
result = model(SAMPLE_IMAGE)

# RGBA (H, W, 4) uint8: source RGB plus the matte as an alpha channel.
rgba = result.cutout()
result.save("subject.png")
```

A matte result carries no boxes; `result.matte` is a dense `(H, W)`
float32 array in `[0, 1]`, 1 fully foreground and 0 fully background. Unlike a
binary mask, the soft matte keeps anti-aliased edge detail such as hair and
fur. `result.cutout()` composites the source image with that alpha channel
into an RGBA array, and `result.save(path)` (or `save=True` on the predict
call) writes it straight to a transparent-background PNG. The model runs at a
fixed native 1024x1024 canvas; a different resolution is not supported,
because the Swin backbone's relative-position tables are tied to it, and a
mismatch interpolates them badly rather than raising an error. See
[prediction](/docs/predict) for sources, streaming and result handling.

## Variants

One published size, `l`, a Swin-L tier backbone. FeyNobg takes BiRefNet's
architecture and deepens its third Swin stage from 18 to 24 blocks before
retraining, so the LibreYOLO port reuses BiRefNet's forward path,
preprocessing and single-logit output contract; predict, validate and
checkpoint handling behave the same as the `birefnet` family.

## Validate

`val()` reports two metrics over a paired image/matte folder, both in
`[0, 1]` and independent of resolution: MAE, the mean absolute error against
the ground-truth alpha (lower is better), and S-measure (Fan et al., ICCV
2017), a structural similarity that credits preserving the subject's shape and
holes, which pixel MAE alone misses (higher is better). Validation drives the
model's own `predict`, so it uses the family's exact preprocessing.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreFeyNobgl-matte.pt")

# A directory containing images/ and an auto-detected matte directory
# (mattes/, matte/, gt/, masks/, mask/ or alpha/) also works in place
# of a dataset YAML.
metrics = model.val(data="my-matte-dataset/")

print(metrics["metrics/MAE"])
print(metrics["metrics/Smeasure"])
```

Validation is inference-only. The upstream `nobg` library ships Apache-2.0
training code; fine-tuning today means training there and converting the
result with LibreYOLO's own conversion script, not calling `train()` on this
family, which raises rather than running a partial trainer.

## 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: FeyNobg, Feyn Inc.
- Upstream license: Apache-2.0
- Upstream source: https://github.com/feyninc/nobg
- LibreYOLO code: MIT
- Weights: Apache-2.0, republished at https://huggingface.co/LibreYOLO
- Interpretation: Apache-2.0 is a permissive license, so these weights can be used in commercial and closed-source products. It asks you to keep its license text and attribution notices with any copy of the weights you redistribute, and it grants a patent license. It places no obligation on your own application code. FeyNobg builds on BiRefNet's architecture (MIT) with a deepened backbone stage, and Feyn Inc. releases both the nobg library and the FeyNobg weights under Apache-2.0. LibreYOLO's checkpoint is a format conversion of Feyn's own published weights, with the learned parameters unchanged; fine-tuning is not wired into this library, so there is no LibreYOLO-trained variant to license separately.

## Citation

```bibtex
@software{nobg,
  title={nobg: Open Source Background Removal Models for Image and Video Matting},
  author={Hichri, Hafedh},
  year={2026},
  url={https://github.com/feyninc/nobg},
  license={Apache-2.0},
}
```

Copied from https://github.com/feyninc/nobg#citation


## FeyNobg architecture

- l: [SVG](/diagrams/models/feynobg/l-matte.svg), [interactive diagram](/diagrams/models/feynobg/l-matte.html)
