Spaces:
Runtime error
Runtime error
Refactor : 오류 위험이 있는 코드 전부 제거
Browse files
app.py
CHANGED
|
@@ -131,26 +131,24 @@ def sepia(inputs, button_text):
|
|
| 131 |
# plt.axis("off")
|
| 132 |
# return fig
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
logits_segmentation = outputs_segmentation.logits
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 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()
|