Update app.py
Browse files
app.py
CHANGED
@@ -82,24 +82,27 @@ def sepia(input_img):
|
|
82 |
logits = tf.transpose(logits, [0, 2, 3, 1])
|
83 |
logits = tf.image.resize(
|
84 |
logits, input_img.size[::-1]
|
85 |
-
)
|
86 |
seg = tf.math.argmax(logits, axis=-1)[0]
|
87 |
|
88 |
color_seg = np.zeros(
|
89 |
(seg.shape[0], seg.shape[1], 3), dtype=np.uint8
|
90 |
-
)
|
91 |
for label, color in enumerate(colormap):
|
92 |
color_seg[seg.numpy() == label, :] = color
|
93 |
|
94 |
-
#
|
95 |
-
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
# Gradio Interface ์ค์
|
98 |
demo = gr.Interface(fn=sepia,
|
99 |
inputs=gr.Image(shape=(800, 600)),
|
100 |
-
outputs=['
|
101 |
examples=["cityoutdoor-1.jpg", "cityoutdoor-2.jpg", "cityoutdoor-3.jpg"],
|
102 |
allow_flagging='never')
|
103 |
|
104 |
-
|
105 |
demo.launch()
|
|
|
82 |
logits = tf.transpose(logits, [0, 2, 3, 1])
|
83 |
logits = tf.image.resize(
|
84 |
logits, input_img.size[::-1]
|
85 |
+
) # We reverse the shape of `image` because `image.size` returns width and height.
|
86 |
seg = tf.math.argmax(logits, axis=-1)[0]
|
87 |
|
88 |
color_seg = np.zeros(
|
89 |
(seg.shape[0], seg.shape[1], 3), dtype=np.uint8
|
90 |
+
) # height, width, 3
|
91 |
for label, color in enumerate(colormap):
|
92 |
color_seg[seg.numpy() == label, :] = color
|
93 |
|
94 |
+
# Show image + mask
|
95 |
+
pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
|
96 |
+
pred_img = pred_img.astype(np.uint8)
|
97 |
+
|
98 |
+
fig = draw_plot(pred_img, seg)
|
99 |
+
return fig
|
100 |
|
|
|
101 |
demo = gr.Interface(fn=sepia,
|
102 |
inputs=gr.Image(shape=(800, 600)),
|
103 |
+
outputs=['plot'],
|
104 |
examples=["cityoutdoor-1.jpg", "cityoutdoor-2.jpg", "cityoutdoor-3.jpg"],
|
105 |
allow_flagging='never')
|
106 |
|
107 |
+
|
108 |
demo.launch()
|