Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,175 +1,178 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: other
|
| 3 |
-
license_name: bria-rmbg-1.4
|
| 4 |
-
license_link: https://bria.ai/bria-huggingface-model-license-agreement/
|
| 5 |
-
pipeline_tag: image-segmentation
|
| 6 |
-
tags:
|
| 7 |
-
- remove background
|
| 8 |
-
- background
|
| 9 |
-
- background-removal
|
| 10 |
-
- Pytorch
|
| 11 |
-
- vision
|
| 12 |
-
- legal liability
|
| 13 |
-
- transformers
|
| 14 |
-
- transformers.js
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
- **
|
| 61 |
-
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
| 77 |
-
|
|
| 78 |
-
|
|
| 79 |
-
|
|
| 80 |
-
|
| 81 |
-
|
|
| 82 |
-
|
|
| 83 |
-
|
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
| 88 |
-
| -
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
| 94 |
-
|
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
from
|
| 132 |
-
from
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: bria-rmbg-1.4
|
| 4 |
+
license_link: https://bria.ai/bria-huggingface-model-license-agreement/
|
| 5 |
+
pipeline_tag: image-segmentation
|
| 6 |
+
tags:
|
| 7 |
+
- remove background
|
| 8 |
+
- background
|
| 9 |
+
- background-removal
|
| 10 |
+
- Pytorch
|
| 11 |
+
- vision
|
| 12 |
+
- legal liability
|
| 13 |
+
- transformers
|
| 14 |
+
- transformers.js
|
| 15 |
+
extra_gated_description: RMBG v1.4 is available as a source-available model for non-commercial use
|
| 16 |
+
extra_gated_heading: Fill in this form to get instant access
|
| 17 |
+
extra_gated_fields:
|
| 18 |
+
Name: text
|
| 19 |
+
Company/Org name: text
|
| 20 |
+
Org Type (Early/Growth Startup, Enterprise, Academy): text
|
| 21 |
+
Role: text
|
| 22 |
+
Country: text
|
| 23 |
+
Email: text
|
| 24 |
+
By submitting this form, I agree to BRIA’s Privacy policy and Terms & conditions, see links below: checkbox
|
| 25 |
+
title: Background Remover Pro
|
| 26 |
+
sdk: gradio
|
| 27 |
+
emoji: ⚡
|
| 28 |
+
colorFrom: blue
|
| 29 |
+
colorTo: purple
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
# BRIA Background Removal v1.4 Model Card
|
| 33 |
+
|
| 34 |
+
RMBG v1.4 is our state-of-the-art background removal model, designed to effectively separate foreground from background in a range of
|
| 35 |
+
categories and image types. This model has been trained on a carefully selected dataset, which includes:
|
| 36 |
+
general stock images, e-commerce, gaming, and advertising content, making it suitable for commercial use cases powering enterprise content creation at scale.
|
| 37 |
+
The accuracy, efficiency, and versatility currently rival leading source-available models.
|
| 38 |
+
It is ideal where content safety, legally licensed datasets, and bias mitigation are paramount.
|
| 39 |
+
|
| 40 |
+
Developed by BRIA AI, RMBG v1.4 is available as a source-available model for non-commercial use.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
To purchase a commercial license, simply click [Here](https://go.bria.ai/3D5EGp0).
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
[CLICK HERE FOR A DEMO](https://huggingface.co/spaces/briaai/BRIA-RMBG-1.4)
|
| 47 |
+
|
| 48 |
+
**NOTE** New RMBG version available! Check out [RMBG-2.0](https://huggingface.co/briaai/RMBG-2.0)
|
| 49 |
+
|
| 50 |
+
Join our [Discord community](https://discord.gg/Nxe9YW9zHS) for more information, tutorials, tools, and to connect with other users!
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+

|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
### Model Description
|
| 57 |
+
|
| 58 |
+
- **Developed by:** [BRIA AI](https://bria.ai/)
|
| 59 |
+
- **Model type:** Background Removal
|
| 60 |
+
- **License:** [bria-rmbg-1.4](https://bria.ai/bria-huggingface-model-license-agreement/)
|
| 61 |
+
- The model is released under a Creative Commons license for non-commercial use.
|
| 62 |
+
- Commercial use is subject to a commercial agreement with BRIA. To purchase a commercial license simply click [Here](https://go.bria.ai/3B4Asxv).
|
| 63 |
+
|
| 64 |
+
- **Model Description:** BRIA RMBG 1.4 is a saliency segmentation model trained exclusively on a professional-grade dataset.
|
| 65 |
+
- **BRIA:** Resources for more information: [BRIA AI](https://bria.ai/)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
## Training data
|
| 70 |
+
Bria-RMBG model was trained with over 12,000 high-quality, high-resolution, manually labeled (pixel-wise accuracy), fully licensed images.
|
| 71 |
+
Our benchmark included balanced gender, balanced ethnicity, and people with different types of disabilities.
|
| 72 |
+
For clarity, we provide our data distribution according to different categories, demonstrating our model’s versatility.
|
| 73 |
+
|
| 74 |
+
### Distribution of images:
|
| 75 |
+
|
| 76 |
+
| Category | Distribution |
|
| 77 |
+
| -----------------------------------| -----------------------------------:|
|
| 78 |
+
| Objects only | 45.11% |
|
| 79 |
+
| People with objects/animals | 25.24% |
|
| 80 |
+
| People only | 17.35% |
|
| 81 |
+
| people/objects/animals with text | 8.52% |
|
| 82 |
+
| Text only | 2.52% |
|
| 83 |
+
| Animals only | 1.89% |
|
| 84 |
+
|
| 85 |
+
| Category | Distribution |
|
| 86 |
+
| -----------------------------------| -----------------------------------------:|
|
| 87 |
+
| Photorealistic | 87.70% |
|
| 88 |
+
| Non-Photorealistic | 12.30% |
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
| Category | Distribution |
|
| 92 |
+
| -----------------------------------| -----------------------------------:|
|
| 93 |
+
| Non Solid Background | 52.05% |
|
| 94 |
+
| Solid Background | 47.95%
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
| Category | Distribution |
|
| 98 |
+
| -----------------------------------| -----------------------------------:|
|
| 99 |
+
| Single main foreground object | 51.42% |
|
| 100 |
+
| Multiple objects in the foreground | 48.58% |
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
## Qualitative Evaluation
|
| 104 |
+
|
| 105 |
+

|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
## Architecture
|
| 109 |
+
|
| 110 |
+
RMBG v1.4 is developed on the [IS-Net](https://github.com/xuebinqin/DIS) enhanced with our unique training scheme and proprietary dataset.
|
| 111 |
+
These modifications significantly improve the model’s accuracy and effectiveness in diverse image-processing scenarios.
|
| 112 |
+
|
| 113 |
+
## Installation
|
| 114 |
+
```bash
|
| 115 |
+
pip install -qr https://huggingface.co/briaai/RMBG-1.4/resolve/main/requirements.txt
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
## Usage
|
| 119 |
+
|
| 120 |
+
Either load the pipeline
|
| 121 |
+
```python
|
| 122 |
+
from transformers import pipeline
|
| 123 |
+
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
| 124 |
+
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
|
| 125 |
+
pillow_mask = pipe(image_path, return_mask = True) # outputs a pillow mask
|
| 126 |
+
pillow_image = pipe(image_path) # applies mask on input and returns a pillow image
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
Or load the model
|
| 130 |
+
```python
|
| 131 |
+
from PIL import Image
|
| 132 |
+
from skimage import io
|
| 133 |
+
import torch
|
| 134 |
+
import torch.nn.functional as F
|
| 135 |
+
from transformers import AutoModelForImageSegmentation
|
| 136 |
+
from torchvision.transforms.functional import normalize
|
| 137 |
+
model = AutoModelForImageSegmentation.from_pretrained("briaai/RMBG-1.4",trust_remote_code=True)
|
| 138 |
+
def preprocess_image(im: np.ndarray, model_input_size: list) -> torch.Tensor:
|
| 139 |
+
if len(im.shape) < 3:
|
| 140 |
+
im = im[:, :, np.newaxis]
|
| 141 |
+
# orig_im_size=im.shape[0:2]
|
| 142 |
+
im_tensor = torch.tensor(im, dtype=torch.float32).permute(2,0,1)
|
| 143 |
+
im_tensor = F.interpolate(torch.unsqueeze(im_tensor,0), size=model_input_size, mode='bilinear')
|
| 144 |
+
image = torch.divide(im_tensor,255.0)
|
| 145 |
+
image = normalize(image,[0.5,0.5,0.5],[1.0,1.0,1.0])
|
| 146 |
+
return image
|
| 147 |
+
|
| 148 |
+
def postprocess_image(result: torch.Tensor, im_size: list)-> np.ndarray:
|
| 149 |
+
result = torch.squeeze(F.interpolate(result, size=im_size, mode='bilinear') ,0)
|
| 150 |
+
ma = torch.max(result)
|
| 151 |
+
mi = torch.min(result)
|
| 152 |
+
result = (result-mi)/(ma-mi)
|
| 153 |
+
im_array = (result*255).permute(1,2,0).cpu().data.numpy().astype(np.uint8)
|
| 154 |
+
im_array = np.squeeze(im_array)
|
| 155 |
+
return im_array
|
| 156 |
+
|
| 157 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 158 |
+
model.to(device)
|
| 159 |
+
|
| 160 |
+
# prepare input
|
| 161 |
+
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
| 162 |
+
orig_im = io.imread(image_path)
|
| 163 |
+
orig_im_size = orig_im.shape[0:2]
|
| 164 |
+
model_input_size = [1024, 1024]
|
| 165 |
+
image = preprocess_image(orig_im, model_input_size).to(device)
|
| 166 |
+
|
| 167 |
+
# inference
|
| 168 |
+
result=model(image)
|
| 169 |
+
|
| 170 |
+
# post process
|
| 171 |
+
result_image = postprocess_image(result[0][0], orig_im_size)
|
| 172 |
+
|
| 173 |
+
# save result
|
| 174 |
+
pil_mask_im = Image.fromarray(result_image)
|
| 175 |
+
orig_image = Image.open(image_path)
|
| 176 |
+
no_bg_image = orig_image.copy()
|
| 177 |
+
no_bg_image.putalpha(pil_mask_im)
|
| 178 |
+
```
|