Random Crop, Resize


(Dim Trigkakis) #1

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

or

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?


#2

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)))
print(out.size())

(Royi) #3

How could one add rotations as transforms?

Thank You.


#4

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?