dakkoong commited on
Commit
3c6c6ea
ยท
1 Parent(s): 0f79e23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -1,7 +1,4 @@
1
  import gradio as gr
2
-
3
- from matplotlib import gridspec
4
- import matplotlib.pyplot as plt
5
  import numpy as np
6
  from PIL import Image
7
  import tensorflow as tf
@@ -85,27 +82,24 @@ 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
- ) # 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=(800, 600)),
106
- outputs=['label'],
107
  examples=["cityoutdoor-1.jpg", "cityoutdoor-2.jpg", "cityoutdoor-3.jpg"],
108
  allow_flagging='never')
109
 
110
-
111
- demo.launch()
 
1
  import gradio as gr
 
 
 
2
  import numpy as np
3
  from PIL import Image
4
  import tensorflow as tf
 
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
+ # Return segmentation label image instead of Matplotlib Figure
95
+ return color_seg
 
 
 
 
96
 
97
+ # Gradio Interface ์„ค์ •
98
  demo = gr.Interface(fn=sepia,
99
  inputs=gr.Image(shape=(800, 600)),
100
+ outputs=['label'], # 'plot'์—์„œ 'label'๋กœ ๋ณ€๊ฒฝ
101
  examples=["cityoutdoor-1.jpg", "cityoutdoor-2.jpg", "cityoutdoor-3.jpg"],
102
  allow_flagging='never')
103
 
104
+ # Gradio ์‹คํ–‰
105
+ demo.launch()