Random Crop, Resize

Hello everyone,

I have problems with transforms for images. Specifically, if I try to use RandomCrop or RandomSizedCrop, any kind of argument, from int, tuple or list, gives errors.

img = t(img)
File “/scratch/Dimitris/software/pytorch/pytorchenv/lib/python2.7/site-packages/torchvision/transforms.py”, line 238, in call
area = img.size[0] * img.size[1]
TypeError: ‘int’ object has no attribute ‘getitem


img = t(img)
File “/scratch/Dimitris/software/pytorch/pytorchenv/lib/python2.7/site-packages/torchvision/transforms.py”, line 204, in call
w, h = img.size
TypeError: ‘int’ object is not iterable

Is there anyone having similar problems?

can you give the snippet of code that will reproduce this error?

Here’s code that I have that works fine:

import torch
import torchvision as vision

rc = vision.transforms.RandomCrop([224, 224])
toPIL = vision.transforms.ToPILImage()
toTensor = vision.transforms.ToTensor()

input = torch.randn(3, 256, 256)

out = toTensor(rc(toPIL(input)))

How could one add rotations as transforms?

Thank You.

I’m facing the same error with RandomResizedCrop. I’ll try the solution you said. Do we need to implement vision.transforms.ToPILImage() to use torchvision Transforms? Won’t numpy arrays be acceptable?