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 () :
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?
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!