pytorch / pytorch/vision

ColorJitter's get_params doesn't have same arguments as __init__

Open
#905 0 comments 3 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.