Skip to content

Commit 4b84d04

Browse files
authored
Removed numpy.typing (#175)
1 parent 33f8394 commit 4b84d04

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

luxonis_ml/data/datasets/annotation.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Any, ClassVar, Dict, List, Literal, Optional, Tuple, TypedDict, Union
55

66
import numpy as np
7-
import numpy.typing as npt
87
import pycocotools.mask as mask_util
98
from PIL import Image, ImageDraw
109
from pydantic import (
@@ -194,7 +193,7 @@ class SegmentationAnnotation(Annotation):
194193
@abstractmethod
195194
def to_numpy(
196195
self, class_mapping: Dict[str, int], width: int, height: int
197-
) -> npt.NDArray[np.bool_]:
196+
) -> np.ndarray:
198197
"""Converts the annotation to a numpy array."""
199198
pass
200199

@@ -257,9 +256,7 @@ def get_value(self) -> Dict[str, Any]:
257256
"counts": rle["counts"].decode("utf-8"),
258257
}
259258

260-
def to_numpy(
261-
self, _: Dict[str, int], width: int, height: int
262-
) -> npt.NDArray[np.bool_]:
259+
def to_numpy(self, _: Dict[str, int], width: int, height: int) -> np.ndarray:
263260
assert isinstance(self.counts, bytes)
264261
return mask_util.decode(
265262
{"counts": self.counts, "size": [height, width]}
@@ -312,7 +309,7 @@ def _validate_shape(mask: np.ndarray) -> np.ndarray:
312309

313310
@field_validator("mask", mode="before")
314311
@staticmethod
315-
def _validate_mask(mask: Any) -> npt.NDArray[np.bool_]:
312+
def _validate_mask(mask: Any) -> np.ndarray:
316313
if not isinstance(mask, np.ndarray):
317314
raise ValueError("Mask must be a numpy array")
318315
return mask.astype(np.bool_)
@@ -327,7 +324,7 @@ def get_value(self) -> Dict[str, Any]:
327324
"counts": rle["counts"].decode("utf-8"), # type: ignore
328325
}
329326

330-
def to_numpy(self, *_) -> npt.NDArray[np.bool_]:
327+
def to_numpy(self, *_) -> np.ndarray:
331328
return self.mask
332329

333330

@@ -343,9 +340,7 @@ class PolylineSegmentationAnnotation(SegmentationAnnotation):
343340

344341
points: List[Tuple[NormalizedFloat, NormalizedFloat]] = Field(min_length=3)
345342

346-
def to_numpy(
347-
self, _: Dict[str, int], width: int, height: int
348-
) -> npt.NDArray[np.bool_]:
343+
def to_numpy(self, _: Dict[str, int], width: int, height: int) -> np.ndarray:
349344
polyline = [(round(x * width), round(y * height)) for x, y in self.points]
350345
mask = Image.new("L", (width, height), 0)
351346
draw = ImageDraw.Draw(mask)

luxonis_ml/data/utils/data_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Dict, Iterator, Tuple
33

44
import numpy as np
5-
import numpy.typing as npt
65

76

87
def check_array(path: Path) -> None:
@@ -30,10 +29,10 @@ def _check_valid_array(path: Path) -> bool:
3029

3130

3231
def rgb_to_bool_masks(
33-
segmentation_mask: npt.NDArray[np.uint8],
32+
segmentation_mask: np.ndarray,
3433
class_colors: Dict[str, Tuple[int, int, int]],
3534
add_background_class: bool = False,
36-
) -> Iterator[Tuple[str, npt.NDArray[np.bool_]]]:
35+
) -> Iterator[Tuple[str, np.ndarray]]:
3736
"""Helper function to convert an RGB segmentation mask to boolean masks for each
3837
class.
3938

0 commit comments

Comments
 (0)