Problem with transform.RandomAffine: unexpected argument 'fillcolor'

When I am trying to use the torchvision.transforms.RandomAffine, I always got such an error:TypeError: transform() got an unexpected keyword argument ‘fillcolor’. Here is my code:

class RandomAffineTform(object):
“”“Online affine transformation on patches: randomly generated transform matrix.”""

def __call__(self, sample):
    patch1, patch2 = sample['patch1'], sample['patch2']
    patch1, patch2 = transforms.ToPILImage()(patch1), transforms.ToPILImage()(patch2)

    aff_tf = transforms.RandomAffine(degrees=5, scale=(0.9, 1.1), shear=5)

    return {'patch1': transforms.ToTensor()(aff_tf(patch1)),
            'patch2': transforms.ToTensor()(aff_tf(patch2))}

I have no idea how to debug it.

Which torchvision version are you using?
This code seems to work and basically does, what your code should do:

img = transforms.ToPILImage()(torch.randn(3, 224, 224))
transform = transforms.RandomAffine(degrees=5, scale=(0.9, 1.1), shear=5)
x = transforms.ToTensor()(transform(img))

Hi,

I am using torchvision-0.2.1

Thank you @ptrblck_de, the problem was just solved.

As I did not uninstall the previous version of torchvision when I upgrade to the latest version, the code was still using 2.0 instead of 2.1. The problem was solved when I simply deleted the old version. :slight_smile:

1 Like