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

I get the following error message after updating to the latest torchvision.
The transformation that causes the error is randomRotation.
I believe that it’s related to the following bugfix:

Moreover, it only happens when it is preceded by
transforms.Grayscale(num_output_channels=1) .
How can i make it work without downgrading?
Thank you.

  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torch/utils/data/_utils/", 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/", 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/", line 44, in <listcomp>
    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/", line 257, in __getitem__
    return self.dataset[self.indices[idx]]
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torchvision/datasets/", line 140, in __getitem__
    sample = self.transform(sample)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torchvision/transforms/", line 70, in __call__
    img = t(img)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torchvision/transforms/", line 1003, in __call__
    return F.rotate(img, angle, self.resample, self.expand,, self.fill)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/torchvision/transforms/", 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/", line 1915, in rotate
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/PIL/", line 2205, in transform
    im = new(self.mode, size, fillcolor)
  File "/Users/user/opt/anaconda3/envs/vident/lib/python3.7/site-packages/PIL/", line 2375, in new
    return Image()._new(core.fill(mode, size, color))
TypeError: function takes exactly 1 argument (3 given)
1 Like

The issue is tracked here.
As a workaround, you could pass fill=(0,) to transforms.RandomRotation as suggested in the linked comment:

transform = transforms.Compose([
    transforms.RandomRotation(10, fill=(0,))

img = transforms.ToPILImage()(torch.randn(3, 224, 224))
img = transform(img)

Note the comma in the argument.


the comma is what i missed. thank you.

You couldn’t know you have to change the fill argument, and it should be fixed soon in the nightly binaries. :wink: