Closed
Description
Now that most of the tensor transforms have been implemented #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
: #2282 #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:
- adjust_brightness
- adjust_contrast
- adjust_saturation
- crop
- center_crop
- five_crop
- ten_crop
- pad (Added symmetric padding mode for Tensors #2373 Unified Pad and F.pad opertion for PIL and Tensor inputs #2345)
- resize (Unified input for resize op #2394)
- resized_crop (Unified input for resized crop op #2396)
- perspective ([BC-breaking] Unified input for F.perspective #2558, [BC-breaking] Unified input for RandomPerspective #2561)
- adjust_hue (adjust_hue now supports inputs of type Tensor #2566)
- adjust_gamma (Add torchscriptable adjust_gamma transform #2459)
- rotate (Unified inputs for
F.rotate
#2495 Unified inputs forT.RandomRotation
#2496 Fixes F.affine and F.rotate to support rectangular tensor images #2553) - affine (Unified input for F.affine #2444, Fixes incoherence in affine transformation with center is defined as … #2468, Unified inputs for
T.RandomAffine
transformation (2292) #2478, Fixes F.affine and F.rotate to support rectangular tensor images #2553) - to_grayscale