chinese-support
#38
by
Miykaelxxm - opened
- MyPipe.py +2 -2
- README.md +4 -21
- example_inference.py +3 -3
MyPipe.py
CHANGED
|
@@ -50,9 +50,9 @@ class RMBGPipe(Pipeline):
|
|
| 50 |
pil_im = Image.fromarray(result_image)
|
| 51 |
if return_mask ==True :
|
| 52 |
return pil_im
|
|
|
|
| 53 |
input_image = load_image(input_image)
|
| 54 |
-
no_bg_image =
|
| 55 |
-
no_bg_image.putalpha(pil_im)
|
| 56 |
return no_bg_image
|
| 57 |
|
| 58 |
# utilities functions
|
|
|
|
| 50 |
pil_im = Image.fromarray(result_image)
|
| 51 |
if return_mask ==True :
|
| 52 |
return pil_im
|
| 53 |
+
no_bg_image = Image.new("RGBA", pil_im.size, (0,0,0,0))
|
| 54 |
input_image = load_image(input_image)
|
| 55 |
+
no_bg_image.paste(input_image, mask=pil_im)
|
|
|
|
| 56 |
return no_bg_image
|
| 57 |
|
| 58 |
# utilities functions
|
README.md
CHANGED
|
@@ -11,7 +11,6 @@ tags:
|
|
| 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"
|
|
@@ -35,27 +34,16 @@ It is ideal where content safety, legally licensed datasets, and bias mitigation
|
|
| 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 |

|
| 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.
|
| 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/)
|
|
@@ -124,10 +112,6 @@ pillow_image = pipe(image_path) # applies mask on input and returns a pillow ima
|
|
| 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)
|
|
@@ -157,7 +141,6 @@ model.to(device)
|
|
| 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
|
|
@@ -167,9 +150,9 @@ result=model(image)
|
|
| 167 |
result_image = postprocess_image(result[0][0], orig_im_size)
|
| 168 |
|
| 169 |
# save result
|
| 170 |
-
|
|
|
|
| 171 |
orig_image = Image.open(image_path)
|
| 172 |
-
no_bg_image =
|
| 173 |
-
no_bg_image.putalpha(pil_mask_im)
|
| 174 |
```
|
| 175 |
|
|
|
|
| 11 |
- vision
|
| 12 |
- legal liability
|
| 13 |
- transformers
|
|
|
|
| 14 |
|
| 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"
|
|
|
|
| 34 |
|
| 35 |
Developed by BRIA AI, RMBG v1.4 is available as a source-available model for non-commercial use.
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
[CLICK HERE FOR A DEMO](https://huggingface.co/spaces/briaai/BRIA-RMBG-1.4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |

|
| 39 |
|
|
|
|
| 40 |
### Model Description
|
| 41 |
|
| 42 |
- **Developed by:** [BRIA AI](https://bria.ai/)
|
| 43 |
- **Model type:** Background Removal
|
| 44 |
- **License:** [bria-rmbg-1.4](https://bria.ai/bria-huggingface-model-license-agreement/)
|
| 45 |
- The model is released under a Creative Commons license for non-commercial use.
|
| 46 |
+
- Commercial use is subject to a commercial agreement with BRIA. [Contact Us](https://bria.ai/contact-us) for more information.
|
| 47 |
|
| 48 |
- **Model Description:** BRIA RMBG 1.4 is a saliency segmentation model trained exclusively on a professional-grade dataset.
|
| 49 |
- **BRIA:** Resources for more information: [BRIA AI](https://bria.ai/)
|
|
|
|
| 112 |
|
| 113 |
Or load the model
|
| 114 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
from transformers import AutoModelForImageSegmentation
|
| 116 |
from torchvision.transforms.functional import normalize
|
| 117 |
model = AutoModelForImageSegmentation.from_pretrained("briaai/RMBG-1.4",trust_remote_code=True)
|
|
|
|
| 141 |
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
| 142 |
orig_im = io.imread(image_path)
|
| 143 |
orig_im_size = orig_im.shape[0:2]
|
|
|
|
| 144 |
image = preprocess_image(orig_im, model_input_size).to(device)
|
| 145 |
|
| 146 |
# inference
|
|
|
|
| 150 |
result_image = postprocess_image(result[0][0], orig_im_size)
|
| 151 |
|
| 152 |
# save result
|
| 153 |
+
pil_im = Image.fromarray(result_image)
|
| 154 |
+
no_bg_image = Image.new("RGBA", pil_im.size, (0,0,0,0))
|
| 155 |
orig_image = Image.open(image_path)
|
| 156 |
+
no_bg_image.paste(orig_image, mask=pil_im)
|
|
|
|
| 157 |
```
|
| 158 |
|
example_inference.py
CHANGED
|
@@ -28,10 +28,10 @@ def example_inference():
|
|
| 28 |
result_image = postprocess_image(result[0][0], orig_im_size)
|
| 29 |
|
| 30 |
# save result
|
| 31 |
-
|
|
|
|
| 32 |
orig_image = Image.open(im_path)
|
| 33 |
-
no_bg_image =
|
| 34 |
-
no_bg_image.putalpha(pil_mask_im)
|
| 35 |
no_bg_image.save("example_image_no_bg.png")
|
| 36 |
|
| 37 |
|
|
|
|
| 28 |
result_image = postprocess_image(result[0][0], orig_im_size)
|
| 29 |
|
| 30 |
# save result
|
| 31 |
+
pil_im = Image.fromarray(result_image)
|
| 32 |
+
no_bg_image = Image.new("RGBA", pil_im.size, (0,0,0,0))
|
| 33 |
orig_image = Image.open(im_path)
|
| 34 |
+
no_bg_image.paste(orig_image, mask=pil_im)
|
|
|
|
| 35 |
no_bg_image.save("example_image_no_bg.png")
|
| 36 |
|
| 37 |
|