Unify Tensor and PIL transforms
See original GitHub issueNow that most of the tensor transforms have been implemented https://github.com/pytorch/vision/issues/1375, it is time to make unify the implementations for PIL and Tensor so that torchvision.transforms
and torchvision.transforms.functional
works seamlessly between both datatypes.
As such, we would like that the following work with the same interface:
# functional interface
torchvision.transforms.functional.hflip(pil_image)
torchvision.transforms.functional.hflip(tensor_image)
# class interface
transform = torchvision.transforms.RandomHorizontalFlip(0.3)
transform(pil_image)
transform(tensor_image)
# torchscript support for tensor_image
script_transform = torch.jit.script(transform)
script_transform(tensor_image)
Example PRs adding support for hflip
and vflip
: https://github.com/pytorch/vision/pull/2282 https://github.com/pytorch/vision/pull/2283
We would like to add support for torchscript to the torchvision.transforms
interface as well, which for simplicity might require a few changes. Most notably we would need the transforms to inherit from nn.Module
.
Here is a list of transforms that can be readily converted:
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (9 by maintainers)
New issue opened #2887
The issue can be closed as all mentioned transformations now support tensor and pil image as input.