Background Remover (BEN2 Base)
BEN2 Base is a deep learning model for automatic background removal from images.
The model predicts a foreground segmentation mask that can be used to remove or replace the background.
This repository contains the pretrained weights:
BEN2_Base.pth
The model can be used in:
photo editing tools
product image processing
portrait segmentation
dataset preprocessing
AI image pipelines
Model Details
Property Value Model Name BEN2 Base Task Background Removal Architecture Segmentation Network Framework PyTorch File Size 1.13 GB Input RGB image Output Foreground mask
Repository Files
File Description BEN2_Base.pth Pretrained background removal model weights
Installation
Install required libraries:
pip install torch torchvision pillow numpy opencv-python
Usage Example
Example inference using PyTorch.
1 import torch
2 from PIL import Image
3 import torchvision . transforms as transforms
4
5 # Load model
6 model = torch . load ( "BEN2_Base.pth" , map_location = "cpu" )
7 model . eval ( )
8
9 # Preprocessing
10 transform = transforms . Compose ( [
11 transforms . Resize ( ( 512 , 512 ) ) ,
12 transforms . ToTensor ( )
13 ] )
14
15 image = Image . open ( "input.jpg" ) . convert ( "RGB" )
16 input_tensor = transform ( image ) . unsqueeze ( 0 )
17
18 # Inference
19 with torch . no_grad ( ) :
20 output = model ( input_tensor )
21
22 mask = output . squeeze ( ) . cpu ( ) . numpy ( )
You can apply the mask to generate a transparent PNG or replace the background.
Example Workflow
Load an image
Resize and normalize
Run model inference
Generate segmentation mask
Remove background
Use Cases
E-commerce
Remove backgrounds from product images.
Portrait Editing
Create clean profile images.
Content Creation
Prepare images for thumbnails, ads, or designs.
AI Pipelines
Preprocess images for ML datasets.
Limitations
Performance may vary with extremely complex backgrounds.
Very small foreground objects may reduce segmentation quality.
Images should be resized for optimal results.
Training
This repository provides pretrained weights only .
License
Please verify the license before using the model in commercial applications.
Author
Ashank Gupta