I am playing around with making several different data loaders using different transformations and methods and got this error
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 280 and 499 in dimension 2 at /opt/conda/conda-bld/pytorch_1579022034529/work/aten/src/TH/generic/THTensor.cpp:612
When I am trying to use the data loaders.
So the basic code for one of them looks like this (which is giving the error but all of them do too)
basic = transforms.Compose([transforms.ToTensor()])
basic_train_dataset = datasets.ImageFolder(TRAIN_DIR, transform=basic)
data, lable = next(iter(basic_train_dataset))
print(lable) #This works fine
BATCH_SIZE = 20
NUM_WORKERS = 0
VALIDATION_SIZE = 0.15
basic_train_loader = DataLoader(basic_train_dataset, batch_size=BATCH_SIZE, shuffle=False, num_workers=NUM_WORKERS)
basic_dataiter = iter(basic_train_loader)
images, labels = basic_dataiter.next() # The error is thrown here
print(labels)
Here is the whole code I am working on.
https://www.kaggle.com/matthewmillar/pytorchdataloaderexamples/edit
and here is the whole stack trace
RuntimeError Traceback (most recent call last)
<ipython-input-30-91a907a2cbb6> in <module>
1 # Simple visuzlization for dataloaders to check what they are producing.
2 basic_dataiter = iter(aug_train_loader)
----> 3 images, labels = basic_dataiter.next()
4 print(labels)
/opt/conda/lib/python3.6/site-packages/torch/utils/data/dataloader.py in __next__(self)
343
344 def __next__(self):
--> 345 data = self._next_data()
346 self._num_yielded += 1
347 if self._dataset_kind == _DatasetKind.Iterable and \
/opt/conda/lib/python3.6/site-packages/torch/utils/data/dataloader.py in _next_data(self)
383 def _next_data(self):
384 index = self._next_index() # may raise StopIteration
--> 385 data = self._dataset_fetcher.fetch(index) # may raise StopIteration
386 if self._pin_memory:
387 data = _utils.pin_memory.pin_memory(data)
/opt/conda/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
45 else:
46 data = self.dataset[possibly_batched_index]
---> 47 return self.collate_fn(data)
/opt/conda/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py in default_collate(batch)
77 elif isinstance(elem, container_abcs.Sequence):
78 transposed = zip(*batch)
---> 79 return [default_collate(samples) for samples in transposed]
80
81 raise TypeError(default_collate_err_msg_format.format(elem_type))
/opt/conda/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py in <listcomp>(.0)
77 elif isinstance(elem, container_abcs.Sequence):
78 transposed = zip(*batch)
---> 79 return [default_collate(samples) for samples in transposed]
80
81 raise TypeError(default_collate_err_msg_format.format(elem_type))
/opt/conda/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py in default_collate(batch)
53 storage = elem.storage()._new_shared(numel)
54 out = elem.new(storage)
---> 55 return torch.stack(batch, 0, out=out)
56 elif elem_type.__module__ == 'numpy' and elem_type.__name__ != 'str_' \
57 and elem_type.__name__ != 'string_':
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 280 and 499 in dimension 2 at /opt/conda/conda-bld/pytorch_1579022034529/work/aten/src/TH/generic/THTensor.cpp:612
Thanks for any help with this.