From f39c2baa94d6d62d528e95df727bcdd82f255115 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Mon, 8 May 2023 05:14:03 +0300 Subject: [PATCH] code formatiing --- frigate/detectors/plugins/mediapipe.py | 29 +++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/frigate/detectors/plugins/mediapipe.py b/frigate/detectors/plugins/mediapipe.py index c1e9f9dbb..15c160288 100644 --- a/frigate/detectors/plugins/mediapipe.py +++ b/frigate/detectors/plugins/mediapipe.py @@ -16,24 +16,28 @@ logger = logging.getLogger(__name__) DETECTOR_KEY = "mediapipe" + class MediapipeDetectorConfig(BaseDetectorConfig): type: Literal[DETECTOR_KEY] - #num_threads: int = Field(default=3, title="Number of detection threads") + class Mediapipe(DetectionApi): type_key = DETECTOR_KEY def __init__(self, detector_config: MediapipeDetectorConfig): base_options = python.BaseOptions(model_asset_path=detector_config.model.path) - options = vision.ObjectDetectorOptions(base_options=base_options, - score_threshold=0.5) + options = vision.ObjectDetectorOptions( + base_options=base_options, score_threshold=0.5 + ) self.detector = vision.ObjectDetector.create_from_options(options) self.labels = detector_config.model.merged_labelmap self.h = detector_config.model.height self.w = detector_config.model.width - logger.debug(f"Detection started. Model: {detector_config.model.path}, h: {self.h}, w: {self.w}") - + logger.debug( + f"Detection started. Model: {detector_config.model.path}, h: {self.h}, w: {self.w}" + ) + def get_label_index(self, label_value): if label_value.lower() == "truck": label_value = "car" @@ -41,7 +45,7 @@ class Mediapipe(DetectionApi): if value == label_value.lower(): return index return -1 - + def detect_raw(self, tensor_input): # STEP 3: Load the input image. image_data = np.squeeze(tensor_input).astype(np.uint8) @@ -56,8 +60,10 @@ class Mediapipe(DetectionApi): for i, detection in enumerate(results.detections): if i == 20: break - - bbox = detection.bounding_box # left, upper, right, and lower pixel coordinate. + + bbox = ( + detection.bounding_box + ) # left, upper, right, and lower pixel coordinate. category = detection.categories[0] label = self.get_label_index(category.category_name) if label < 0: @@ -68,10 +74,9 @@ class Mediapipe(DetectionApi): round(category.score, 2), bbox.origin_y / self.h, bbox.origin_x / self.w, - (bbox.origin_y+bbox.height) / self.h, - (bbox.origin_x+bbox.width) / self.w, + (bbox.origin_y + bbox.height) / self.h, + (bbox.origin_x + bbox.width) / self.w, ] logger.debug(f"Detection: raw: {detection} result: {detections[i]}") - - return detections \ No newline at end of file + return detections