Update README.md
Browse files
README.md
CHANGED
|
@@ -1,175 +1,40 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 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 |
-
[CLICK HERE FOR A DEMO](https://huggingface.co/spaces/briaai/BRIA-RMBG-1.4)
|
| 43 |
-
|
| 44 |
-
**NOTE** New RMBG version available! Check out [RMBG-2.0](https://huggingface.co/briaai/RMBG-2.0)
|
| 45 |
-
|
| 46 |
-
Join our [Discord community](https://discord.gg/Nxe9YW9zHS) for more information, tutorials, tools, and to connect with other users!
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-

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

|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
## Architecture
|
| 105 |
-
|
| 106 |
-
RMBG v1.4 is developed on the [IS-Net](https://github.com/xuebinqin/DIS) enhanced with our unique training scheme and proprietary dataset.
|
| 107 |
-
These modifications significantly improve the model’s accuracy and effectiveness in diverse image-processing scenarios.
|
| 108 |
-
|
| 109 |
-
## Installation
|
| 110 |
-
```bash
|
| 111 |
-
pip install -qr https://huggingface.co/briaai/RMBG-1.4/resolve/main/requirements.txt
|
| 112 |
-
```
|
| 113 |
-
|
| 114 |
-
## Usage
|
| 115 |
-
|
| 116 |
-
Either load the pipeline
|
| 117 |
-
```python
|
| 118 |
-
from transformers import pipeline
|
| 119 |
-
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
| 120 |
-
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
|
| 121 |
-
pillow_mask = pipe(image_path, return_mask = True) # outputs a pillow mask
|
| 122 |
-
pillow_image = pipe(image_path) # applies mask on input and returns a pillow image
|
| 123 |
-
```
|
| 124 |
-
|
| 125 |
-
Or load the model
|
| 126 |
-
```python
|
| 127 |
-
from PIL import Image
|
| 128 |
-
from skimage import io
|
| 129 |
-
import torch
|
| 130 |
-
import torch.nn.functional as F
|
| 131 |
-
from transformers import AutoModelForImageSegmentation
|
| 132 |
-
from torchvision.transforms.functional import normalize
|
| 133 |
-
model = AutoModelForImageSegmentation.from_pretrained("briaai/RMBG-1.4",trust_remote_code=True)
|
| 134 |
-
def preprocess_image(im: np.ndarray, model_input_size: list) -> torch.Tensor:
|
| 135 |
-
if len(im.shape) < 3:
|
| 136 |
-
im = im[:, :, np.newaxis]
|
| 137 |
-
# orig_im_size=im.shape[0:2]
|
| 138 |
-
im_tensor = torch.tensor(im, dtype=torch.float32).permute(2,0,1)
|
| 139 |
-
im_tensor = F.interpolate(torch.unsqueeze(im_tensor,0), size=model_input_size, mode='bilinear')
|
| 140 |
-
image = torch.divide(im_tensor,255.0)
|
| 141 |
-
image = normalize(image,[0.5,0.5,0.5],[1.0,1.0,1.0])
|
| 142 |
-
return image
|
| 143 |
-
|
| 144 |
-
def postprocess_image(result: torch.Tensor, im_size: list)-> np.ndarray:
|
| 145 |
-
result = torch.squeeze(F.interpolate(result, size=im_size, mode='bilinear') ,0)
|
| 146 |
-
ma = torch.max(result)
|
| 147 |
-
mi = torch.min(result)
|
| 148 |
-
result = (result-mi)/(ma-mi)
|
| 149 |
-
im_array = (result*255).permute(1,2,0).cpu().data.numpy().astype(np.uint8)
|
| 150 |
-
im_array = np.squeeze(im_array)
|
| 151 |
-
return im_array
|
| 152 |
-
|
| 153 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 154 |
-
model.to(device)
|
| 155 |
-
|
| 156 |
-
# prepare input
|
| 157 |
-
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
| 158 |
-
orig_im = io.imread(image_path)
|
| 159 |
-
orig_im_size = orig_im.shape[0:2]
|
| 160 |
-
model_input_size = [1024, 1024]
|
| 161 |
-
image = preprocess_image(orig_im, model_input_size).to(device)
|
| 162 |
-
|
| 163 |
-
# inference
|
| 164 |
-
result=model(image)
|
| 165 |
-
|
| 166 |
-
# post process
|
| 167 |
-
result_image = postprocess_image(result[0][0], orig_im_size)
|
| 168 |
-
|
| 169 |
-
# save result
|
| 170 |
-
pil_mask_im = Image.fromarray(result_image)
|
| 171 |
-
orig_image = Image.open(image_path)
|
| 172 |
-
no_bg_image = orig_image.copy()
|
| 173 |
-
no_bg_image.putalpha(pil_mask_im)
|
| 174 |
-
```
|
| 175 |
-
|
|
|
|
| 1 |
+
license: other
|
| 2 |
+
license_name: custom-non-commercial
|
| 3 |
+
license_link: https://huggingface.co/Muhammad8815/inno-rmbg-removal-8815/blob/main/LICENSE
|
| 4 |
+
pipeline_tag: image-segmentation
|
| 5 |
+
tags:
|
| 6 |
+
- remove-background
|
| 7 |
+
- background-removal
|
| 8 |
+
- pytorch
|
| 9 |
+
- onnx
|
| 10 |
+
- image-segmentation
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Inno RMBG Removal v1.0
|
| 14 |
+
|
| 15 |
+
This is a custom-trained image background removal model using PyTorch and ONNX. It performs pixel-wise background removal on input images with high accuracy.
|
| 16 |
+
|
| 17 |
+
## Model Highlights
|
| 18 |
+
|
| 19 |
+
- Supports PyTorch `.pth` and ONNX inference.
|
| 20 |
+
- Trained on diverse images of objects, people, and scenes.
|
| 21 |
+
- Provides a binary mask of the foreground, suitable for downstream tasks (e.g. background replacement, transparency effects).
|
| 22 |
+
|
| 23 |
+
## Example Input/Output
|
| 24 |
+
|
| 25 |
+
**Input:**
|
| 26 |
+

|
| 27 |
+
|
| 28 |
+
**Output (no background):**
|
| 29 |
+

|
| 30 |
+
|
| 31 |
+
## Inference Code (PyTorch)
|
| 32 |
+
```python
|
| 33 |
+
from PIL import Image
|
| 34 |
+
from utilities import preprocess_image, postprocess_image, load_model
|
| 35 |
+
|
| 36 |
+
model = load_model("model.pth")
|
| 37 |
+
image = Image.open("example_input.jpg")
|
| 38 |
+
mask = model.predict(image)
|
| 39 |
+
image.putalpha(mask)
|
| 40 |
+
image.save("output.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|