Skip to content

Unify Tensor and PIL transforms #2292

Closed
@fmassa

Description

@fmassa

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:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions