Getting KeyError: 'uint32' in default_collate method in data/dataloader.py

I have written the dataloader as

composed_transform = transforms.Compose([transforms.Scale((resnet_input,resnet_input)),transforms.RandomHorizontalFlip(), transforms.ToTensor()])
train_dataset = AdVFR(root_dir=’.’, train=True, transform=composed_transform)

while running the loader I am getting the error

KeyError Traceback (most recent call last)
in ()
5 train_dataiter = iter(train_loader)
----> 6 train_images, train_labels = train_dataiter.next()
~/miniconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py in next(self)
177 if self.num_workers == 0: # same-process loading
178 indices = next(self.sample_iter) # may raise StopIteration
–> 179 batch = self.collate_fn([self.dataset[i] for i in indices])
180 if self.pin_memory:
181 batch = pin_memory_batch(batch)
~/miniconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py in default_collate(batch)
107 elif isinstance(batch[0], collections.Sequence):
108 transposed = zip(*batch)
–> 109 return [default_collate(samples) for samples in transposed]
110
111 raise TypeError((“batch must contain tensors, numbers, dicts or lists; found {}”
~/miniconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py in (.0)
107 elif isinstance(batch[0], collections.Sequence):
108 transposed = zip(*batch)
–> 109 return [default_collate(samples) for samples in transposed]
110
111 raise TypeError((“batch must contain tensors, numbers, dicts or lists; found {}”
~/miniconda3/lib/python3.6/site-packages/torch/utils/data/dataloader.py in default_collate(batch)
96 if elem.shape == (): # scalars
97 py_type = float if elem.dtype.name.startswith(‘float’) else int
—> 98 return numpy_type_map[elem.dtype.name](list(map(py_type, batch)))
99 elif isinstance(batch[0], int):
100 return torch.LongTensor(batch)
KeyError: ‘uint32’

As far as I have got that in default_collate method of /torch/utils/data/dataloader.py it is trying to map uint32 to one of the tensor type.

numpy_type_map = {
‘float64’: torch.DoubleTensor,
‘float32’: torch.FloatTensor,
‘float16’: torch.HalfTensor,
‘int64’: torch.LongTensor,
‘int32’: torch.IntTensor,
‘int16’: torch.ShortTensor,
‘int8’: torch.CharTensor,
‘uint8’: torch.ByteTensor,
}

Can anybody help me to figure out where am I getting this ‘uint32’

Resolved the error :slight_smile: the datatype of label was uint32.

1 Like