ONNX Model Zoo

RedbeardNZ/BEN2

By RedbeardNZ · ↓ 3 · ♥ 0 · Updated 2025-06-25

What's in this repo

This page lists the files in RedbeardNZ/BEN2, including BEN2_Base.onnx.

  • 1 ONNX models (.onnx files)
  • 16 files, including 6 .png, 3 .py, 1 .onnx, 1 .pth, 1 .md, 1 .json
  • Last updated 2025-06-25

ONNX files

File Size Download
BEN2_Base.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

BEN2: Background Erase Network

arXiv GitHub Website

Overview

BEN2 (Background Erase Network) introduces a novel approach to foreground segmentation through its innovative Confidence Guided Matting (CGM) pipeline. The architecture employs a refiner network that targets and processes pixels where the base model exhibits lower confidence levels, resulting in more precise and reliable matting results. This model is built on BEN: PWC

BEN2 access

BEN2 was trained on the DIS5k and our 22K proprietary segmentation dataset. Our enhanced model delivers superior performance in hair matting, 4K processing, object segmentation, and edge refinement. Our Base model is open source. To try the full model through our free web demo or integrate BEN2 into your project with our API:

Contact us

  • For access to our commercial model email us at sales@prama.llc
  • Our website: https://prama.llc/
  • Follow us on X: https://x.com/PramaResearch/

Installation

pip install -e "git+https://github.com/PramaLLC/BEN2.git#egg=ben2"

Quick start code

from ben2 import BEN_Base
from PIL import Image
import torch

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

file = "./image.png" # input image

model = BEN_Base.from_pretrained("PramaLLC/BEN2")
model.to(device).eval()

image = Image.open(file)
foreground = model.inference(image, refine_foreground=False,) #Refine foreground is an extract postprocessing step that increases inference time but can improve matting edges. The default value is False.

foreground.save("./foreground.png")

Batch image processing

from ben2 import BEN_Base
from PIL import Image
import torch

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

model = BEN_Base.from_pretrained("PramaLLC/BEN2")
model.to(device).eval()

file1 = "./image1.png" # input image1
file2 = "./image2.png" # input image2
image1 = Image.open(file1)
image2 = Image.open(file2)

foregrounds = model.inference([image1, image2]) #  We recommend that the batch size not exceed 3 for consumer GPUs as there are minimal inference gains due to our custom batch processing for the MVANet decoding steps.
foregrounds[0].save("./foreground1.png")
foregrounds[1].save("./foreground2.png")

BEN2 video segmentation

BEN2 Demo

Video Segmentation

sudo apt update
sudo apt install ffmpeg
from ben2 import BEN_Base
from PIL import Image
import torch

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

video_path = "/path_to_your_video.mp4"# input video

model = BEN_Base.from_pretrained("PramaLLC/BEN2")
model.to(device).eval()

model.segment_video(
    video_path= video_path,
    output_path="./", # Outputs will be saved as foreground.webm or foreground.mp4. The default value is "./"
    fps=0, # If this is set to 0 CV2 will detect the fps in the original video. The default value is 0.
    refine_foreground=False,  #refine foreground is an extract postprocessing step that increases inference time but can improve matting edges. The default value is False.
    batch=1,  # We recommended that batch size not exceed 3 for consumer GPUs as there are minimal inference gains. The default value is 1.
    print_frames_processed=True,  #Informs you what frame is being processed. The default value is True.
    webm = False, # This will output an alpha layer video but this defaults to mp4 when webm is false. The default value is False.
    rgb_value= (0, 255, 0) # If you do not use webm this will be the RGB value of the resulting background only when webm is False. The default value is a green background (0,255,0).
 )

# BEN2 evaluation Model Comparison

RMBG 2.0 did not preserve the DIS 5k validation dataset

Example 1 Example 2 Example 3 Example 6 Example 7

Model info

ben2 onnx safetensors BEN2 background-remove mask-generation Dichotomous image segmentation background remove foreground background remove background pytorch
↓ 3 ♥ 0

Created: 2025-06-25

Updated: 2025-06-25

View on Hugging Face

Files (16)

.gitattributes
BEN2.py
BEN2_Base.onnx ONNX
BEN2_demo_pictures/grid_example1.png
BEN2_demo_pictures/grid_example2.png
BEN2_demo_pictures/grid_example3.png
BEN2_demo_pictures/grid_example6.png
BEN2_demo_pictures/grid_example7.png
BEN2_demo_pictures/model_comparison.png
README.md
config.json
inference.py
model.safetensors
onnx_run.py
requirements.txt

Related models