From 834b46942b61bd1c8603f142f3849e1f6dd88b73 Mon Sep 17 00:00:00 2001 From: Rames The Generic Date: Sat, 9 Nov 2024 16:07:46 -0500 Subject: [PATCH] Fix crash on model load and version increment App will now load the default model and alert the user when an incorrect file path is specified rather than crashing on startup. Incremented the version number from 2.0.6 Alpha to 2.1.0 Beta --- BabbleApp/Locale/English/locale.json | 1 + "BabbleApp/Locale/Espa\303\261ol/locale.json" | 1 + BabbleApp/Locale/OwO/locale.json | 1 + BabbleApp/Locale/Pirate Speak/locale.json | 1 + BabbleApp/algo_settings_widget.py | 1 + BabbleApp/babble_processor.py | 26 ++++++++++++++----- BabbleApp/babbleapp.py | 2 +- BabbleApp/config.py | 2 +- 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/BabbleApp/Locale/English/locale.json b/BabbleApp/Locale/English/locale.json index 70233d3..3e29034 100644 --- a/BabbleApp/Locale/English/locale.json +++ b/BabbleApp/Locale/English/locale.json @@ -37,6 +37,7 @@ "error.size": "Size of frames to display are of unequal sizes", "error.capture": "Frame capture issue detected", "error.winmm": "Failed to load winmm", + "error.modelLoad": "Failed to load model:", "warn.frameDrop": "Frame drop. Corrupted JPEG", "warn.captureProblem": "Capture source problem, assuming camera disconnected, waiting for reconnect", "warn.serialCapture": "Serial capture source problem, assuming camera disconnected, waiting for reconnect", diff --git "a/BabbleApp/Locale/Espa\303\261ol/locale.json" "b/BabbleApp/Locale/Espa\303\261ol/locale.json" index dca5330..20693f9 100644 --- "a/BabbleApp/Locale/Espa\303\261ol/locale.json" +++ "b/BabbleApp/Locale/Espa\303\261ol/locale.json" @@ -37,6 +37,7 @@ "error.size": "Los tamaños de los fotogramas para mostrar son de dimensiones desiguales", "error.capture": "Detectado problema en la captura de fotogramas", "error.winmm": "Error al cargar winmm", + "error.modelLoad": "Error al cargar Modelo:", "warn.frameDrop": "Pérdida de fotogramas. JPEG dañado", "warn.captureProblem": "Problema con la fuente de captura, se asume que la cámara está desconectada, esperando reconexión", "warn.serialCapture": "Problema con la fuente de captura en serie, se asume que la cámara está desconectada, esperando reconexión", diff --git a/BabbleApp/Locale/OwO/locale.json b/BabbleApp/Locale/OwO/locale.json index 1995b33..272da82 100644 --- a/BabbleApp/Locale/OwO/locale.json +++ b/BabbleApp/Locale/OwO/locale.json @@ -37,6 +37,7 @@ "error.size": "Size of frames to display are of unequal sizes", "error.capture": "Frame capture issue detected", "error.winmmDll": "Failed to load winmm", + "error.modelLoad": "Failed to load model:", "warn.frameDrop": "Frame drop. Corrupted JPEG", "warn.captureProblem": "Capture source problem, assuming camera disconnected, waiting for reconnect", "warn.serialCapture": "Serial capture source problem, assuming camera disconnected, waiting for reconnect", diff --git a/BabbleApp/Locale/Pirate Speak/locale.json b/BabbleApp/Locale/Pirate Speak/locale.json index 280b5de..f2b627f 100644 --- a/BabbleApp/Locale/Pirate Speak/locale.json +++ b/BabbleApp/Locale/Pirate Speak/locale.json @@ -37,6 +37,7 @@ "error.size": "Size of frames to display are of unequal sizes", "error.capture": "Frame capture issue detected", "error.winmmDll": "Failed to load winmm", + "error.modelLoad": "Failed to load mdoel:", "warn.frameDrop": "Frame drop. Corrupted JPEG", "warn.captureProblem": "Capture source problem, assuming camera disconnected, waiting for reconnect", "warn.serialCapture": "Serial capture source problem, assuming camera disconnected, waiting for reconnect", diff --git a/BabbleApp/algo_settings_widget.py b/BabbleApp/algo_settings_widget.py index 79bb344..a7d8932 100644 --- a/BabbleApp/algo_settings_widget.py +++ b/BabbleApp/algo_settings_widget.py @@ -41,6 +41,7 @@ def __init__( size=(32), tooltip=f'{lang._instance.get_string("algorithm.modelFileTooptip")}.', ), + sg.FolderBrowse(), sg.Text( f'{lang._instance.get_string("algorithm.inferenceThreads")}:', background_color=bg_color_highlight, diff --git a/BabbleApp/babble_processor.py b/BabbleApp/babble_processor.py index 3e3a533..68a36e5 100644 --- a/BabbleApp/babble_processor.py +++ b/BabbleApp/babble_processor.py @@ -86,6 +86,8 @@ def __init__( self.runtime = self.settings.gui_runtime self.use_gpu = self.settings.gui_use_gpu self.gpu_index = self.settings.gui_gpu_index + config_default: BabbleConfig = BabbleConfig() + self.default_model = config_default.settings.gui_model_file self.output = [] self.val_list = [] self.calibrate_config = np.empty((1, 45)) @@ -103,12 +105,24 @@ def __init__( provider = "DmlExecutionProvider" else: provider = "CPUExecutionProvider" # Build onnxruntime to get both DML and OpenVINO - self.sess = ort.InferenceSession( - f"{self.model}onnx/model.onnx", - self.opts, - providers=[provider], - provider_options=[{"device_id": self.gpu_index}], - ) + try: + self.sess = ort.InferenceSession( + f"{self.model}/onnx/model.onnx", + self.opts, + providers=[provider], + provider_options=[{"device_id": self.gpu_index}], + ) + except: # Load default model if we can't find the specified model + print( + f'\033[91m[{lang._instance.get_string("log.error")}] {lang._instance.get_string("error.modelLoad")} {self.model}\033[0m' + ) + print(f'\033[91mLoading Default model: {self.default_model}.\033[0m') + self.sess = ort.InferenceSession( + f"{self.default_model}/onnx/model.onnx", + self.opts, + providers=[provider], + provider_options=[{"device_id": self.gpu_index}], + ) self.input_name = self.sess.get_inputs()[0].name self.output_name = self.sess.get_outputs()[0].name try: diff --git a/BabbleApp/babbleapp.py b/BabbleApp/babbleapp.py index 9bec103..18e2587 100644 --- a/BabbleApp/babbleapp.py +++ b/BabbleApp/babbleapp.py @@ -58,7 +58,7 @@ CALIB_SETTINGS_RADIO_NAME = "-CALIBSETTINGSRADIO-" page_url = "https://github.com/SummerSigh/ProjectBabble/releases/latest" -appversion = "Babble v2.0.6 Alpha" +appversion = "Babble v2.1.0 Beta" def timerResolution(toggle): if winmm != None: diff --git a/BabbleApp/config.py b/BabbleApp/config.py index 29b8026..302368e 100644 --- a/BabbleApp/config.py +++ b/BabbleApp/config.py @@ -35,7 +35,7 @@ class BabbleSettingsConfig(BaseModel): gui_ROSC: bool = False gui_osc_location: str = "" gui_multiply: float = 1 - gui_model_file: str = "Models/3MEFFB0E7MSE/" + gui_model_file: str = "Models/3MEFFB0E7MSE" gui_runtime: str = "ONNX" gui_use_gpu: bool = False gui_gpu_index: int = 0