From eee625bef2eb2a9a0a13f9393488c3c51a169458 Mon Sep 17 00:00:00 2001 From: alec-groff <148134052+alec-groff@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:25:00 -0600 Subject: [PATCH 1/4] Update detector_config.py --- frigate/detectors/detector_config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frigate/detectors/detector_config.py b/frigate/detectors/detector_config.py index ca1915449..3103e4aa8 100644 --- a/frigate/detectors/detector_config.py +++ b/frigate/detectors/detector_config.py @@ -51,6 +51,9 @@ class ModelConfig(BaseModel): model_type: ModelTypeEnum = Field( default=ModelTypeEnum.ssd, title="Object Detection Model Type" ) + order: list[int] = Field( + default=[0,1,2,3], title="Order Output Tensors [0=boxes,1=scores,2=class_ids,3=count]" + ) _merged_labelmap: Optional[Dict[int, str]] = PrivateAttr() _colormap: Dict[int, Tuple[int, int, int]] = PrivateAttr() _model_hash: str = PrivateAttr() From df7cdecfdfe32ba4a7684174e0bd71cd84c635d9 Mon Sep 17 00:00:00 2001 From: alec-groff <148134052+alec-groff@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:25:28 -0600 Subject: [PATCH 2/4] Update edgetpu_tfl.py --- frigate/detectors/plugins/edgetpu_tfl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/frigate/detectors/plugins/edgetpu_tfl.py b/frigate/detectors/plugins/edgetpu_tfl.py index ac67626a2..5b3435197 100644 --- a/frigate/detectors/plugins/edgetpu_tfl.py +++ b/frigate/detectors/plugins/edgetpu_tfl.py @@ -44,6 +44,7 @@ class EdgeTpuTfl(DetectionApi): model_path=detector_config.model.path, experimental_delegates=[edge_tpu_delegate], ) + self.order = detector_config.model.order except ValueError: logger.error( "No EdgeTPU was detected. If you do not have a Coral device yet, you must configure CPU detectors." From b1abdc2f8b887bf7d7eaaf4d6f8265b5d1843ce6 Mon Sep 17 00:00:00 2001 From: alec-groff <148134052+alec-groff@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:32:16 -0600 Subject: [PATCH 3/4] Update edgetpu_tfl.py --- frigate/detectors/plugins/edgetpu_tfl.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frigate/detectors/plugins/edgetpu_tfl.py b/frigate/detectors/plugins/edgetpu_tfl.py index 5b3435197..37a9ea7e4 100644 --- a/frigate/detectors/plugins/edgetpu_tfl.py +++ b/frigate/detectors/plugins/edgetpu_tfl.py @@ -60,11 +60,11 @@ class EdgeTpuTfl(DetectionApi): self.interpreter.set_tensor(self.tensor_input_details[0]["index"], tensor_input) self.interpreter.invoke() - boxes = self.interpreter.tensor(self.tensor_output_details[0]["index"])()[0] - class_ids = self.interpreter.tensor(self.tensor_output_details[1]["index"])()[0] - scores = self.interpreter.tensor(self.tensor_output_details[2]["index"])()[0] + boxes = self.interpreter.tensor(self.tensor_output_details[self.order[0]]["index"])()[0] + class_ids = self.interpreter.tensor(self.tensor_output_details[self.order[1]]["index"])()[0] + scores = self.interpreter.tensor(self.tensor_output_details[self.order[2]]["index"])()[0] count = int( - self.interpreter.tensor(self.tensor_output_details[3]["index"])()[0] + self.interpreter.tensor(self.tensor_output_details[self.order[3]]["index"])()[0] ) detections = np.zeros((20, 6), np.float32) From 61a808869ba87cb15ad37a1489720fe3164832fc Mon Sep 17 00:00:00 2001 From: Alec Groff Date: Mon, 29 Jan 2024 09:16:04 -0600 Subject: [PATCH 4/4] modified: frigate/detectors/detector_config.py modified: frigate/detectors/plugins/cpu_tfl.py modified: frigate/detectors/plugins/edgetpu_tfl.py --- frigate/detectors/detector_config.py | 4 ++-- frigate/detectors/plugins/cpu_tfl.py | 10 ++++++---- frigate/detectors/plugins/edgetpu_tfl.py | 10 +++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/frigate/detectors/detector_config.py b/frigate/detectors/detector_config.py index 3103e4aa8..f6317bb3f 100644 --- a/frigate/detectors/detector_config.py +++ b/frigate/detectors/detector_config.py @@ -51,8 +51,8 @@ class ModelConfig(BaseModel): model_type: ModelTypeEnum = Field( default=ModelTypeEnum.ssd, title="Object Detection Model Type" ) - order: list[int] = Field( - default=[0,1,2,3], title="Order Output Tensors [0=boxes,1=scores,2=class_ids,3=count]" + tfl_detector_output_tensor_order: list[int] = Field( + default=[0,1,2,3], title="Order Output Tensors of TFL models [0=boxes,1=scores,2=class_ids,3=count]" ) _merged_labelmap: Optional[Dict[int, str]] = PrivateAttr() _colormap: Dict[int, Tuple[int, int, int]] = PrivateAttr() diff --git a/frigate/detectors/plugins/cpu_tfl.py b/frigate/detectors/plugins/cpu_tfl.py index 8a54363e1..9627494be 100644 --- a/frigate/detectors/plugins/cpu_tfl.py +++ b/frigate/detectors/plugins/cpu_tfl.py @@ -37,15 +37,17 @@ class CpuTfl(DetectionApi): self.tensor_input_details = self.interpreter.get_input_details() self.tensor_output_details = self.interpreter.get_output_details() + self.tfl_detector_output_tensor_order = detector_config.model.tfl_detector_output_tensor_order + def detect_raw(self, tensor_input): self.interpreter.set_tensor(self.tensor_input_details[0]["index"], tensor_input) self.interpreter.invoke() - boxes = self.interpreter.tensor(self.tensor_output_details[0]["index"])()[0] - class_ids = self.interpreter.tensor(self.tensor_output_details[1]["index"])()[0] - scores = self.interpreter.tensor(self.tensor_output_details[2]["index"])()[0] + boxes = self.interpreter.tensor(self.tensor_output_details[self.tfl_detector_output_tensor_order[0]]["index"])()[0] + class_ids = self.interpreter.tensor(self.tensor_output_details[self.tfl_detector_output_tensor_order[1]]["index"])()[0] + scores = self.interpreter.tensor(self.tensor_output_details[self.tfl_detector_output_tensor_order[2]]["index"])()[0] count = int( - self.interpreter.tensor(self.tensor_output_details[3]["index"])()[0] + self.interpreter.tensor(self.tensor_output_details[self.tfl_detector_output_tensor_order[3]]["index"])()[0] ) detections = np.zeros((20, 6), np.float32) diff --git a/frigate/detectors/plugins/edgetpu_tfl.py b/frigate/detectors/plugins/edgetpu_tfl.py index 37a9ea7e4..323b4ae16 100644 --- a/frigate/detectors/plugins/edgetpu_tfl.py +++ b/frigate/detectors/plugins/edgetpu_tfl.py @@ -44,7 +44,7 @@ class EdgeTpuTfl(DetectionApi): model_path=detector_config.model.path, experimental_delegates=[edge_tpu_delegate], ) - self.order = detector_config.model.order + self.tfl_detector_output_tensor_order = detector_config.model.tfl_detector_output_tensor_order except ValueError: logger.error( "No EdgeTPU was detected. If you do not have a Coral device yet, you must configure CPU detectors." @@ -60,11 +60,11 @@ class EdgeTpuTfl(DetectionApi): self.interpreter.set_tensor(self.tensor_input_details[0]["index"], tensor_input) self.interpreter.invoke() - boxes = self.interpreter.tensor(self.tensor_output_details[self.order[0]]["index"])()[0] - class_ids = self.interpreter.tensor(self.tensor_output_details[self.order[1]]["index"])()[0] - scores = self.interpreter.tensor(self.tensor_output_details[self.order[2]]["index"])()[0] + boxes = self.interpreter.tensor(self.tensor_output_details[self.tfl_detector_output_tensor_order[0]]["index"])()[0] + class_ids = self.interpreter.tensor(self.tensor_output_details[self.tfl_detector_output_tensor_order[1]]["index"])()[0] + scores = self.interpreter.tensor(self.tensor_output_details[self.tfl_detector_output_tensor_order[2]]["index"])()[0] count = int( - self.interpreter.tensor(self.tensor_output_details[self.order[3]]["index"])()[0] + self.interpreter.tensor(self.tensor_output_details[self.tfl_detector_output_tensor_order[3]]["index"])()[0] ) detections = np.zeros((20, 6), np.float32)