I’m trying to build a data loader for image folders. My folder is like below:
data/train/Type_1/.jpg
data/train/Type_2/.jpg
data/train/Type_3/*.jpg
And I use the following script for building the DataLoader.
import torch
import torchvision.transforms as T
from torchvision import datasets
Train_transform = T.Compose([
T.RandomSizedCrop( 224 ),
T.RandomHorizontalFlip,
T.ToTensor(),
T.Normalize( mean = [ 0.485, 0.456, 0.406 ],
std = [ 0.229, 0.224, 0.225 ] )
])
traindir = ‘data/train’
train_loader = torch.utils.data.DataLoader(
datasets.ImageFolder( traindir, Train_transform ), batch_size = 32,
shuffle = True, num_workers = 4, pin_memory=True )
for i, (input, target) in enumerate( train_loader ):
print input.size(), i
break
However when I try to iterate the dataloader, the following error appears.
TypeError                                 Traceback (most recent call last)
 in ()
19     shuffle = True, num_workers = 4, pin_memory=True )
20
—> 21 for i, (input, target) in enumerate( train_loader ):
22     print input.size(), i
23     break
/home/yufeng/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.pyc 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/yufeng/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.pyc 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/yufeng/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.py”, line 34, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/yufeng/anaconda2/lib/python2.7/site-packages/torchvision-0.1.8-py2.7.egg/torchvision/datasets/folder.py”, line 67, in getitem
img = self.transform(img)
File “/home/yufeng/anaconda2/lib/python2.7/site-packages/torchvision-0.1.8-py2.7.egg/torchvision/transforms.py”, line 29, in call
img = t(img)
TypeError: object() takes no parameters
Can anyone help point out the errors here? Any suggestions is more than appreciated. Thanks for your time.