RMBG v1.4 is our state-of-the-art background removal model, designed to effectively separate foreground from background in a range of
categories and image types. This model has been trained on a carefully selected dataset, which includes:
general stock images, e-commerce, gaming, and advertising content, making it suitable for commercial use cases powering enterprise content creation at scale.
The accuracy, efficiency, and versatility currently rival leading source-available models.
It is ideal where content safety, legally licensed datasets, and bias mitigation are paramount.
Developed by BRIA AI, RMBG v1.4 is available as a source-available model for non-commercial use.
To purchase a commercial license, simply click
Here.
NOTE New RMBG version available! Check out
RMBG-2.0
Join our
Discord community for more information, tutorials, tools, and to connect with other users!
-
-
Model type: Background Removal
-
- The model is released under a Creative Commons license for non-commercial use.
- Commercial use is subject to a commercial agreement with BRIA. To purchase a commercial license simply click Here.
-
Model Description: BRIA RMBG 1.4 is a saliency segmentation model trained exclusively on a professional-grade dataset.
-
BRIA: Resources for more information:
BRIA AI
Bria-RMBG model was trained with over 12,000 high-quality, high-resolution, manually labeled (pixel-wise accuracy), fully licensed images.
Our benchmark included balanced gender, balanced ethnicity, and people with different types of disabilities.
For clarity, we provide our data distribution according to different categories, demonstrating our model’s versatility.
RMBG v1.4 is developed on the
IS-Net enhanced with our unique training scheme and proprietary dataset.
These modifications significantly improve the model’s accuracy and effectiveness in diverse image-processing scenarios.
1from transformers import pipeline
2image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
3pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
4pillow_mask = pipe(image_path, return_mask = True) # outputs a pillow mask
5pillow_image = pipe(image_path) # applies mask on input and returns a pillow image
1from PIL import Image
2from skimage import io
3import torch
4import torch.nn.functional as F
5from transformers import AutoModelForImageSegmentation
6from torchvision.transforms.functional import normalize
7model = AutoModelForImageSegmentation.from_pretrained("briaai/RMBG-1.4",trust_remote_code=True)
8def preprocess_image(im: np.ndarray, model_input_size: list) -> torch.Tensor:
9 if len(im.shape) < 3:
10 im = im[:, :, np.newaxis]
11 # orig_im_size=im.shape[0:2]
12 im_tensor = torch.tensor(im, dtype=torch.float32).permute(2,0,1)
13 im_tensor = F.interpolate(torch.unsqueeze(im_tensor,0), size=model_input_size, mode='bilinear')
14 image = torch.divide(im_tensor,255.0)
15 image = normalize(image,[0.5,0.5,0.5],[1.0,1.0,1.0])
16 return image
17
18def postprocess_image(result: torch.Tensor, im_size: list)-> np.ndarray:
19 result = torch.squeeze(F.interpolate(result, size=im_size, mode='bilinear') ,0)
20 ma = torch.max(result)
21 mi = torch.min(result)
22 result = (result-mi)/(ma-mi)
23 im_array = (result*255).permute(1,2,0).cpu().data.numpy().astype(np.uint8)
24 im_array = np.squeeze(im_array)
25 return im_array
26
27device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
28model.to(device)
29
30# prepare input
31image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
32orig_im = io.imread(image_path)
33orig_im_size = orig_im.shape[0:2]
34model_input_size = [1024, 1024]
35image = preprocess_image(orig_im, model_input_size).to(device)
36
37# inference
38result=model(image)
39
40# post process
41result_image = postprocess_image(result[0][0], orig_im_size)
42
43# save result
44pil_mask_im = Image.fromarray(result_image)
45orig_image = Image.open(image_path)
46no_bg_image = orig_image.copy()
47no_bg_image.putalpha(pil_mask_im)