Commit ·
7e182e3
1
Parent(s): 14f2a96
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,6 +56,16 @@ inputs = gr.inputs.Image(type="pil", label="Upload an image", source="upload")
|
|
| 56 |
image_output = gr.outputs.Image(type="numpy", label="Output Image")
|
| 57 |
# outputs = gr.outputs.HTML() #uncomment for single class output
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def gen_pred(img=inputs, model=seg_model):
|
| 60 |
# rgb_path = os.path.join(test_image_dir,img)
|
| 61 |
# img = cv2.imread(rgb_path)
|
|
@@ -69,11 +79,12 @@ def gen_pred(img=inputs, model=seg_model):
|
|
| 69 |
pred = model.predict(img)
|
| 70 |
pred = np.squeeze(pred, axis=0)
|
| 71 |
print(pred)
|
|
|
|
| 72 |
# color_coverted = cv2.cvtColor(pred, cv2.COLOR_BGR2RGB)
|
| 73 |
# pil_image = Image.fromarray(pred)
|
| 74 |
-
PIL_image = Image.fromarray(pred.astype('uint8'), 'RGB')
|
| 75 |
# return "UI in developing process ..."
|
| 76 |
-
return
|
| 77 |
|
| 78 |
title = "<h1 style='text-align: center;'>Semantic Segmentation</h1>"
|
| 79 |
description = "Upload an image and get prediction mask"
|
|
|
|
| 56 |
image_output = gr.outputs.Image(type="numpy", label="Output Image")
|
| 57 |
# outputs = gr.outputs.HTML() #uncomment for single class output
|
| 58 |
|
| 59 |
+
def fig2img(fig):
|
| 60 |
+
"""Convert a Matplotlib figure to a PIL Image and return it"""
|
| 61 |
+
import io
|
| 62 |
+
buf = io.BytesIO()
|
| 63 |
+
fig.savefig(buf)
|
| 64 |
+
buf.seek(0)
|
| 65 |
+
img = Image.open(buf)
|
| 66 |
+
return img
|
| 67 |
+
|
| 68 |
+
|
| 69 |
def gen_pred(img=inputs, model=seg_model):
|
| 70 |
# rgb_path = os.path.join(test_image_dir,img)
|
| 71 |
# img = cv2.imread(rgb_path)
|
|
|
|
| 79 |
pred = model.predict(img)
|
| 80 |
pred = np.squeeze(pred, axis=0)
|
| 81 |
print(pred)
|
| 82 |
+
pred = fig2img(pred)
|
| 83 |
# color_coverted = cv2.cvtColor(pred, cv2.COLOR_BGR2RGB)
|
| 84 |
# pil_image = Image.fromarray(pred)
|
| 85 |
+
# PIL_image = Image.fromarray(pred.astype('uint8'), 'RGB')
|
| 86 |
# return "UI in developing process ..."
|
| 87 |
+
return pred
|
| 88 |
|
| 89 |
title = "<h1 style='text-align: center;'>Semantic Segmentation</h1>"
|
| 90 |
description = "Upload an image and get prediction mask"
|