From 409dcbd9da5d1aeb5c3a7746163be87bfaf3628d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 Apr 2024 20:49:03 +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/__init__.py | 5 ++--- supervision/keypoints/annotate.py | 9 +++------ supervision/keypoints/core.py | 6 ++---- supervision/keypoints/skeletons.py | 9 ++++----- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/supervision/__init__.py b/supervision/__init__.py index 549e870e..c4883335 100644 --- a/supervision/__init__.py +++ b/supervision/__init__.py @@ -56,9 +56,6 @@ from supervision.detection.utils import ( polygon_to_xyxy, scale_boxes, ) -from supervision.keypoints.core import KeyPoints -from supervision.keypoints.skeletons import KnownSkeletons, Skeleton -from supervision.keypoints.annotate import KeyPointAnnotator, SkeletonAnnotator from supervision.draw.color import Color, ColorPalette from supervision.draw.utils import ( calculate_optimal_line_thickness, @@ -72,7 +69,9 @@ from supervision.draw.utils import ( ) from supervision.geometry.core import Point, Position, Rect from supervision.geometry.utils import get_polygon_center +from supervision.keypoints.annotate import KeyPointAnnotator, SkeletonAnnotator from supervision.keypoints.core import KeyPoints +from supervision.keypoints.skeletons import KnownSkeletons, Skeleton from supervision.metrics.detection import ConfusionMatrix, MeanAveragePrecision from supervision.tracker.byte_tracker.core import ByteTrack from supervision.utils.file import list_files_with_extensions diff --git a/supervision/keypoints/annotate.py b/supervision/keypoints/annotate.py index e051fa8e..978c1e8d 100644 --- a/supervision/keypoints/annotate.py +++ b/supervision/keypoints/annotate.py @@ -8,7 +8,7 @@ from supervision.annotators.base import ImageType from supervision.annotators.utils import scene_to_annotator_img_type from supervision.draw.color import Color from supervision.keypoints.core import KeyPoints -from supervision.keypoints.skeletons import Skeleton, KnownSkeletons +from supervision.keypoints.skeletons import KnownSkeletons, Skeleton class BaseKeyPointAnnotator(ABC): @@ -75,14 +75,11 @@ class SkeletonAnnotator(BaseKeyPointAnnotator): self.skeleton = skeleton @scene_to_annotator_img_type - def annotate( - self, scene: ImageType, keypoints: KeyPoints - ) -> ImageType: + def annotate(self, scene: ImageType, keypoints: KeyPoints) -> ImageType: if len(keypoints) == 0: return scene if keypoints.class_id is None: - raise ValueError( - "KeyPoints must have class_id to annotate a skeleton") + raise ValueError("KeyPoints must have class_id to annotate a skeleton") xy_all = keypoints.xy for xy in xy_all: diff --git a/supervision/keypoints/core.py b/supervision/keypoints/core.py index 5aa0a4d1..2b432be4 100644 --- a/supervision/keypoints/core.py +++ b/supervision/keypoints/core.py @@ -58,8 +58,7 @@ class KeyPoints: xy: npt.NDArray[np.float32] class_id: Optional[npt.NDArray[np.int_]] = None confidence: Optional[npt.NDArray[np.float32]] = None - data: Dict[str, Union[npt.NDArray[Any], List] - ] = field(default_factory=dict) + data: Dict[str, Union[npt.NDArray[Any], List]] = field(default_factory=dict) def __post_init__(self): validate_keypoints_fields( @@ -139,8 +138,7 @@ class KeyPoints: xy = ultralytics_results.keypoints.xy.cpu().numpy() class_id = ultralytics_results.boxes.cls.cpu().numpy().astype(int) - class_names = np.array([ultralytics_results.names[i] - for i in class_id]) + class_names = np.array([ultralytics_results.names[i] for i in class_id]) confidence = ultralytics_results.keypoints.conf.cpu().numpy() data = {CLASS_NAME_DATA_FIELD: class_names} diff --git a/supervision/keypoints/skeletons.py b/supervision/keypoints/skeletons.py index a9d8d01f..03a4f335 100644 --- a/supervision/keypoints/skeletons.py +++ b/supervision/keypoints/skeletons.py @@ -1,5 +1,3 @@ - - from typing import List, Tuple @@ -70,6 +68,7 @@ class KnownSkeletons: # Suppose you have a model returning 15 keypoints. skeleton = KnownSkeletons().get_skeleton(15) """ + _instance = None _skeletons: dict[int, Skeleton] = {} @@ -81,14 +80,14 @@ class KnownSkeletons: def add_skeleton(self, skeleton: Skeleton) -> None: len_limbs = len(skeleton.limbs) if len_limbs in self._skeletons: - raise ValueError( - f"A skeleton with {len_limbs} limbs already exists") + raise ValueError(f"A skeleton with {len_limbs} limbs already exists") self._skeletons[len_limbs] = skeleton def get_skeleton(self, limb_count: int) -> Skeleton: if limb_count not in self._skeletons: print( - f"Warning: No skeleton found with {limb_count} limbs. Will create one now.") + f"Warning: No skeleton found with {limb_count} limbs. Will create one now." + ) self.add_skeleton(_make_sequential_skeleton(limb_count)) return self._skeletons[limb_count]