General Introduction
BEN2 (Background Erase Network 2) is a deep learning model developed by Prama LLC that specializes in automatically removing the background from an image and generating a foreground image. The model employs an innovative Confidence Guided Matting (CGM) pipeline to process pixels with lower confidence in the base model through a refinement network, resulting in higher accuracy foreground segmentation.BEN2 was trained on DIS5k and Prama LLC's 22K proprietary segmentation dataset, and performs excellently, especially in hair keying, 4K processing, object segmentation and edge refinement. Its installation package is only 1.13GB, and officially deployed instances are capable of keying a 1080p image in less than 6 seconds, while processing a 4K image takes about 20 seconds.
Related Recommendations:removebg: remove picture background with one click, removebg online free Chinese version
Function List
- Background Removal: Automatically removes the background from the image and generates a binary mask and foreground image.
- foreground segmentation: High-precision foreground segmentation for a variety of complex scenes.
- CUDA Support: Supports GPU acceleration to boost processing speed.
- Simple API: Provides a clean API for easy integration into various applications.
- High Resolution Processing: Supports 4K image processing for high resolution requirements.
- Edge refinement: Enhance segmentation accuracy by processing edges through a fine-grained network.
- Rapid processing: The official deployment example was able to key 1080p images in 6 seconds, and 4K images were processed in about 20 seconds.
Using Help
Installation process
- Cloning Warehouse:
git clone https://huggingface.co/PramaLLC/BEN2
cd BEN2
- Install the dependencies:
pip install -r requirements.txt
Usage Process
- Import the necessary libraries and models:
from PIL import Image
import torch
from model import BEN_Base
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = BEN_Base().to(device).eval()
model.load_state_dict(torch.load('BEN_Base.pth'))
- Load the image and perform inference:
image = Image.open('path_to_image.png')
mask, foreground = model.inference(image)
mask.save('mask.png')
foreground.save('foreground.png')
Main function operation flow
- Background Removal::
- After loading the image, the model automatically generates a background mask and a foreground image.
- The mask image is saved as
mask.png
The foreground image is saved asforeground.png
The
- foreground segmentation::
- The model passes through the Confidence Guided Matting (CGM) pipeline to accurately segment the foreground.
- Ideal for complex backgrounds and detail-rich images such as hair, edges, etc.
- High Resolution Processing::
- Supports 4K image processing to ensure the segmentation effect of high-resolution images.
- Suitable for application scenarios that require high precision and quality image processing.
- Edge refinement::
- Enhance segmentation accuracy by processing edges through a fine-grained network.
- Especially suitable for images that require fine edge processing, such as product photos, portraits, etc.
- Rapid processing::
- The official deployment example is capable of keying 1080p images in 6 seconds, and 4K images are processed in about 20 seconds.
- Ideal for application scenarios where a large number of images need to be processed quickly.