Error when using transforms.Scale

I am having trouble trying to use the transforms.Scale(size=(100,200)) method as I keep getting the error message below. I have checked that using only the ToTensor() does not give me any error so I don’t think its an issue with the installation ? Also, I am aware that I have an older version of torchvision but I still can’t figure out why it doesn’t work.

Below is the error message followed by the __getitem__ method

Traceback (most recent call last):
File “train.py”, line 603, in
main(args)
File “train.py”, line 243, in main
for batch in train_loader:
File “/home/haziq/anaconda3/envs/pytorch-cuda9.0/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 336, in next
return self._process_next_batch(batch)
File “/home/haziq/anaconda3/envs/pytorch-cuda9.0/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 357, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
TypeError: Traceback (most recent call last):
File “/home/haziq/anaconda3/envs/pytorch-cuda9.0/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 106, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/haziq/anaconda3/envs/pytorch-cuda9.0/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 106, in
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/haziq/Desktop/Trajectory Prediction/sgan-original/sgan/data/trajectories.py”, line 149, in getitem
pedestrian_images.append(self.transform(cv2.imread(os.path.join(folder, ‘crops’, str(frame).zfill(10), str(int(idx)).zfill(10)+“.png”))))
File “/home/haziq/anaconda3/envs/pytorch-cuda9.0/lib/python3.5/site-packages/torchvision-0.1.9-py3.5.egg/torchvision/transforms.py”, line 34, in call
img = t(img)
File “/home/haziq/anaconda3/envs/pytorch-cuda9.0/lib/python3.5/site-packages/torchvision-0.1.9-py3.5.egg/torchvision/transforms.py”, line 199, in call
return img.resize(self.size, self.interpolation)
TypeError: ‘tuple’ object cannot be interpreted as an integer

    def __getitem__(self, index):

        # get data for the given index
        df = self.df[self.df['global_id'] == index]

        # read images
        pedestrian_images = []
        for folder,frame,idx in zip(df['folder'],df['frame'],df['id']):
                pedestrian_images.append(self.transform(cv2.imread(os.path.join(folder, 'crops', str(frame).zfill(10), str(int(idx)).zfill(10)+".png"))))
	
        return pedestrian_images

The error message is a bit strange, however the error might be thrown, since you are passing a numpy array instead of a PIL.Image.
The image transformations of torchvision.transforms usually work on PIL.Images, so try to load it as such.
Also, transforms.Scale is deprecated, you should use transforms.Resize instead.

1 Like