vision icon indicating copy to clipboard operation
vision copied to clipboard

Setting a float value to `magnitude` argument of `RandAugment()` gets the wrong error message

Open hyperkai opened this issue 10 months ago • 1 comments

🐛 Describe the bug

Setting a float value to magnitude argument of RandAugment() gets the wrong error message as shown below:

from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import RandAugment

my_data = OxfordIIITPet(
    root="data",
    transform=RandAugment(magnitude=3.5)
)

my_data[0] # Error

IndexError: only integers, slices (:), ellipsis (...), None and long or byte Variables are valid indices (got float)

But setting None to magnitude argument doesn't work as shown below so the wrong error message above should be corrected:

from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import RandAugment

my_data = OxfordIIITPet(
    root="data",
    transform=RandAugment(magnitude=None)
)

my_data[0] # Error

ValueError: only one element tensors can be converted to Python scalars

In addition, setting a list of one element to magnitude argument works as shown below but it's useless so magnitude argument should only accept int but not list(int):

from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import RandAugment

my_data = OxfordIIITPet(
    root="data",
    transform=RandAugment(magnitude=[3])
)

my_data[0]
# (<PIL.Image.Image image mode=RGB size=394x500>, 0)

Versions

import torchvision

torchvision.__version__ # '0.20.1'

hyperkai avatar Feb 25 '25 19:02 hyperkai

The docs are clear that this should be an int, but I guess we can enforce a stricter input check to enforce an int >= 0. Feel free to submit a PR

NicolasHug avatar Feb 26 '25 09:02 NicolasHug