-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Open
Description
According to the docstring, ColorJitter.get_params has arguments same as that of __init__.
However, while ColorJitter.__init__ can accept tuples or floats as parameters, get_params only accepts tuples:
In [2]: from torchvision.transforms import ColorJitter
In [3]: ColorJitter((0.8, 0.9), (0.8, 0.9), (0.7, 0.9), (0.1, 0.2))
Out[3]: ColorJitter(brightness=(0.8, 0.9), contrast=(0.8, 0.9), saturation=(0.7, 0.9), hue=(0.1, 0.2))
In [4]: ColorJitter(0.9, 0.9, 0.9, 0.1)
Out[4]: ColorJitter(brightness=[0.09999999999999998, 1.9], contrast=[0.09999999999999998, 1.9], saturation=[0.09999999999999998, 1.9], hue=[-0.1, 0.1])
In [5]: ColorJitter.get_params((0.8, 0.9), (0.8, 0.9), (0.7, 0.9), (0.1, 0.2))
Out[5]:
Compose(
Lambda()
Lambda()
Lambda()
Lambda()
)
In [6]: ColorJitter.get_params(0.9, 0.9, 0.9, 0.1)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-32bc75c83828> in <module>
----> 1 ColorJitter.get_params(0.9, 0.9, 0.9, 0.1)
~/anaconda3/envs/pytorch1/lib/python3.6/site-packages/torchvision/transforms/transforms.py in get_params(brightness, contrast, saturation, hue)
805
806 if brightness is not None:
--> 807 brightness_factor = random.uniform(brightness[0], brightness[1])
808 transforms.append(Lambda(lambda img: F.adjust_brightness(img, brightness_factor)))
809
TypeError: 'float' object is not subscriptable
This bug means that workarounds are required to support earlier and later torchvision versions.
I feel that get_params should call self._check_input on the input arguments, just like __init__. I don't however know if this would have any knock-on input on anything else.
(This issue I think was introduced around here.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels