supervision
supervision copied to clipboard
enhance numpy arrays static type checking
Description
- This issue aims to improve the static type checking in our codebase and expand the functionality of the Supervision library. The enhancements will make the static type checking and improve code readilibty and help developers to understand which type they need to use
- Ensure type checking for all possible the functions and classes in the Supervision library.
Old Style code snippet
import numpy as np
@dataclass
class Detection:
xyxy: np.ndarray
mask: Optional[np.ndarray] = None
confidence: Optional[np.ndarray] = None
class_id: Optional[np.ndarray] = None
tracker_id: Optional[np.ndarray] = None
data: Dict[str, Union[np.ndarray, List]] = field(default_factory=dict)
def __len__(self):
return len(self.xyxy)
def __eq__(self, other: Detections):
return all(
[
np.array_equal(self.xyxy, other.xyxy),
np.array_equal(self.mask, other.mask),
np.array_equal(self.class_id, other.class_id),
np.array_equal(self.confidence, other.confidence),
np.array_equal(self.tracker_id, other.tracker_id),
is_data_equal(self.data, other.data),
]
)
New Style code snippet
import numpy as np
import numpy.typing as npt
@dataclass
class Detection:
xyxy: npt.NDArray[np.float32]
mask: Optional[npt.NDArray[np.float32]] = None
confidence: Optional[npt.NDArray[np.float32]] = None
class_id: Optional[npt.NDArray[np.float32]] = None
tracker_id: Optional[npt.NDArray[np.float32]] = None
data: Dict[str, Union[npt.NDArray[Any], List[Any]]] = field(default_factory=dict)
def __len__(self) -> int:
return len(self.xyxy)
def __eq__(self, other: Detections) -> bool:
return all(
[
np.array_equal(self.xyxy, other.xyxy),
np.array_equal(self.mask, other.mask),
np.array_equal(self.class_id, other.class_id),
np.array_equal(self.confidence, other.confidence),
np.array_equal(self.tracker_id, other.tracker_id),
is_data_equal(self.data, other.data),
]
)
Additional
- Note: Please share a Google Colab with minimal code to test the new feature. We know it's additional work, but it will definitely speed up the review process. Each change must be tested by the reviewer. Setting up a local environment to do this is time-consuming. Please ensure that Google Colab can be accessed without any issues (make it public). Thank you! 🙏🏻
@onuralpszr, thanks a lot for creating this issue 🙏🏻 I really appreciate that you're so helpful.
@onuralpszr, thanks a lot for creating this issue 🙏🏻 I really appreciate that you're so helpful.
You are welcome :)
Hello, can i try to do this?
Hello, can i try to do this?
I am already doing most of them. :)
Ohh okay
I really appreciate that you're so helpful
Hi @onuralpszr are you still thinking about finishing this work, or can I make it unassigned?
Hi @onuralpszr are you still thinking about finishing this work, or can I make it unassigned?
Sure, Let me finish and send PR, I already had changes in my local let me re-check, update with latest changes and open PR
@onuralpszr sounds great! 🔥