Commit
·
cd397c1
1
Parent(s):
07a61bc
Update app.py
Browse files
app.py
CHANGED
@@ -52,8 +52,7 @@ def dice_coef(y_true, y_pred, smooth=1):
|
|
52 |
# Load the model
|
53 |
seg_model = tf.keras.models.load_model('seg_unet_model.h5', custom_objects={'Combo_loss': Combo_loss, 'dice_coef': dice_coef})
|
54 |
|
55 |
-
|
56 |
-
inputs = Image.open("./003e2c95d.jpg")
|
57 |
image_output = gr.outputs.Image(type="numpy", label="Output Image")
|
58 |
# outputs = gr.outputs.HTML() #uncomment for single class output
|
59 |
|
@@ -61,13 +60,17 @@ def gen_pred(img=inputs, model=seg_model):
|
|
61 |
# rgb_path = os.path.join(test_image_dir,img)
|
62 |
# img = cv2.imread(rgb_path)
|
63 |
# img = cv2.imread("./003e2c95d.jpg")
|
|
|
|
|
64 |
img = img[::IMG_SCALING[0], ::IMG_SCALING[1]]
|
65 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
66 |
img = img/255
|
67 |
img = tf.expand_dims(img, axis=0)
|
68 |
pred = model.predict(img)
|
69 |
pred = np.squeeze(pred, axis=0)
|
70 |
-
|
|
|
|
|
71 |
|
72 |
|
73 |
title = "<h1 style='text-align: center;'>Semantic Segmentation</h1>"
|
|
|
52 |
# Load the model
|
53 |
seg_model = tf.keras.models.load_model('seg_unet_model.h5', custom_objects={'Combo_loss': Combo_loss, 'dice_coef': dice_coef})
|
54 |
|
55 |
+
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 |
|
|
|
60 |
# rgb_path = os.path.join(test_image_dir,img)
|
61 |
# img = cv2.imread(rgb_path)
|
62 |
# img = cv2.imread("./003e2c95d.jpg")
|
63 |
+
pil_image = PIL.Image.open('./003b50a15.jpg')
|
64 |
+
img = cv2.cvtColor(numpy.array(pil_image), cv2.COLOR_RGB2BGR)
|
65 |
img = img[::IMG_SCALING[0], ::IMG_SCALING[1]]
|
66 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
67 |
img = img/255
|
68 |
img = tf.expand_dims(img, axis=0)
|
69 |
pred = model.predict(img)
|
70 |
pred = np.squeeze(pred, axis=0)
|
71 |
+
color_coverted = cv2.cvtColor(pred, cv2.COLOR_BGR2RGB)
|
72 |
+
pil_image = Image.fromarray(color_coverted)
|
73 |
+
return pil_image
|
74 |
|
75 |
|
76 |
title = "<h1 style='text-align: center;'>Semantic Segmentation</h1>"
|