dakkoong commited on
Commit
067eb76
·
1 Parent(s): 1f52e1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -88,14 +88,22 @@ def sepia(input_img):
88
  ) # We reverse the shape of `image` because `image.size` returns width and height.
89
  seg = tf.math.argmax(logits, axis=-1)[0]
90
 
91
- # Assuming each label corresponds to a class
92
- class_labels = seg.numpy().flatten().tolist()
 
 
 
93
 
94
- return class_labels
 
 
 
 
 
95
 
96
  demo = gr.Interface(fn=sepia,
97
  inputs=gr.Image(shape=(400, 600)),
98
- outputs=gr.outputs.Label(), # Use Label output type for class labels
99
  examples=["cityoutdoor-1.jpg", "cityoutdoor-2.jpg", "cityoutdoor-3.jpg"],
100
  allow_flagging='never')
101
 
 
88
  ) # We reverse the shape of `image` because `image.size` returns width and height.
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
+ ) # height, width, 3
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
+ fig = draw_plot(pred_img, seg)
102
+ return fig
103
 
104
  demo = gr.Interface(fn=sepia,
105
  inputs=gr.Image(shape=(400, 600)),
106
+ outputs=['plot'],
107
  examples=["cityoutdoor-1.jpg", "cityoutdoor-2.jpg", "cityoutdoor-3.jpg"],
108
  allow_flagging='never')
109