vision icon indicating copy to clipboard operation
vision copied to clipboard

Setting a 2D tensor to `RandomAffine()` after instantiation got other error message against error message

Open hyperkai opened this issue 11 months ago • 1 comments

🐛 Describe the bug

Setting a 1D tensor to RandomAffine() after instantiation got the error message as shown below:

import torch
from torchvision.transforms.v2 import RandomAffine

my_tensor = torch.tensor([0]) # 1D

ra = RandomAffine(degrees=0)

ra(my_tensor) # Error

TypeError: Input tensor should have at least two dimensions, but got 1

But, setting a 2D tensor to RandomAffine() after instantiation got other error message against the above error message as shown below:

import torch
from torchvision.transforms.v2 import RandomAffine

my_tensor = torch.tensor([[0, 1, 2]]) # 2D tensor

ra = RandomAffine(degrees=0)

ra(my_tensor) # Error

ValueError: not enough values to unpack (expected 3, got 2)

In addition, setting a 3D tensor to RandomAffine() after instantiation works as shown below:

import torch
from torchvision.transforms.v2 import RandomAffine

my_tensor = torch.tensor([[[0, 1, 2]]]) # 3D tensor

ra = RandomAffine(degrees=0)

ra(my_tensor)
# tensor([[[0, 1, 2]]])

Versions

import torchvision

torchvision.__version__ # '0.20.1'

hyperkai avatar Jan 16 '25 00:01 hyperkai

Thanks for the report - if there are ways to keep the code simple and improve the error messages for cases that make sense (which, I'm not entirely sure is the case for the provided examples), I'm happy to consider a PR.

NicolasHug avatar Feb 19 '25 13:02 NicolasHug