Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -107,44 +107,40 @@ def server(input, output, session: Session):
|
|
| 107 |
id = "image_" + str(i)
|
| 108 |
opacity = ui.input_slider(id, "Opacity", 0, 1.0, 0.5)
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
# fig.add_axes(ax)
|
| 118 |
-
|
| 119 |
-
# v = Visualizer(r["image"][:, :, ::-1],
|
| 120 |
-
# scale=1, instance_mode=ColorMode.SEGMENTATION, font_size_scale=1)
|
| 121 |
-
|
| 122 |
-
# colours = []
|
| 123 |
-
# for cls in r["instances"].pred_classes:
|
| 124 |
-
# if cls == 0:
|
| 125 |
-
# colours.append([1,0,0])
|
| 126 |
-
# elif cls == 1:
|
| 127 |
-
# colours.append([1,1,0])
|
| 128 |
-
# elif cls == 2:
|
| 129 |
-
# colours.append([0,0,0])
|
| 130 |
-
|
| 131 |
-
# out = v.overlay_instances(masks = r["instances"].pred_masks.to("cpu"),
|
| 132 |
-
# assigned_colors = colours,
|
| 133 |
-
# alpha = opacity)
|
| 134 |
-
# ax.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
|
| 135 |
-
|
| 136 |
-
# return fig
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
output.append(
|
| 144 |
ui.div(
|
| 145 |
ui.row(
|
| 146 |
ui.column(4, ui.img(src=f"data:image/png;base64,{r['image_base64']}")),
|
| 147 |
-
|
| 148 |
),
|
| 149 |
opacity,
|
| 150 |
ui.h5(r['filename'], style="margin-top: 15px;"),
|
|
|
|
| 107 |
id = "image_" + str(i)
|
| 108 |
opacity = ui.input_slider(id, "Opacity", 0, 1.0, 0.5)
|
| 109 |
|
| 110 |
+
@render.plot
|
| 111 |
+
def plot_predicitons():
|
| 112 |
+
fig, ax = plt.subplots()
|
| 113 |
+
|
| 114 |
+
ax = plt.Axes(fig, [0., 0., 1., 1.])
|
| 115 |
+
ax.set_axis_off()
|
| 116 |
+
fig.add_axes(ax)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
v = Visualizer(r["image"][:, :, ::-1],
|
| 119 |
+
scale=1, instance_mode=ColorMode.SEGMENTATION, font_size_scale=1)
|
| 120 |
+
|
| 121 |
+
colours = []
|
| 122 |
+
for cls in r["instances"].pred_classes:
|
| 123 |
+
if cls == 0:
|
| 124 |
+
colours.append([1,0,0])
|
| 125 |
+
elif cls == 1:
|
| 126 |
+
colours.append([1,1,0])
|
| 127 |
+
elif cls == 2:
|
| 128 |
+
colours.append([0,0,0])
|
| 129 |
+
|
| 130 |
+
out = v.overlay_instances(masks = r["instances"].pred_masks.to("cpu"),
|
| 131 |
+
assigned_colors = colours,
|
| 132 |
+
alpha = opacity)
|
| 133 |
+
ax.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
|
| 134 |
+
|
| 135 |
+
return fig
|
| 136 |
+
|
| 137 |
+
exec("plot_" + str(i) + " = plot_prediction")
|
| 138 |
|
| 139 |
output.append(
|
| 140 |
ui.div(
|
| 141 |
ui.row(
|
| 142 |
ui.column(4, ui.img(src=f"data:image/png;base64,{r['image_base64']}")),
|
| 143 |
+
ui.column(4, ui.output_plot("plot_" + str(i))),
|
| 144 |
),
|
| 145 |
opacity,
|
| 146 |
ui.h5(r['filename'], style="margin-top: 15px;"),
|