andreped commited on
Commit
b6670af
·
unverified ·
2 Parent(s): 4d59d33 8b764f5

Merge pull request #31 from andreped/render-fix

Browse files

Improved renderer speed by only using a single AnnotatedImage

Files changed (3) hide show
  1. .gitignore +2 -0
  2. demo/src/gui.py +22 -18
  3. demo/src/utils.py +2 -2
.gitignore CHANGED
@@ -11,3 +11,5 @@ venv/
11
  *.onnx
12
  *.xml
13
  *.obj
 
 
 
11
  *.onnx
12
  *.xml
13
  *.obj
14
+ *.zip
15
+ *.txt
demo/src/gui.py CHANGED
@@ -20,7 +20,7 @@ class WebUI:
20
  self.pred_images = []
21
 
22
  # @TODO: This should be dynamically set based on chosen volume size
23
- self.nb_slider_items = 415
24
 
25
  self.model_name = model_name
26
  self.cwd = cwd
@@ -39,8 +39,8 @@ class WebUI:
39
 
40
  # define widgets not to be rendered immediantly, but later on
41
  self.slider = gr.Slider(
42
- 1,
43
- self.nb_slider_items,
44
  value=1,
45
  step=1,
46
  label="Which 2D slice to show",
@@ -74,14 +74,19 @@ class WebUI:
74
 
75
  self.images = load_ct_to_numpy(path)
76
  self.pred_images = load_pred_volume_to_numpy("./prediction.nii.gz")
 
77
  return "./prediction.obj"
78
 
79
  def get_img_pred_pair(self, k):
80
- k = int(k) - 1
81
- out = [gr.AnnotatedImage.update(visible=False)] * self.nb_slider_items
82
- out[k] = gr.AnnotatedImage.update(
83
  self.combine_ct_and_seg(self.images[k], self.pred_images[k]),
84
  visible=True,
 
 
 
 
 
85
  )
86
  return out
87
 
@@ -139,20 +144,19 @@ class WebUI:
139
  with gr.Row():
140
  with gr.Box():
141
  with gr.Column():
142
- image_boxes = []
143
- for i in range(self.nb_slider_items):
144
- visibility = True if i == 1 else False
145
- t = gr.AnnotatedImage(
146
- visible=visibility, elem_id="model-2d"
147
- ).style(
148
- color_map={self.class_name: "#ffae00"},
149
- height=512,
150
- width=512,
151
- )
152
- image_boxes.append(t)
153
 
154
  self.slider.input(
155
- self.get_img_pred_pair, self.slider, image_boxes
 
 
156
  )
157
 
158
  self.slider.render()
 
20
  self.pred_images = []
21
 
22
  # @TODO: This should be dynamically set based on chosen volume size
23
+ self.nb_slider_items = 820
24
 
25
  self.model_name = model_name
26
  self.cwd = cwd
 
39
 
40
  # define widgets not to be rendered immediantly, but later on
41
  self.slider = gr.Slider(
42
+ minimum=1,
43
+ maximum=self.nb_slider_items,
44
  value=1,
45
  step=1,
46
  label="Which 2D slice to show",
 
74
 
75
  self.images = load_ct_to_numpy(path)
76
  self.pred_images = load_pred_volume_to_numpy("./prediction.nii.gz")
77
+
78
  return "./prediction.obj"
79
 
80
  def get_img_pred_pair(self, k):
81
+ k = int(k)
82
+ out = gr.AnnotatedImage(
 
83
  self.combine_ct_and_seg(self.images[k], self.pred_images[k]),
84
  visible=True,
85
+ elem_id="model-2d",
86
+ ).style(
87
+ color_map={self.class_name: "#ffae00"},
88
+ height=512,
89
+ width=512,
90
  )
91
  return out
92
 
 
144
  with gr.Row():
145
  with gr.Box():
146
  with gr.Column():
147
+ # create dummy image to be replaced by loaded images
148
+ t = gr.AnnotatedImage(
149
+ visible=True, elem_id="model-2d"
150
+ ).style(
151
+ color_map={self.class_name: "#ffae00"},
152
+ height=512,
153
+ width=512,
154
+ )
 
 
 
155
 
156
  self.slider.input(
157
+ self.get_img_pred_pair,
158
+ self.slider,
159
+ t,
160
  )
161
 
162
  self.slider.render()
demo/src/utils.py CHANGED
@@ -5,7 +5,7 @@ from skimage.measure import marching_cubes
5
 
6
 
7
  def load_ct_to_numpy(data_path):
8
- if type(data_path) != str:
9
  data_path = data_path.name
10
 
11
  image = nib.load(data_path)
@@ -25,7 +25,7 @@ def load_ct_to_numpy(data_path):
25
 
26
 
27
  def load_pred_volume_to_numpy(data_path):
28
- if type(data_path) != str:
29
  data_path = data_path.name
30
 
31
  image = nib.load(data_path)
 
5
 
6
 
7
  def load_ct_to_numpy(data_path):
8
+ if not isinstance(data_path, str):
9
  data_path = data_path.name
10
 
11
  image = nib.load(data_path)
 
25
 
26
 
27
  def load_pred_volume_to_numpy(data_path):
28
+ if not isinstance(data_path, str):
29
  data_path = data_path.name
30
 
31
  image = nib.load(data_path)