SeoJunn commited on
Commit
25313d8
1 Parent(s): 4777956

Refactor : 오류 위험이 있는 코드 전부 제거

Browse files
Files changed (1) hide show
  1. app.py +24 -29
app.py CHANGED
@@ -131,26 +131,24 @@ def sepia(inputs, button_text):
131
  # plt.axis("off")
132
  # return fig
133
 
134
- if button_text == "segmentation":
135
- inputs_segmentation = feature_extractor(images=input_img, return_tensors="tf")
136
- outputs_segmentation = model_segmentation(**inputs_segmentation)
137
- logits_segmentation = outputs_segmentation.logits
138
 
139
- logits_segmentation = tf.transpose(logits_segmentation, [0, 2, 3, 1])
140
- logits_segmentation = tf.image.resize(logits_segmentation, input_img.size[::-1])
141
- seg = tf.math.argmax(logits_segmentation, axis=-1)[0]
142
 
143
- color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8)
144
- for label, color in enumerate(colormap):
145
- color_seg[seg.numpy() == label, :] = color
146
 
147
- pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
148
- pred_img = pred_img.astype(np.uint8)
 
 
 
149
 
150
- fig = draw_plot(pred_img, seg)
151
- return fig
152
-
153
- return "Please select 'detection' or 'segmentation'."
154
 
155
  def on_button_click(inputs):
156
  """버튼 클릭 이벤트 핸들러"""
@@ -166,18 +164,15 @@ dropdown = gr.Dropdown(
166
  ["segmentation"], label="Menu", info="Chose Segmentation!"
167
  )
168
 
169
- demo = gr.Interface(
170
- fn=sepia,
171
- inputs=[gr.Image(shape=(400, 600))],
172
- outputs=["plot"],
173
- examples=[
174
- ["01.jpg", "1"],
175
- ["02.jpeg", "2"],
176
- ["03.jpeg", "3"],
177
- ["04.jpeg", "4"],
178
- ],
179
- allow_flagging="never",
180
- )
181
-
182
 
183
  demo.launch()
 
131
  # plt.axis("off")
132
  # return fig
133
 
134
+ inputs_segmentation = feature_extractor(images=input_img, return_tensors="tf")
135
+ outputs_segmentation = model_segmentation(**inputs_segmentation)
136
+ logits_segmentation = outputs_segmentation.logits
 
137
 
138
+ logits_segmentation = tf.transpose(logits_segmentation, [0, 2, 3, 1])
139
+ logits_segmentation = tf.image.resize(logits_segmentation, input_img.size[::-1])
140
+ seg = tf.math.argmax(logits_segmentation, axis=-1)[0]
141
 
142
+ color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8)
143
+ for label, color in enumerate(colormap):
144
+ color_seg[seg.numpy() == label, :] = color
145
 
146
+ pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
147
+ pred_img = pred_img.astype(np.uint8)
148
+
149
+ fig = draw_plot(pred_img, seg)
150
+ return fig
151
 
 
 
 
 
152
 
153
  def on_button_click(inputs):
154
  """버튼 클릭 이벤트 핸들러"""
 
164
  ["segmentation"], label="Menu", info="Chose Segmentation!"
165
  )
166
 
167
+ demo = gr.Interface(fn=sepia,
168
+ inputs=[gr.Image(shape=(400, 600)), dropdown],
169
+ outputs=["plot"],
170
+ examples= [
171
+ ["01.jpg", "1"],
172
+ ["02.jpeg", "2"],
173
+ ["03.jpeg", "3"],
174
+ ["04.jpeg", "4"],
175
+ ],
176
+ allow_flagging="never",)
 
 
 
177
 
178
  demo.launch()