-
Notifications
You must be signed in to change notification settings - Fork 7.1k
add gallery for transforms v2 #7331
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
Conversation
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.
Few nits otherwise looks good to me
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.
Thanks Philip
######################################################################################################################## | ||
# As stated above, :mod:`torchvision.transforms.v2` is a drop-in replacement for :mod:`torchvision.transforms` and thus | ||
# also supports transforming plain :class:`torch.Tensor`'s as image or video if applicable. This is achieved with a | ||
# simple heuristic: | ||
# | ||
# * If we find an explicit image or video (:class:`torchvision.datapoints.Image`, :class:`torchvision.datapoints.Video`, | ||
# or :class:`PIL.Image.Image`) in the input, all other plain tensors are passed through. | ||
# * If there is no explicit image or video, only the first plain :class:`torch.Tensor` will be transformed as image or | ||
# video, while all others will be passed through. | ||
|
||
plain_tensor_image = torch.rand(image.shape) | ||
|
||
print(image.shape, plain_tensor_image.shape) | ||
|
||
# passing a plain tensor together with an explicit image, will not transform the former | ||
plain_tensor_image, image = transform(plain_tensor_image, image) | ||
|
||
print(image.shape, plain_tensor_image.shape) | ||
|
||
# passing a plain tensor without an explicit image, will transform the former | ||
plain_tensor_image, _ = transform(plain_tensor_image, bounding_boxes) | ||
|
||
print(image.shape, plain_tensor_image.shape) |
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.
I wonder whether we should actually document the heuristic, since it's a potentially controversial part of the contract right now. I feel like it'd be fine to just document that "a single plain tensor is treated as an image for full BC", and leave out the rest.
But not strong opinion.
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.
Basically, because this is an introductory example I kinda fear that users will think "oh boy, I have to understand all this, and this looks complicated" when in reality 99% of users don't have to worry about this behaviour at all
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.
let's merge, and we'll try to think of a better way to still document this
Hey @NicolasHug! You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py |
Reviewed By: vmoens Differential Revision: D44416549 fbshipit-source-id: f343c4f247ba09d5e6c7c137e9a05a0c7769a499
cc @vfdev-5