Pytorch RuntimeError

Error Log information:


RuntimeError: Caught RuntimeError in DataLoader worker process 2.
Original Traceback (most recent call last):
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py”, line 178, in _worker_loop
data = fetcher.fetch(index)
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py”, line 47, in fetch
return self.collate_fn(data)
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py”, line 74, in default_collate
return {key: default_collate([d[key] for d in batch]) for key in elem}
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py”, line 74, in
return {key: default_collate([d[key] for d in batch]) for key in elem}
File “/home/hong/anaconda3/envs/pytesseract/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py”, line 55, in default_collate
return torch.stack(batch, 0, out=out)
RuntimeError: invalid argument 0: Tensors must have same number of dimensions: got 3 and 4 at /pytorch/aten/src/TH/generic/THTensor.cpp:603


when I add one image and it’s label into my datasets , the error happens…
but before the addition it works OK and the added data seems no problem …
the error happens because the tqdm fetchs the data but get error information …

would Someone please do me a favor?

The error is raised if your Dataset is returning tensors with a variable shape or a different number of dimensions.
In your case it seems that a some tensors have 3 dimensions while others have 4.
Could you check that and let us know if you get stuck?