Search code examples
pythonpytorchdata-augmentationtorchvision

torchvision.transforms.RandomRotation fill argument not working


I am working on tensors and want to rotate them with torchvision.transforms.RandomRotation and use the fill option.

import torch
import torchvision

img1 = torch.rand((1, 16, 16))
img2 = torchvision.transforms.RandomRotation(45, fill=1)(img1)

However, I always get:

Argument fill/fillcolor is not supported for Tensor input. Fill value is zero

and it gets not filled with ones. I have the same problem with torchvision.transforms.RandomPerspective. I am using Python 3.8 and PyTorch 1.7.1. I tried using fill=(1,), which seemed to be a workaround, but it did not worked for me. Do you know what could be wrong?


Solution

  • You're probably using torchvision v0.8.2 or older. This issue was fixed 5 months ago in the PR #2904. If you are not using v0.9.0 or newer, you won't be able to use fill in a Tensor input :(

    So, the only solution is to upgrade your torchvision.