pytorch / pytorch/vision

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

Open
#8,941 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🐛 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'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the torchvision.transforms.v2.RandAugment entry point and reproduce the reported cases with magnitude=3.5, None, and [3]. Trace where magnitude is consumed, then add or update coverage so invalid non-integer values produce the intended validation error and single-item lists are rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.