diff --git a/BabbleApp/babble_model_loader.py b/BabbleApp/babble_model_loader.py index 1b2bff9..d4e52f2 100644 --- a/BabbleApp/babble_model_loader.py +++ b/BabbleApp/babble_model_loader.py @@ -15,7 +15,7 @@ from one_euro_filter import OneEuroFilter def run_model(self): - if self.runtime == "ONNX" or self.runtime == "Default (ONNX)": + if self.runtime in ("ONNX", "Default (ONNX)"): frame = cv2.resize(self.current_image_gray, (256, 256)) frame = transforms.to_tensor(frame) frame = transforms.unsqueeze(frame, 0) diff --git a/BabbleApp/babble_processor.py b/BabbleApp/babble_processor.py index e7899f8..dfa6935 100644 --- a/BabbleApp/babble_processor.py +++ b/BabbleApp/babble_processor.py @@ -92,7 +92,7 @@ class BabbleProcessor: self.opts = ort.SessionOptions() self.opts.intra_op_num_threads = settings.gui_inference_threads self.opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL - if self.runtime == "ONNX" or self.runtime == "Default (ONNX)": # ONNX + if self.runtime in ("ONNX", "Default (ONNX)"): # ONNX if self.use_gpu: provider = "DmlExecutionProvider" else: diff --git a/BabbleApp/babbleapp.py b/BabbleApp/babbleapp.py index 60fb160..b82b438 100644 --- a/BabbleApp/babbleapp.py +++ b/BabbleApp/babbleapp.py @@ -215,10 +215,10 @@ def main(): # GUI Render loop while True: # First off, check for any events from the GUI - event, values = window.read(timeout=2) + event, values = window.read(timeout=30) # If we're in either mode and someone hits q, quit immediately - if event == "Exit" or event == sg.WIN_CLOSED: + if event in ("Exit", sg.WIN_CLOSED): for ( cam ) in ( diff --git a/BabbleApp/camera_widget.py b/BabbleApp/camera_widget.py index d96bf08..6d76d69 100644 --- a/BabbleApp/camera_widget.py +++ b/BabbleApp/camera_widget.py @@ -63,7 +63,7 @@ class CameraWidget: self.capture_event = Event() self.capture_queue = Queue(maxsize=2) self.roi_queue = Queue(maxsize=2) - self.image_queue = Queue(maxsize=500) + self.image_queue = Queue(maxsize=4) self.babble_cnn = BabbleProcessor( self.config, diff --git a/BabbleApp/config.py b/BabbleApp/config.py index 1275c39..29b8026 100644 --- a/BabbleApp/config.py +++ b/BabbleApp/config.py @@ -91,6 +91,8 @@ class BabbleConfig(BaseModel): BabbleConfig(**json.load(settings_file)) shutil.copy(CONFIG_FILE_NAME, BACKUP_CONFIG_FILE_NAME) # print("Backed up settings files.") # Comment out because it's too loud. + except shutil.SameFileError: + pass except json.JSONDecodeError: # No backup because the saved settings file is broken. pass diff --git a/BabbleApp/general_settings_widget.py b/BabbleApp/general_settings_widget.py index 3e26010..a8e7d7c 100644 --- a/BabbleApp/general_settings_widget.py +++ b/BabbleApp/general_settings_widget.py @@ -336,4 +336,4 @@ class SettingsWidget: if changed: self.main_config.save() - self.osc_queue.put((Tab.SETTINGS)) + self.osc_queue.put(Tab.SETTINGS) diff --git a/BabbleApp/landmark_model_loader.py b/BabbleApp/landmark_model_loader.py index 5f6f8b5..19224c2 100644 --- a/BabbleApp/landmark_model_loader.py +++ b/BabbleApp/landmark_model_loader.py @@ -15,7 +15,7 @@ from one_euro_filter import OneEuroFilter def run_model(self): # Replace transforms n shit for the pfld model - if self.runtime == "ONNX" or self.runtime == "Default (ONNX)": + if self.runtime in ("ONNX", "Default (ONNX)"): frame = cv2.resize(self.current_image_gray, (256, 256)) frame = transforms.to_tensor(frame) frame = transforms.unsqueeze(frame, 0) diff --git a/BabbleApp/landmark_processor.py b/BabbleApp/landmark_processor.py index c23225f..418f16d 100644 --- a/BabbleApp/landmark_processor.py +++ b/BabbleApp/landmark_processor.py @@ -92,8 +92,8 @@ class LandmarkProcessor: self.opts = ort.SessionOptions() self.opts.intra_op_num_threads = settings.gui_inference_threads self.opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL - if self.runtime == "ONNX" or self.runtime == "Default (ONNX)": # ONNX - if self.use_gpu: provider = 'DmlExecutionProvider' + if self.runtime in ("ONNX", "Default (ONNX)"): # ONNX + if self.use_gpu: 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}]) # Load Babble CNN until PFLD has been converted self.input_name = self.sess.get_inputs()[0].name diff --git a/BabbleApp/one_euro_filter.py b/BabbleApp/one_euro_filter.py index 1be193c..30fa923 100644 --- a/BabbleApp/one_euro_filter.py +++ b/BabbleApp/one_euro_filter.py @@ -31,9 +31,7 @@ class OneEuroFilter: t = time() t_e = t - self.t_prev - if ( - t_e != 0.0 - ): # occasionally when switching to algos this becomes zero causing divide by zero errors crashing the filter. + if t_e != 0.0: # occasionally when switching to algos this becomes zero causing divide by zero errors crashing the filter. t_e = np.full(x.shape, t_e) # The filtered derivative of the signal. diff --git a/BabbleApp/osc.py b/BabbleApp/osc.py index aecf786..c0d4cb2 100644 --- a/BabbleApp/osc.py +++ b/BabbleApp/osc.py @@ -100,9 +100,10 @@ class VRChatOSC: return try: (self.cam_id, cam_info) = self.msg_queue.get(block=True, timeout=0.1) - except: + except TypeError: + continue + except queue.Empty: continue - output_osc(cam_info.output, self) @@ -135,7 +136,7 @@ class VRChatOSCReceiver: pass def recalibrate_mouth(self, address, osc_value): - if type(osc_value) != bool: + if not isinstance(osc_value, bool): return # just incase we get anything other than bool if osc_value: for cam in self.cams: diff --git a/BabbleApp/osc_calibrate_filter.py b/BabbleApp/osc_calibrate_filter.py index 2812e82..d3fb6a6 100644 --- a/BabbleApp/osc_calibrate_filter.py +++ b/BabbleApp/osc_calibrate_filter.py @@ -13,6 +13,7 @@ class CamId(IntEnum): class cal: def __init__(self): + self.calibration_frame_counter = None self.calibrated_array = None self.raw_array = None diff --git a/BabbleApp/utils/misc_utils.py b/BabbleApp/utils/misc_utils.py index fa8fc03..7ef2743 100644 --- a/BabbleApp/utils/misc_utils.py +++ b/BabbleApp/utils/misc_utils.py @@ -113,7 +113,7 @@ def list_camera_names(): def list_serial_ports(): - print("DEBUG: Listed Serial Ports") + #print("DEBUG: Listed Serial Ports") """ Lists serial port names :raises EnvironmentError: