[Solved]: Unsupported operand type(s) for /: 'list' and 'int' when using transforms.scale() function

Hi,
I wrote below code to read MSCOCO Detection images using DataLoader. In this code I would like to alter the size of the read images to (488,488). Here is the code:

import torchvision.datasets as dset
import torchvision.transforms as trans
import sys
sys.path.append(‘./coco-master/PythonAPI/’)
from pycocotools.coco import COCO
import torch

det = dset.CocoDetection(root=‘./train2014’,
annFile = ‘./annotations/instances_train2014.json’,
transform = trans.Compose([trans.Scale(size=[448,448]),trans.ToTensor(),
trans.Normalize((.5,.5,.5),(.5,.5,.5))]))
trainLoader = torch.utils.data.DataLoader(det, batch_size=16, num_workers=2)
trainItr = iter(trainLoader)
images, labels = trainItr.next()

But when I ran above code, below error has happened (:expressionless:) :

TypeError Traceback (most recent call last)
in ()
----> 1 images, labels = trainItr.next()

/home/mohammad/anaconda3/lib/python3.5/site-packages/torch/utils/data/dataloader.py in next(self)
172 self.reorder_dict[idx] = batch
173 continue
→ 174 return self._process_next_batch(batch)
175
176 next = next # Python 2 compatibility

/home/mohammad/anaconda3/lib/python3.5/site-packages/torch/utils/data/dataloader.py in _process_next_batch(self, batch)
196 self._put_indices()
197 if isinstance(batch, ExceptionWrapper):
→ 198 raise batch.exc_type(batch.exc_msg)
199 return batch
200

TypeError: Traceback (most recent call last):
File “/home/mohammad/anaconda3/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 34, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/mohammad/anaconda3/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 34, in
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/mohammad/anaconda3/lib/python3.5/site-packages/torchvision-0.1.8-py3.5.egg/torchvision/datasets/coco.py”, line 59, in getitem
img = self.transform(img)
File “/home/mohammad/anaconda3/lib/python3.5/site-packages/torchvision-0.1.8-py3.5.egg/torchvision/transforms.py”, line 29, in call
img = t(img)
File “/home/mohammad/anaconda3/lib/python3.5/site-packages/torchvision-0.1.8-py3.5.egg/torchvision/transforms.py”, line 139, in call
ow = int(self.size * w / h)
TypeError: unsupported operand type(s) for /: ‘list’ and ‘int’

Could you please tell me what should I do? :innocent:
In pytorch document, it said that we can set a specific width and height for scale function as tuple or list. But I think something goes wrong with that!

@smth, Hi soumith. May I make an issue in github for this problem? I think transform.py has some flaws.

as francisco pointed out, you just need to update your torchvision to the latest.

1 Like

Thanks Dear soumith. By the way My torchvision is the last one! Could you please tell me what is the last version of torchvision? i would like to check it for sure.

pytorch---->0.1.11------>py35_5----->soumith
torchvision------------->0.1.8----------->py35_2------>soumith

The problem was solved . I just need to update my torchvision: Thanks @smth.

pip uninstall -y torchvision
pip uninstall -y torchvision # yes run the command again
pip install https://github.com/pytorch/vision/archive/master.zip

2 Likes

Ok, It works.Thanks, Although it is still 0.1.8