Custom data loader and label encoding with CIFAR-10

I am trying to use a Dataset loader in order to load the CIFAR-1O data set from a local drive.
For learning purposes, I do NOT wish to use the already available loader as shown here:

E.g. torchvision.datasets.CIFAR10.

I downloaded the data manually from here:

Few questions:

  1. Using the original example, I can see that the original labels, are NOT one hot encoded, do I assume correctly that
    cross-entropy and neg. log-likelihood losses in pytorch do NOT require one-hot encodings?

  2. In my custom code (, I can see that the data as well as the labels are loaded correctly, when I tried (wrongly?) to one hot encode them, an exception was thrown during iteration.

However, now I do not one hot encode them (assuming 1 above is true), and the following exception is thrown while iterating the dataset:

TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S55') dtype('S55') dtype('S55')

This is the code for iterating:

for i, data in enumerate(train_loader, 0):'i=%d: '%(i))
images, labels = data
num = len(images)

ax = plt.subplot(1, imagesToShow, i + 1)
ax.set_title('Sample #{}'.format(i))

for n in range(num):
    plt.imshow (GenericImageDataset.flaotTensorToImage(image))
if i==imagesToShow-1:

Thanks for any help,

yes,they don’t require

I have a rough look at your code, the bug seems come from self.X_train, self.X_train[index] is not string

1 Like

Had several other issues,
I have a basic working version here:

Now if my batch size is larger than 1, the images wont display :slight_smile:

torchvision.utils.make_grid would help