Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hyperkai opened this issue Feb 25, 2025 · 1 comment

Comments

@hyperkai
Copy link

🐛 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'
@NicolasHug
Copy link
Member

NicolasHug commented Feb 26, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants