44from typing import Any , ClassVar , Dict , List , Literal , Optional , Tuple , TypedDict , Union
55
66import numpy as np
7- import numpy .typing as npt
87import pycocotools .mask as mask_util
98from PIL import Image , ImageDraw
109from 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 )
0 commit comments