I am learning how to use Pytorch following the official tutorial: https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html 3
Everything went smoothly until I ran the CIFAR10 classification example.(I didn’t modify the code at all)
The error message:
Traceback (most recent call last):
  File "/tmp/pycharm_project_331/main.py", line 90, in <module>
    for i, data in enumerate(trainloader, 0):
  File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 286, in __next__
    return self._process_next_batch(batch)
  File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 307, in _process_next_batch
    raise batch.exc_type(batch.exc_msg)
TypeError: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 57, in _worker_loop
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/usr/local/lib/python3.5/dist-packages/torch/utils/data/dataloader.py", line 57, in <listcomp>
    samples = collate_fn([dataset[i] for i in batch_indices])
  File "/usr/local/lib/python3.5/dist-packages/torchvision/datasets/cifar.py", line 121, in __getitem__
    img = self.transform(img)
  File "/usr/local/lib/python3.5/dist-packages/torchvision/transforms/transforms.py", line 49, in __call__
    img = t(img)
  File "/usr/local/lib/python3.5/dist-packages/torchvision/transforms/transforms.py", line 143, in __call__
    return F.normalize(tensor, self.mean, self.std)
  File "/usr/local/lib/python3.5/dist-packages/torchvision/transforms/functional.py", line 165, in normalize
    raise TypeError('tensor is not a torch image.')
TypeError: tensor is not a torch image.

I thought maybe I miss some codes, but the code is fine. So I ran the code again for a few more times. The error message disappear somehow, and the training went smoothly.
I can’t find any pattern to replicate the error. It just pops up whenever I change the code, and fixed itself without any code modification.
I configured PyCharm to connect to a remote interpreters via SSH(an Ubuntu server), but the same thing occurred when I’m using a local interpreter, and running the code via python console.
This is so frustrating since I have no idea if my code is wrong or it’s just the same thing happening.