@@ -119,7 +119,7 @@ def warn(self, warning):
119119 """Sends a warning to main thread"""
120120 self .warn_signal .emit (warning )
121121
122- def raise_error (self , exception , msg ):
122+ def _raise_error (self , exception , msg ):
123123 """Raises an error in main thread"""
124124 logger .error (msg , exc_info = True )
125125 logger .error (exception , exc_info = True )
@@ -131,8 +131,8 @@ def raise_error(self, exception, msg):
131131
132132 self .error_signal .emit (exception , msg )
133133 self .errored .emit (exception )
134+ self .quit ()
134135 yield exception
135- # self.quit()
136136
137137 def log_parameters (self ):
138138 config = self .config
@@ -334,7 +334,8 @@ def model_output_wrapper(inputs):
334334 except Exception as e :
335335 logger .exception (e )
336336 logger .debug ("failed to run sliding window inference" )
337- self .raise_error (e , "Error during sliding window inference" )
337+ self ._raise_error (e , "Error during sliding window inference" )
338+ # raise e
338339 logger .debug (f"Inference output shape: { outputs .shape } " )
339340
340341 self .log ("Post-processing..." )
@@ -346,7 +347,8 @@ def model_output_wrapper(inputs):
346347 return out
347348 except Exception as e :
348349 logger .exception (e )
349- self .raise_error (e , "Error during sliding window inference" )
350+ self ._raise_error (e , "Error during sliding window inference" )
351+ # raise e
350352 # sys.stdout = old_stdout
351353 # sys.stderr = old_stderr
352354
@@ -437,7 +439,7 @@ def save_image(
437439 try :
438440 imwrite (file_path , image )
439441 except ValueError as e :
440- self . raise_error ( e , "Error during image saving" )
442+ raise e
441443 filename = Path (file_path ).stem
442444
443445 if from_layer :
@@ -595,7 +597,7 @@ def inference_on_layer(self, image, model, post_process_transforms):
595597 stats = stats ,
596598 )
597599
598- # @thread_worker(connect={"errored": self.raise_error })
600+ # @thread_worker(connect={"errored": self._raise_error })
599601 def inference (self ):
600602 """
601603 Requires:
@@ -659,10 +661,10 @@ def inference(self):
659661 # device=self.config.device,
660662 num_classes = self .config .model_info .num_classes ,
661663 )
662- # try:
663- model = model .to (self .config .device )
664- # except Exception as e:
665- # self.raise_error (e, "Issue loading model to device")
664+ try :
665+ model = model .to (self .config .device )
666+ except RuntimeError as e :
667+ self ._raise_error (e , "Issue loading model to device" )
666668 # logger.debug(f"model : {model}")
667669 if model is None :
668670 raise ValueError ("Model is None" )
@@ -687,13 +689,14 @@ def inference(self):
687689 strict = True ,
688690 )
689691 self .log (f"Weights status : { missing } " )
690- except RuntimeError as e :
691- self .raise_error (e , "Error when loading weights" )
692+ except Exception as e :
693+ self ._raise_error (e , "Error when loading weights" )
694+ return None
692695 self .log ("Done" )
693696 # except Exception as e:
694- # self.raise_error (e, "Issue loading weights")
697+ # self._raise_error (e, "Issue loading weights")
695698 # except Exception as e:
696- # self.raise_error (e, "Issue instantiating model")
699+ # self._raise_error (e, "Issue instantiating model")
697700
698701 # if model_name == "SegResNet":
699702 # model = model_class(
@@ -779,11 +782,11 @@ def inference(self):
779782 yield self .inference_on_layer (
780783 input_image , model , post_process_transforms
781784 )
785+
782786 model .to ("cpu" )
783787 # self.quit()
784788 except Exception as e :
785789 logger .exception (e )
786- self .raise_error (e , "Inference failed" )
787- self .quit ()
790+ self ._raise_error (e , "Inference failed" )
788791 finally :
789792 self .quit ()
0 commit comments