Code example fix
#23
by
rbgo
- opened
README.md
CHANGED
@@ -105,7 +105,7 @@ Either load the pipeline
|
|
105 |
from transformers import pipeline
|
106 |
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
107 |
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
|
108 |
-
pillow_mask = pipe(
|
109 |
pillow_image = pipe(image_path) # applies mask on input and returns a pillow image
|
110 |
```
|
111 |
|
@@ -137,7 +137,7 @@ model.to(device)
|
|
137 |
|
138 |
# prepare input
|
139 |
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
140 |
-
orig_im = io.imread(
|
141 |
orig_im_size = orig_im.shape[0:2]
|
142 |
image = preprocess_image(orig_im, model_input_size).to(device)
|
143 |
|
@@ -150,7 +150,7 @@ result_image = postprocess_image(result[0][0], orig_im_size)
|
|
150 |
# save result
|
151 |
pil_im = Image.fromarray(result_image)
|
152 |
no_bg_image = Image.new("RGBA", pil_im.size, (0,0,0,0))
|
153 |
-
orig_image = Image.open(
|
154 |
no_bg_image.paste(orig_image, mask=pil_im)
|
155 |
```
|
156 |
|
|
|
105 |
from transformers import pipeline
|
106 |
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
107 |
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
|
108 |
+
pillow_mask = pipe(image_path, return_mask = True) # outputs a pillow mask
|
109 |
pillow_image = pipe(image_path) # applies mask on input and returns a pillow image
|
110 |
```
|
111 |
|
|
|
137 |
|
138 |
# prepare input
|
139 |
image_path = "https://farm5.staticflickr.com/4007/4322154488_997e69e4cf_z.jpg"
|
140 |
+
orig_im = io.imread(image_path)
|
141 |
orig_im_size = orig_im.shape[0:2]
|
142 |
image = preprocess_image(orig_im, model_input_size).to(device)
|
143 |
|
|
|
150 |
# save result
|
151 |
pil_im = Image.fromarray(result_image)
|
152 |
no_bg_image = Image.new("RGBA", pil_im.size, (0,0,0,0))
|
153 |
+
orig_image = Image.open(image_path)
|
154 |
no_bg_image.paste(orig_image, mask=pil_im)
|
155 |
```
|
156 |
|