GulbaharAI commited on
Commit
35e3112
·
verified ·
1 Parent(s): 5aaf40e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +178 -175
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
- extra_gated_description: RMBG v1.4 is available as a source-available model for non-commercial use
17
- extra_gated_heading: "Fill in this form to get instant access"
18
- extra_gated_fields:
19
- Name: text
20
- Company/Org name: text
21
- Org Type (Early/Growth Startup, Enterprise, Academy): text
22
- Role: text
23
- Country: text
24
- Email: text
25
- By submitting this form, I agree to BRIA’s Privacy policy and Terms & conditions, see links below: checkbox
26
- ---
27
-
28
- # BRIA Background Removal v1.4 Model Card
29
-
30
- RMBG v1.4 is our state-of-the-art background removal model, designed to effectively separate foreground from background in a range of
31
- categories and image types. This model has been trained on a carefully selected dataset, which includes:
32
- general stock images, e-commerce, gaming, and advertising content, making it suitable for commercial use cases powering enterprise content creation at scale.
33
- The accuracy, efficiency, and versatility currently rival leading source-available models.
34
- It is ideal where content safety, legally licensed datasets, and bias mitigation are paramount.
35
-
36
- Developed by BRIA AI, RMBG v1.4 is available as a source-available model for non-commercial use.
37
-
38
-
39
- To purchase a commercial license, simply click [Here](https://go.bria.ai/3D5EGp0).
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
- ![examples](t4.png)
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
- ![examples](results.png)
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
+ ---
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
+ ![examples](t4.png)
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
+ ![examples](results.png)
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
+ ```