Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance numpy arrays static type checking #1021

Open
onuralpszr opened this issue Mar 19, 2024 · 9 comments
Open

enhance numpy arrays static type checking #1021

onuralpszr opened this issue Mar 19, 2024 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@onuralpszr
Copy link
Collaborator

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 onuralpszr added the enhancement New feature or request label Mar 19, 2024
@onuralpszr onuralpszr self-assigned this Mar 19, 2024
@SkalskiP
Copy link
Collaborator

@onuralpszr, thanks a lot for creating this issue 🙏🏻 I really appreciate that you're so helpful.

@SkalskiP SkalskiP changed the title Enhance Static Type Checking of the Supervision enhance numpy arrays static type checking Mar 19, 2024
@onuralpszr
Copy link
Collaborator Author

@onuralpszr, thanks a lot for creating this issue 🙏🏻 I really appreciate that you're so helpful.

You are welcome :)

@jeslinpjames
Copy link
Contributor

Hello, can i try to do this?

@onuralpszr
Copy link
Collaborator Author

Hello, can i try to do this?

I am already doing most of them. :)

@jeslinpjames
Copy link
Contributor

Ohh okay

@miladhatami1393
Copy link

I really appreciate that you're so helpful

@SkalskiP
Copy link
Collaborator

Hi @onuralpszr are you still thinking about finishing this work, or can I make it unassigned?

@onuralpszr
Copy link
Collaborator Author

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

@SkalskiP
Copy link
Collaborator

@onuralpszr sounds great! 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants