Error about torch.FloatTensor attribute 'resize'

Hi everyone,
I have met a problem when loading my own dataset,

trainset = torchvision.datasets.ImageFolder(root='../dataset/', 
                            transform=transforms.Compose([
                            transforms.ToTensor(),
                            transforms.Scale((64,64))
                            ]))

trainloader = torch.utils.data.DataLoader(trainset, batch_size=batch_size,
                                      shuffle=True, num_workers=2)

data = iter(trainloader)
imgs = data.next()[0]

And I got the error:

AttributeError: Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/torch/utils/data/dataloader.py”, line 41, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/usr/local/lib/python2.7/dist-packages/torchvision/datasets/folder.py”, line 118, in getitem
img = self.transform(img)
File “/usr/local/lib/python2.7/dist-packages/torchvision/transforms.py”, line 34, in call
img = t(img)
File “/usr/local/lib/python2.7/dist-packages/torchvision/transforms.py”, line 199, in call
return img.resize(self.size, self.interpolation)
AttributeError: ‘torch.FloatTensor’ object has no attribute ‘resize’

any idea? thanks.

Hi,

there are two types of transforms: Those that take PIL images as input and those that take Tensors. Scale takes an image (which has a resize method).
Note that in order to be able to pass a tuple to the Scale transform, you need to install from the https://github.com/pytorch/vision master branch.

Best regards

Thomas

Thanks Thomas. Actually, I just noticed it.