Commit ·
3f407e8
1
Parent(s): b7e96b9
Allow for multiple objects
Browse files
app.py
CHANGED
|
@@ -13,20 +13,19 @@ from io import BytesIO
|
|
| 13 |
model = Model()
|
| 14 |
|
| 15 |
|
| 16 |
-
def run(image_path, threshold):
|
| 17 |
image = Image.open(image_path).convert('RGB')
|
| 18 |
canvas = Image.new('RGB', image.size, (0, 0, 0))
|
| 19 |
|
| 20 |
# We copy the image that and fill it with black, to get the dimensions
|
| 21 |
rgb = np.array(canvas)
|
| 22 |
-
masks = model(image_path, threshold,
|
| 23 |
|
| 24 |
-
mask
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
img = Image.fromarray(rgb)
|
| 28 |
|
| 29 |
-
return
|
| 30 |
|
| 31 |
|
| 32 |
TITLE = 'MaskCut'
|
|
@@ -42,9 +41,15 @@ demo = gr.Interface(fn=run,
|
|
| 42 |
maximum=1,
|
| 43 |
value=0.15,
|
| 44 |
step=0.01),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
],
|
| 46 |
outputs=gr.Image(label='Output image', type="pil"),
|
| 47 |
-
examples=[[path.as_posix(), 0.15] for path in paths],
|
| 48 |
title=TITLE,
|
| 49 |
description=DESCRIPTION)
|
| 50 |
demo.queue(concurrency_count=3, api_open=True)
|
|
|
|
| 13 |
model = Model()
|
| 14 |
|
| 15 |
|
| 16 |
+
def run(image_path, threshold, num_objects):
|
| 17 |
image = Image.open(image_path).convert('RGB')
|
| 18 |
canvas = Image.new('RGB', image.size, (0, 0, 0))
|
| 19 |
|
| 20 |
# We copy the image that and fill it with black, to get the dimensions
|
| 21 |
rgb = np.array(canvas)
|
| 22 |
+
masks = model(image_path, threshold, num_objects)
|
| 23 |
|
| 24 |
+
for mask in masks:
|
| 25 |
+
fg = mask > 0.5
|
| 26 |
+
rgb[fg] = 255
|
|
|
|
| 27 |
|
| 28 |
+
return Image.fromarray(rgb)
|
| 29 |
|
| 30 |
|
| 31 |
TITLE = 'MaskCut'
|
|
|
|
| 41 |
maximum=1,
|
| 42 |
value=0.15,
|
| 43 |
step=0.01),
|
| 44 |
+
gr.Slider(
|
| 45 |
+
label='Number of objects in the image',
|
| 46 |
+
minimum=1,
|
| 47 |
+
maximum=10,
|
| 48 |
+
value=1,
|
| 49 |
+
step=1)
|
| 50 |
],
|
| 51 |
outputs=gr.Image(label='Output image', type="pil"),
|
| 52 |
+
examples=[[path.as_posix(), 0.15, 2] for path in paths],
|
| 53 |
title=TITLE,
|
| 54 |
description=DESCRIPTION)
|
| 55 |
demo.queue(concurrency_count=3, api_open=True)
|