Skip to content

Commit

Permalink
Merge pull request #31 from andreped/render-fix
Browse files Browse the repository at this point in the history
Improved renderer speed by only using a single AnnotatedImage
  • Loading branch information
andreped authored Oct 30, 2023
2 parents 4d59d33 + 8b764f5 commit b6670af
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ venv/
*.onnx
*.xml
*.obj
*.zip
*.txt
40 changes: 22 additions & 18 deletions demo/src/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
self.pred_images = []

# @TODO: This should be dynamically set based on chosen volume size
self.nb_slider_items = 415
self.nb_slider_items = 820

self.model_name = model_name
self.cwd = cwd
Expand All @@ -39,8 +39,8 @@ def __init__(

# define widgets not to be rendered immediantly, but later on
self.slider = gr.Slider(
1,
self.nb_slider_items,
minimum=1,
maximum=self.nb_slider_items,
value=1,
step=1,
label="Which 2D slice to show",
Expand Down Expand Up @@ -74,14 +74,19 @@ def process(self, mesh_file_name):

self.images = load_ct_to_numpy(path)
self.pred_images = load_pred_volume_to_numpy("./prediction.nii.gz")

return "./prediction.obj"

def get_img_pred_pair(self, k):
k = int(k) - 1
out = [gr.AnnotatedImage.update(visible=False)] * self.nb_slider_items
out[k] = gr.AnnotatedImage.update(
k = int(k)
out = gr.AnnotatedImage(
self.combine_ct_and_seg(self.images[k], self.pred_images[k]),
visible=True,
elem_id="model-2d",
).style(
color_map={self.class_name: "#ffae00"},
height=512,
width=512,
)
return out

Expand Down Expand Up @@ -139,20 +144,19 @@ def run(self):
with gr.Row():
with gr.Box():
with gr.Column():
image_boxes = []
for i in range(self.nb_slider_items):
visibility = True if i == 1 else False
t = gr.AnnotatedImage(
visible=visibility, elem_id="model-2d"
).style(
color_map={self.class_name: "#ffae00"},
height=512,
width=512,
)
image_boxes.append(t)
# create dummy image to be replaced by loaded images
t = gr.AnnotatedImage(
visible=True, elem_id="model-2d"
).style(
color_map={self.class_name: "#ffae00"},
height=512,
width=512,
)

self.slider.input(
self.get_img_pred_pair, self.slider, image_boxes
self.get_img_pred_pair,
self.slider,
t,
)

self.slider.render()
Expand Down
4 changes: 2 additions & 2 deletions demo/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def load_ct_to_numpy(data_path):
if type(data_path) != str:
if not isinstance(data_path, str):
data_path = data_path.name

image = nib.load(data_path)
Expand All @@ -25,7 +25,7 @@ def load_ct_to_numpy(data_path):


def load_pred_volume_to_numpy(data_path):
if type(data_path) != str:
if not isinstance(data_path, str):
data_path = data_path.name

image = nib.load(data_path)
Expand Down

0 comments on commit b6670af

Please sign in to comment.