vision icon indicating copy to clipboard operation
vision copied to clipboard

Setting a single negative value or a couple of negative values to `sigma` argument of `ElasticTransform()` doesn't get error against the error message

Open hyperkai opened this issue 11 months ago • 1 comments

🐛 Describe the bug

Setting a negative and positive value together to sigma argument of ElasticTransform() gets the error messages as shown below:

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

my_data1 = OxfordIIITPet(
    root="data",             # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
    transform=ElasticTransform(sigma=[-100, 100])
)

my_data2 = OxfordIIITPet(
    root="data",             # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
    transform=ElasticTransform(sigma=[100, -100])
)

my_data1[0] # Error
my_data2[0] # Error

ValueError: sigma should have positive values. Got [-100.0, 100.0]

ValueError: sigma should have positive values. Got [100.0, -100.0]

But setting a single negative value or a couple of negative values to sigma argument of ElasticTransform() doesn't get error against the above error message as shown below:

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

my_data1 = OxfordIIITPet(
    root="data",             # ↓ ↓ ↓ ↓ ↓
    transform=ElasticTransform(sigma=-100)
)

my_data2 = OxfordIIITPet(
    root="data",             # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
    transform=ElasticTransform(sigma=[-100, -100])
)

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

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

Versions

import torchvision

torchvision.__version__ # '0.20.1'

hyperkai avatar Jan 24 '25 01:01 hyperkai

happy to consider a PR @hyperkai .

NicolasHug avatar Feb 19 '25 13:02 NicolasHug