From f2df550a2ad335053314d3ecc442b4f62a07e090 Mon Sep 17 00:00:00 2001 From: GaryHuang-ASUS Date: Fri, 26 Sep 2025 12:01:00 +0800 Subject: [PATCH] [Update] Update detector script coding format --- frigate/detectors/plugins/synaptics.py | 31 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/frigate/detectors/plugins/synaptics.py b/frigate/detectors/plugins/synaptics.py index 70d972595..7fc877a89 100644 --- a/frigate/detectors/plugins/synaptics.py +++ b/frigate/detectors/plugins/synaptics.py @@ -10,7 +10,11 @@ from synap.preprocessor import Preprocessor from synap.postprocessor import Detector from frigate.detectors.detection_api import DetectionApi -from frigate.detectors.detector_config import BaseDetectorConfig, ModelTypeEnum, InputTensorEnum +from frigate.detectors.detector_config import ( + BaseDetectorConfig, + ModelTypeEnum, + InputTensorEnum, +) logger = logging.getLogger(__name__) @@ -20,6 +24,7 @@ DETECTOR_KEY = "synaptics" class SynapDetectorConfig(BaseDetectorConfig): type: Literal[DETECTOR_KEY] + class SynapDetector(DetectionApi): type_key = DETECTOR_KEY @@ -37,7 +42,8 @@ class SynapDetector(DetectionApi): except Exception as e: logger.error(f"Failed to init Synap NPU: {e}") raise - + + self.width = detector_config.model.width self.height = detector_config.model.height self.model_type = detector_config.model.model_type @@ -52,28 +58,32 @@ class SynapDetector(DetectionApi): def detect_raw(self, tensor_input: np.ndarray): # It has only been testing for pre-converted mobilenet80 .tflite -> .synap model currently layout = Layout.nhwc # default layout + detections = np.zeros((20, 6), np.float32) + if self.input_tensor_layout == InputTensorEnum.nhwc: layout = Layout.nhwc - postprocess_data = self.preprocessor.assign(self.network.inputs, tensor_input, Shape(tensor_input.shape), layout) + postprocess_data = self.preprocessor.assign( + self.network.inputs, tensor_input, Shape(tensor_input.shape), layout + ) output_tensor_obj = self.network.predict() output = self.detector.process(output_tensor_obj, postprocess_data) if self.model_type == ModelTypeEnum.ssd: - detections = np.zeros((20, 6), np.float32) - for i, item in enumerate(output.items): if i == 20: break bb = item.bounding_box - + + # Convert corner coordinates to normalized [0,1] range x1 = bb.origin.x / self.width # Top-left X y1 = bb.origin.y / self.height # Top-left Y x2 = (bb.origin.x + bb.size.x) / self.width # Bottom-right X y2 = (bb.origin.y + bb.size.y) / self.height # Bottom-right Y - + + detections[i] = [ item.class_index, float(item.confidence), @@ -82,9 +92,8 @@ class SynapDetector(DetectionApi): y2, x2, ] - - return detections else: - print(f"Unsupported model type: {self.model_type}") - return np.zeros((20, 6), np.float32) + logger.error(f"Unsupported model type: {self.model_type}") + + return np.zeros((20, 6), np.float32)