Spaces:
Runtime error
Runtime error
finish
Browse files
app.py
CHANGED
|
@@ -66,6 +66,8 @@ def draw_plot(pred_img, seg):
|
|
| 66 |
plt.subplot(grid_spec[0])
|
| 67 |
plt.imshow(pred_img)
|
| 68 |
plt.axis('off')
|
|
|
|
|
|
|
| 69 |
LABEL_NAMES = np.asarray(labels_list)
|
| 70 |
FULL_LABEL_MAP = np.arange(len(LABEL_NAMES)).reshape(len(LABEL_NAMES), 1)
|
| 71 |
FULL_COLOR_MAP = label_to_color_image(FULL_LABEL_MAP)
|
|
@@ -77,6 +79,17 @@ def draw_plot(pred_img, seg):
|
|
| 77 |
plt.yticks(range(len(unique_labels)), LABEL_NAMES[unique_labels])
|
| 78 |
plt.xticks([], [])
|
| 79 |
ax.tick_params(width=0.0, labelsize=25)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
return fig
|
| 81 |
|
| 82 |
|
|
@@ -91,7 +104,6 @@ def sepia(input_img):
|
|
| 91 |
logits, input_img.size[::-1]
|
| 92 |
) # We reverse the shape of `image` because `image.size` returns width and height.
|
| 93 |
seg = tf.math.argmax(logits, axis=-1)[0]
|
| 94 |
-
|
| 95 |
color_seg = np.zeros(
|
| 96 |
(seg.shape[0], seg.shape[1], 3), dtype=np.uint8
|
| 97 |
) # height, width, 3
|
|
@@ -108,7 +120,7 @@ def sepia(input_img):
|
|
| 108 |
|
| 109 |
demo = gr.Interface(fn=sepia,
|
| 110 |
inputs=gr.Image(shape=(1024, 1024)),
|
| 111 |
-
outputs=['plot'
|
| 112 |
examples=["city-1.jpg", "city-2.jpg", "city-3.jpg", "city-4.jpg", "city-5.jpg"],
|
| 113 |
allow_flagging='never')
|
| 114 |
|
|
|
|
| 66 |
plt.subplot(grid_spec[0])
|
| 67 |
plt.imshow(pred_img)
|
| 68 |
plt.axis('off')
|
| 69 |
+
|
| 70 |
+
# 라벨 이름을 추가하기 위한 코드
|
| 71 |
LABEL_NAMES = np.asarray(labels_list)
|
| 72 |
FULL_LABEL_MAP = np.arange(len(LABEL_NAMES)).reshape(len(LABEL_NAMES), 1)
|
| 73 |
FULL_COLOR_MAP = label_to_color_image(FULL_LABEL_MAP)
|
|
|
|
| 79 |
plt.yticks(range(len(unique_labels)), LABEL_NAMES[unique_labels])
|
| 80 |
plt.xticks([], [])
|
| 81 |
ax.tick_params(width=0.0, labelsize=25)
|
| 82 |
+
|
| 83 |
+
# 라벨 이름 텍스트 추가
|
| 84 |
+
for label, color in enumerate(colormap):
|
| 85 |
+
mask = seg.numpy() == label
|
| 86 |
+
if np.any(mask):
|
| 87 |
+
y, x = np.where(mask)
|
| 88 |
+
y = np.mean(y).astype(int)
|
| 89 |
+
x = np.mean(x).astype(int)
|
| 90 |
+
label_name = LABEL_NAMES[label]
|
| 91 |
+
plt.text(x, y, label_name, fontsize=20, color=tuple(color))
|
| 92 |
+
|
| 93 |
return fig
|
| 94 |
|
| 95 |
|
|
|
|
| 104 |
logits, input_img.size[::-1]
|
| 105 |
) # We reverse the shape of `image` because `image.size` returns width and height.
|
| 106 |
seg = tf.math.argmax(logits, axis=-1)[0]
|
|
|
|
| 107 |
color_seg = np.zeros(
|
| 108 |
(seg.shape[0], seg.shape[1], 3), dtype=np.uint8
|
| 109 |
) # height, width, 3
|
|
|
|
| 120 |
|
| 121 |
demo = gr.Interface(fn=sepia,
|
| 122 |
inputs=gr.Image(shape=(1024, 1024)),
|
| 123 |
+
outputs=['plot'],
|
| 124 |
examples=["city-1.jpg", "city-2.jpg", "city-3.jpg", "city-4.jpg", "city-5.jpg"],
|
| 125 |
allow_flagging='never')
|
| 126 |
|