-
Notifications
You must be signed in to change notification settings - Fork 7k
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
base: main
Are you sure you want to change the base?
Conversation
This is to avoid the pyright error `reportUnknownMemberType` when using this function.
🔗 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. |
torchvision/transforms/functional.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
Thank you for the initial review @NicolasHug . I'd appreciate another look, and I can be quicker with responses from now. |
torchvision/transforms/functional.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
This is to avoid the pyright error
reportUnknownMemberType
when using this function.