Skip to content

transforms v2 rotate can create different sizes between tensors and PIL with expand=True #7714

@pmeier

Description

@pmeier
import torch
from torchvision.transforms.v2 import functional as F

input_tensor = torch.rand(3, 17, 11)
input_pil = F.to_pil_image(input_tensor)

kwargs = dict(angle=-10.9, center=(1.2, 4.9), expand=True)

output_tensor = F.rotate(input_tensor, **kwargs)
output_pil = F.rotate(input_pil, **kwargs)

shape_tensor = F.get_image_size(output_tensor)
shape_pil = F.get_image_size(output_pil)

assert shape_tensor == shape_pil, f"{shape_tensor} != {shape_pil}"
AssertionError: [15, 20] != [15, 19]

Replacing the import with from torchvision.transforms import functional as F, i.e. using transforms v1, does not have this problem.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions