Spaces:
Sleeping
Sleeping
GoBoKyung
commited on
Commit
·
809f88d
1
Parent(s):
385ad10
city
Browse files
app.py
CHANGED
@@ -85,27 +85,25 @@ def sepia(input_img):
|
|
85 |
logits = tf.transpose(logits, [0, 2, 3, 1])
|
86 |
logits = tf.image.resize(
|
87 |
logits, input_img.size[::-1]
|
88 |
-
)
|
89 |
seg = tf.math.argmax(logits, axis=-1)[0]
|
90 |
|
91 |
color_seg = np.zeros(
|
92 |
(seg.shape[0], seg.shape[1], 3), dtype=np.uint8
|
93 |
-
)
|
|
|
94 |
for label, color in enumerate(colormap):
|
95 |
color_seg[seg.numpy() == label, :] = color
|
96 |
|
97 |
-
# Show image + mask
|
98 |
pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
|
99 |
pred_img = pred_img.astype(np.uint8)
|
100 |
|
101 |
-
|
102 |
-
return fig
|
103 |
|
104 |
demo = gr.Interface(fn=sepia,
|
105 |
-
inputs=gr.Image(
|
106 |
-
outputs=
|
107 |
examples=["img_1.jpg", "img_2.jpeg", "img_3.jpg", "img_4.jpg", "img_5.png"],
|
108 |
allow_flagging='never')
|
109 |
|
110 |
-
|
111 |
-
demo.launch()
|
|
|
85 |
logits = tf.transpose(logits, [0, 2, 3, 1])
|
86 |
logits = tf.image.resize(
|
87 |
logits, input_img.size[::-1]
|
88 |
+
)
|
89 |
seg = tf.math.argmax(logits, axis=-1)[0]
|
90 |
|
91 |
color_seg = np.zeros(
|
92 |
(seg.shape[0], seg.shape[1], 3), dtype=np.uint8
|
93 |
+
)
|
94 |
+
|
95 |
for label, color in enumerate(colormap):
|
96 |
color_seg[seg.numpy() == label, :] = color
|
97 |
|
|
|
98 |
pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
|
99 |
pred_img = pred_img.astype(np.uint8)
|
100 |
|
101 |
+
return pred_img # Return the segmented image directly
|
|
|
102 |
|
103 |
demo = gr.Interface(fn=sepia,
|
104 |
+
inputs=gr.Image(type="pil", label="Upload an Image"),
|
105 |
+
outputs=gr.Image(type="pil", label="Segmented Image"),
|
106 |
examples=["img_1.jpg", "img_2.jpeg", "img_3.jpg", "img_4.jpg", "img_5.png"],
|
107 |
allow_flagging='never')
|
108 |
|
109 |
+
demo.launch()
|
|