From 5c7dc99d5ea82234890e0eb002bdc18bf8587811 Mon Sep 17 00:00:00 2001 From: SnuffSocket <82658601+SnuffSocket@users.noreply.github.com> Date: Mon, 7 Oct 2024 02:29:20 +0300 Subject: [PATCH] Fix: Set ONNX Options: Disable telemetry, limit threads, lower CPU usage, potential "memory leak" --- BabbleApp/babble_processor.py | 6 +++++- BabbleApp/landmark_processor.py | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/BabbleApp/babble_processor.py b/BabbleApp/babble_processor.py index 2eddb4c..71d6c96 100644 --- a/BabbleApp/babble_processor.py +++ b/BabbleApp/babble_processor.py @@ -87,9 +87,13 @@ class BabbleProcessor: self.calibrate_config = np.empty((1, 45)) self.min_max_array = np.empty((2, 45)) + ort.disable_telemetry_events() self.opts = ort.SessionOptions() + self.opts.inter_op_num_threads = 1 self.opts.intra_op_num_threads = settings.gui_inference_threads self.opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL + self.opts.add_session_config_entry("session.intra_op.allow_spinning", "0") # ~3% savings worth ~6ms avg latency. Not noticeable at 60fps? + self.opts.enable_mem_pattern = False if self.runtime == "ONNX" or self.runtime == "Default (ONNX)": # ONNX if self.use_gpu: provider = 'DmlExecutionProvider' else: provider = "CPUExecutionProvider" # Build onnxruntime to get both DML and OpenVINO @@ -241,4 +245,4 @@ class BabbleProcessor: self.output_images_and_update(CamInfo(self.current_algo, self.output)) def get_framesize(self): - return self.FRAMESIZE \ No newline at end of file + return self.FRAMESIZE diff --git a/BabbleApp/landmark_processor.py b/BabbleApp/landmark_processor.py index d642a47..4f842cc 100644 --- a/BabbleApp/landmark_processor.py +++ b/BabbleApp/landmark_processor.py @@ -88,10 +88,13 @@ class LandmarkProcessor: #self.calibrate_config = np.empty((1, 45)) #self.min_max_array = np.empty((2, 45)) - + ort.disable_telemetry_events() self.opts = ort.SessionOptions() + self.opts.inter_op_num_threads = 1 self.opts.intra_op_num_threads = settings.gui_inference_threads self.opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL + self.opts.add_session_config_entry("session.intra_op.allow_spinning", "0") # ~3% savings worth ~6ms avg latency. Not noticeable at 60fps? + self.opts.enable_mem_pattern = False if self.runtime == "ONNX" or self.runtime == "Default (ONNX)": # ONNX if self.use_gpu: provider = 'DmlExecutionProvider' else: provider = "CPUExecutionProvider" # Build onnxruntime to get both DML and OpenVINO @@ -219,7 +222,7 @@ class LandmarkProcessor: self.current_image, self.current_frame_number, self.current_fps, - ) = self.capture_queue_incoming.get(block=True, timeout=0.2) + ) = self.capture_queue_incoming.get(block=True, timeout=0.1) except queue.Empty: # print("No image available") continue