ColorJitter's get_params doesn't have same arguments as __init__
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
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.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in torchvision/transforms/transforms.py at ColorJitter.init and get_params, comparing their argument handling and the referenced _check_input behavior. Verify that get_params supports the scalar and tuple forms documented for init, while preserving the existing tuple behavior; no test file is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100