Error message following update to torchvision 0.5 "function takes exactly 1 argument (3 given)"

username: mcfn
cooked: <p>I get the following error message after updating to the latest torchvision.<br>
The transformation that causes the error is randomRotation.<br>
I believe that it’s related to the following bugfix:<br>
<aside class="onebox githubpullrequest">
  <header class="source">
      <a href="https://github.com/pytorch/vision/pull/1280" target="_blank" rel="nofollow noopener">github.com/pytorch/vision</a>
  </header>
  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Pull Request">
    <svg width="60" height="60" class="github-icon" viewbox="0 0 12 16" aria-hidden="true"><path d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/vision/pull/1280" target="_blank" rel="nofollow noopener">Adds optional fill colour to rotate</a>
    </h4>

    <div class="branches">
      <code>pytorch:master</code> ← <code>pmeier:add_fill_to_rotate</code>
    </div>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2019-08-30" data-time="09:34:29" data-timezone="UTC">09:34AM - 30 Aug 19 UTC</span>
      </div>

      <div class="user">
        <a href="https://github.com/pmeier" target="_blank" rel="nofollow noopener">
          <img alt="pmeier" src="https://avatars0.githubusercontent.com/u/6849766?v=4" class="onebox-avatar-inline" width="20" height="20">
          pmeier
        </a>
      </div>

      <div class="lines" title="2 commits changed 2 files with 12 additions and 4 deletions">
        <a href="https://github.com/pytorch/vision/pull/1280/files" target="_blank" rel="nofollow noopener">
          <span class="added">+12</span>
          <span class="removed">-4</span>
        </a>
      </div>
    </div>

  </div>
</div>
  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
Moreover, it only happens when it is preceded by<br>
transforms.Grayscale(num_output_channels=1) .<br>
How can i make it work without downgrading?<br>
Thank you.</p>
<pre><code class="lang-auto">  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in &lt;listcomp&gt;
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torch/utils/data/dataset.py", line 257, in __getitem__
    return self.dataset[self.indices[idx]]
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torchvision/datasets/folder.py", line 140, in __getitem__
    sample = self.transform(sample)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 70, in __call__
    img = t(img)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 1003, in __call__
    return F.rotate(img, angle, self.resample, self.expand, self.center, self.fill)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 729, in rotate
    return img.rotate(angle, resample, expand, center, fillcolor=fill)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/PIL/Image.py", line 1915, in rotate
    fillcolor=fillcolor)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/PIL/Image.py", line 2205, in transform
    im = new(self.mode, size, fillcolor)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/PIL/Image.py", line 2375, in new
    return Image()._new(core.fill(mode, size, color))
TypeError: function takes exactly 1 argument (3 given)
</code></pre>

username: ptrblck
cooked: <p>The issue is tracked <a href="https://github.com/pytorch/vision/issues/1759#issuecomment-575307516">here</a>.<br>
As a workaround, you could pass <code>fill=(0,)</code> to <code>transforms.RandomRotation</code> as suggested in the linked comment:</p>
<pre><code class="lang-python">transform = transforms.Compose([
    transforms.Grayscale(num_output_channels=1),
    transforms.RandomRotation(10, fill=(0,))
])

img = transforms.ToPILImage()(torch.randn(3, 224, 224))
img = transform(img)
</code></pre>
<p>Note the comma in the argument.</p>

username: mcfn
cooked: <p>the comma is what i missed. thank you.</p>

username: ptrblck
cooked: <p>You couldn’t know you have to change the <code>fill</code> argument, and it should be fixed soon in the nightly binaries. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>