vision icon indicating copy to clipboard operation
vision copied to clipboard

Setting a list of no transforms to `transforms` argument of `RandomApply()` gets the indirect error message

Open hyperkai opened this issue 8 months ago • 1 comments

📚 The doc issue

Setting a list of no transforms to transforms argument of RandomApply() gets the indirect error message as shown below. *You can see this issue as well:

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

my_data = OxfordIIITPet(
    root="data",                   # ↓↓
    transform=RandomApply(transforms=[], p=1)
)

my_data[0][0] # Error

UnboundLocalError: cannot access local variable 'outputs' where it is not associated with a value

So, it should be something direct like below:

ValueError: There must be at least one transform

Suggest a potential alternative/fix

import torchvision

torchvision.__version__ # '0.20.1'

hyperkai avatar Apr 18 '25 03:04 hyperkai

Thanks for the report, feel free to submit a PR @hyperkai

NicolasHug avatar Apr 22 '25 11:04 NicolasHug