DiGuaQiu commited on
Commit
243d214
1 Parent(s): e1e89c3

Decrease workload on CPUs

Browse files
Files changed (1) hide show
  1. app.py +4 -11
app.py CHANGED
@@ -72,9 +72,10 @@ def save_file(segmentation, path):
72
  def infer(image_path):
73
  with tempfile.TemporaryDirectory() as tmpdirname:
74
 
75
- inference.infer(
76
- [image_path], tmpdirname, [0, 1, 2, 3, 4], cpu_only=False if torch.cuda.is_available() else True
77
- )
 
78
  filename = add_postfix(Path(image_path).name, "seg")
79
  segmentation = sitk.ReadImage(tmpdirname + "/" + filename)
80
 
@@ -124,13 +125,6 @@ with gr.Blocks(css=css, title="MRSegmentator") as iface:
124
  with gr.Column():
125
  overlay_image_np = gr.AnnotatedImage(label="Axial View")
126
 
127
- # pred_dict = gr.Label(label="Prediction")
128
- # explanation= gr.Textbox(label="Classification Decision")
129
-
130
- # with gr.Accordion("Additional Information", open=False):
131
- # gradcam = gr.Image(label="GradCAM")
132
- # cropped_boxed_array_disp = gr.Image(label="Bounding Box")
133
-
134
  input_file.change(
135
  utils.read_and_display,
136
  inputs=[input_file, image_state, seg_state],
@@ -149,5 +143,4 @@ with gr.Blocks(css=css, title="MRSegmentator") as iface:
149
 
150
  if __name__ == "__main__":
151
  iface.queue()
152
- # iface.launch(server_name='0.0.0.0', server_port=8080)
153
  iface.launch()
 
72
  def infer(image_path):
73
  with tempfile.TemporaryDirectory() as tmpdirname:
74
 
75
+ if torch.cuda.is_available():
76
+ inference.infer([image_path], tmpdirname, [0, 1, 2, 3, 4], cpu_only=False, split_level=1)
77
+ else:
78
+ inference.infer([image_path], tmpdirname, [0], cpu_only=True, split_level=1)
79
  filename = add_postfix(Path(image_path).name, "seg")
80
  segmentation = sitk.ReadImage(tmpdirname + "/" + filename)
81
 
 
125
  with gr.Column():
126
  overlay_image_np = gr.AnnotatedImage(label="Axial View")
127
 
 
 
 
 
 
 
 
128
  input_file.change(
129
  utils.read_and_display,
130
  inputs=[input_file, image_state, seg_state],
 
143
 
144
  if __name__ == "__main__":
145
  iface.queue()
 
146
  iface.launch()