From bcc4b25eb91e7e835d42ca465f655a05abeb5fc0 Mon Sep 17 00:00:00 2001 From: SkalskiP Date: Sat, 8 Apr 2023 19:05:07 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=96=A4bake=20black=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/detection/annotate.py | 4 +++- supervision/detection/core.py | 24 ++++++++++++++---------- supervision/notebook/utils.py | 8 +++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/supervision/detection/annotate.py b/supervision/detection/annotate.py index 9c49b824..070a5d66 100644 --- a/supervision/detection/annotate.py +++ b/supervision/detection/annotate.py @@ -58,7 +58,9 @@ class BoxAnnotator: font = cv2.FONT_HERSHEY_SIMPLEX for i in range(len(detections)): x1, y1, x2, y2 = detections.xyxy[i].astype(int) - class_id = detections.class_id[i] if detections.class_id is not None else None + class_id = ( + detections.class_id[i] if detections.class_id is not None else None + ) idx = class_id if class_id is not None else i color = ( self.color.by_idx(idx) diff --git a/supervision/detection/core.py b/supervision/detection/core.py index 08bd8867..40a391c6 100644 --- a/supervision/detection/core.py +++ b/supervision/detection/core.py @@ -1,7 +1,7 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Iterator, List, Optional, Tuple, Union, Any +from typing import Any, Iterator, List, Optional, Tuple, Union import numpy as np @@ -17,8 +17,7 @@ def _validate_xyxy(xyxy: Any, n: int) -> None: def _validate_mask(mask: Any, n: int) -> None: is_valid = mask is None or ( - isinstance(mask, np.ndarray) - and len(mask.shape) == 3 and mask[0] == n + isinstance(mask, np.ndarray) and len(mask.shape) == 3 and mask[0] == n ) if not is_valid: raise ValueError("mask must be 3d np.ndarray with (n, W, H) shape") @@ -26,8 +25,7 @@ def _validate_mask(mask: Any, n: int) -> None: def _validate_class_id(class_id: Any, n: int) -> None: is_valid = class_id is None or ( - isinstance(class_id, np.ndarray) - and class_id.shape == (n,) + isinstance(class_id, np.ndarray) and class_id.shape == (n,) ) if not is_valid: raise ValueError("class_id must be None or 1d np.ndarray with (n,) shape") @@ -35,8 +33,7 @@ def _validate_class_id(class_id: Any, n: int) -> None: def _validate_confidence(confidence: Any, n: int) -> None: is_valid = confidence is None or ( - isinstance(confidence, np.ndarray) - and confidence.shape == (n,) + isinstance(confidence, np.ndarray) and confidence.shape == (n,) ) if not is_valid: raise ValueError("confidence must be None or 1d np.ndarray with (n,) shape") @@ -44,8 +41,7 @@ def _validate_confidence(confidence: Any, n: int) -> None: def _validate_tracker_id(tracker_id: Any, n: int) -> None: is_valid = tracker_id is None or ( - isinstance(tracker_id, np.ndarray) - and tracker_id.shape == (n,) + isinstance(tracker_id, np.ndarray) and tracker_id.shape == (n,) ) if not is_valid: raise ValueError("tracker_id must be None or 1d np.ndarray with (n,) shape") @@ -86,7 +82,15 @@ class Detections: def __iter__( self, - ) -> Iterator[Tuple[np.ndarray, Optional[np.ndarray], Optional[float], Optional[int], Optional[int]]]: + ) -> Iterator[ + Tuple[ + np.ndarray, + Optional[np.ndarray], + Optional[float], + Optional[int], + Optional[int], + ] + ]: """ Iterates over the Detections object and yield a tuple of `(xyxy, confidence, class_id, tracker_id)` for each detection. """ diff --git a/supervision/notebook/utils.py b/supervision/notebook/utils.py index 789eee12..79434ca7 100644 --- a/supervision/notebook/utils.py +++ b/supervision/notebook/utils.py @@ -6,9 +6,7 @@ import numpy as np def plot_image( - image: np.ndarray, - size: Tuple[int, int] = (12, 12), - cmap: Optional[str] = "gray" + image: np.ndarray, size: Tuple[int, int] = (12, 12), cmap: Optional[str] = "gray" ) -> None: """ Plots image using matplotlib. @@ -36,7 +34,7 @@ def plot_image( else: plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) - plt.axis('off') + plt.axis("off") plt.show() @@ -45,7 +43,7 @@ def plot_images_grid( grid_size: Tuple[int, int], titles: Optional[List[str]] = None, size: Tuple[int, int] = (12, 12), - cmap: Optional[str] = "gray" + cmap: Optional[str] = "gray", ) -> None: """ Plots images in a grid using matplotlib.