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

Add detail to type for functional.to_tensor pic #8449

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

adamtheturtle
Copy link
Contributor

This is to avoid the pyright error reportUnknownMemberType when using this function.

This is to avoid the pyright error `reportUnknownMemberType` when using this function.
Copy link

pytorch-bot bot commented May 29, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/8449

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@@ -124,7 +124,7 @@ def _is_numpy_image(img: Any) -> bool:
return img.ndim in {2, 3}


def to_tensor(pic: Union[PILImage, np.ndarray]) -> Tensor:
def to_tensor(pic: Union[PILImage, np.ndarray[int, int]]) -> Tensor:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamtheturtle thanks for the PR - just to make sure I understand correctly, does np.ndarray[int, int] mean the ndarry is expected to only have 2 dimensions? If that's the case then that is not correct as we allow both 2D and 3D arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies @NicolasHug for leaving this hanging. I have had another go, and not specified the dimensions. I have also used numpy.typing.NDArray.

@adamtheturtle
Copy link
Contributor Author

Thank you for the initial review @NicolasHug .

I'd appreciate another look, and I can be quicker with responses from now.

@@ -124,7 +125,7 @@ def _is_numpy_image(img: Any) -> bool:
return img.ndim in {2, 3}


def to_tensor(pic: Union[PILImage, np.ndarray]) -> Tensor:
def to_tensor(pic: Union[PILImage, NDArray[np.uint8]]) -> Tensor:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @adamtheturtle I don't think this is correct, to_tensor also accepts numpy arrays of float values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking another look @NicolasHug . I have attempted to update this PR. We will get there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants