jatamura commited on
Commit
573f3ce
·
verified ·
1 Parent(s): b6fb2a7

Changed name of each render.plot function

Browse files
Files changed (1) hide show
  1. app.py +34 -28
app.py CHANGED
@@ -93,6 +93,37 @@ def server(input, output, session: Session):
93
  # Update reactive value
94
  analysis_results.set(results)
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  @output
97
  @render.ui
98
  def results_container():
@@ -105,40 +136,15 @@ def server(input, output, session: Session):
105
  for i, r in enumerate(results):
106
 
107
  id = "image_" + str(i)
108
- opacity = ui.input_slider(id, "Number of bins", 0, 1.0, 0.5)
109
 
110
- @render.plot
111
- def plot_predicitons():
112
- fig, ax = plt.subplots()
113
-
114
- v = Visualizer(r["image"][:, :, ::-1],
115
- scale=1, instance_mode=ColorMode.SEGMENTATION, font_size_scale=1)
116
-
117
- colours = []
118
- for cls in r["instances"].pred_classes:
119
- if cls == 0:
120
- colours.append([1,0,0])
121
- elif cls == 1:
122
- colours.append([1,1,0])
123
- elif cls == 2:
124
- colours.append([0,0,0])
125
-
126
- out = v.overlay_instances(masks = r["instances"].pred_masks.to("cpu"),
127
- assigned_colors = colours,
128
- alpha = input[id]())
129
- ax.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
130
-
131
- # ax = plt.Axes(fig, [0., 0., 1., 1.])
132
- ax.set_axis_off()
133
- # fig.add_axes(ax)
134
-
135
- return fig
136
 
137
  output.append(
138
  ui.div(
139
  ui.row(
140
  ui.column(4, ui.img(src=f"data:image/png;base64,{r['image_base64']}")),
141
- ui.column(4, ui.output_plot("plot_predicitons")),
142
  ),
143
  opacity,
144
  ui.h5(r['filename'], style="margin-top: 15px;"),
 
93
  # Update reactive value
94
  analysis_results.set(results)
95
 
96
+ def create_plot_function(name, opacity):
97
+ @render.plot
98
+ def plot_predicitons():
99
+ fig, ax = plt.subplots()
100
+
101
+ ax = plt.Axes(fig, [0., 0., 1., 1.])
102
+ ax.set_axis_off()
103
+ fig.add_axes(ax)
104
+
105
+ v = Visualizer(r["image"][:, :, ::-1],
106
+ scale=1, instance_mode=ColorMode.SEGMENTATION, font_size_scale=1)
107
+
108
+ colours = []
109
+ for cls in r["instances"].pred_classes:
110
+ if cls == 0:
111
+ colours.append([1,0,0])
112
+ elif cls == 1:
113
+ colours.append([1,1,0])
114
+ elif cls == 2:
115
+ colours.append([0,0,0])
116
+
117
+ out = v.overlay_instances(masks = r["instances"].pred_masks.to("cpu"),
118
+ assigned_colors = colours,
119
+ alpha = opacity)
120
+ ax.imshow(cv2.cvtColor(out.get_image()[:, :, ::-1], cv2.COLOR_BGR2RGB))
121
+
122
+ return fig
123
+
124
+ plot_prediction.__name__ = name
125
+ return plot_prediction
126
+
127
  @output
128
  @render.ui
129
  def results_container():
 
136
  for i, r in enumerate(results):
137
 
138
  id = "image_" + str(i)
139
+ opacity = ui.input_slider(id, "Opacity", 0, 1.0, 0.5)
140
 
141
+ plot_function = create_plot_function("plot_" + sti(i), input[id]())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ui.column(4, ui.output_plot(plot_function.__name__)),
148
  ),
149
  opacity,
150
  ui.h5(r['filename'], style="margin-top: 15px;"),