add gallery for transforms v2#7331
Conversation
vfdev-5
left a comment
There was a problem hiding this comment.
Few nits otherwise looks good to me
| ######################################################################################################################## | ||
| # 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.
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.
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.
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