From 9fc66563dd7848d2c2900185a75cadb954f87598 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:23:50 +0000 Subject: [PATCH] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20form?= =?UTF-8?q?at=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/detection/core.py | 14 ++++++++++---- supervision/detection/tools/transformers.py | 11 ++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 0ae3fa65..301ed3e2 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -495,12 +495,18 @@ class Detections: transformers_results.__class__.__name__ == "Tensor" or "segmentation" in transformers_results ): - return cls(**process_transformers_v5_segmentation_result( - transformers_results, id2label)) + return cls( + **process_transformers_v5_segmentation_result( + transformers_results, id2label + ) + ) if "masks" in transformers_results or "png_string" in transformers_results: - return cls(**process_transformers_v4_segmentation_result( - transformers_results, id2label)) + return cls( + **process_transformers_v4_segmentation_result( + transformers_results, id2label + ) + ) if "boxes" in transformers_results: return cls(**process_detection_result(transformers_results, id2label)) diff --git a/supervision/detection/tools/transformers.py b/supervision/detection/tools/transformers.py index 0833e092..98207ce0 100644 --- a/supervision/detection/tools/transformers.py +++ b/supervision/detection/tools/transformers.py @@ -1,5 +1,5 @@ import io -from typing import Dict, Optional, Any +from typing import Any, Dict, Optional import numpy as np from PIL import Image @@ -11,7 +11,7 @@ from supervision.detection.utils import mask_to_xyxy def append_class_names_to_data( class_ids: np.ndarray, id2label: Optional[Dict[int, str]], - data: Optional[Dict[str, Any]] = None + data: Optional[Dict[str, Any]] = None, ) -> Dict[str, Any]: """ Helper function to create or append to a data dictionary with class names if @@ -119,7 +119,7 @@ def process_transformers_v4_segmentation_result( mask=np.squeeze(masks, axis=1) if boxes is not None else masks, confidence=segmentation_result["scores"].cpu().detach().numpy(), class_id=class_ids, - data=append_class_names_to_data(class_ids, id2label ,{}), + data=append_class_names_to_data(class_ids, id2label, {}), ) @@ -202,10 +202,7 @@ def process_png_segmentation_result( class_ids = np.array([segment["category_id"] for segment in segments_info]) label_mask = png_string_to_label_mask(segmentation_result["png_string"]) masks = np.array( - [ - (label_mask == segment["id"]).astype(bool) - for segment in segments_info - ] + [(label_mask == segment["id"]).astype(bool) for segment in segments_info] ) data = append_class_names_to_data(class_ids, id2label, {})