fix(pre_commit): 🎨 auto format pre-commit hooks

This commit is contained in:
pre-commit-ci[bot] 2024-04-23 20:49:03 +00:00
parent 07482a347c
commit 409dcbd9da
4 changed files with 11 additions and 18 deletions

View File

@ -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

View File

@ -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:

View File

@ -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}

View File

@ -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]