🖤bake black happy

This commit is contained in:
SkalskiP 2023-04-08 19:05:07 +02:00
parent d5d2035048
commit bcc4b25eb9
3 changed files with 20 additions and 16 deletions

View File

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

View File

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

View File

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