RuntimeError: Variable data has to be a tensor, but got tuple

Dear All,
This relates to one of my earlier posts (Custom data loader and label encoding with CIFAR-10 - #3 by QuantScientist), but it deserves a new thread.

When I iterate the Data set during training, like so:

for i, (inputs, labels) in enumerate(train_loader):
print (type(inputs))
print (type(labels))
print (“Label:” + str(labels))

The labels return 4 items as a tuple instead of only one Item (for instance, “dog”). I understand that the problem is with my data loader however I can not seem to figure out which line of code is the culprit.

The full code is here:
https://github.com/QuantScientist/Deep-Learning-Boot-Camp/blob/master/day%2002%20PyTORCH%20and%20PyCUDA/PyTorch/21-PyTorch-CIFAR-10-Custom-data-loader-from-scratch.ipynb

And this is the exception:

Many thanks for any help!

turn your label to a number,i.e frog->0,truck->1, and then turn them to a tensor.

Thanks Chen, I found this yesterday, used defaultdict(LabelEncoder) and updated the Notebooke: https://github.com/QuantScientist/Deep-Learning-Boot-Camp/blob/master/day%2002%20PyTORCH%20and%20PyCUDA/PyTorch/21-PyTorch-CIFAR-10-Custom-data-loader-from-scratch.ipynb

I was surprised since PyTorch can work with class labels which are not encoded, but when you write a Custom dataset it actually forces you to do so (e.g. encode)

Actually Dataset and DataLoader are not so complicated. I would strongly advise you to read


and