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