MNIST labels are not of size (batch_size, num_classes)

Hi, so I am messing around with some datasets when suddenly I got a size error. This normally does not happen, so I check the shapes of the data and targets.

The shape of the MNIST targets is of size (batch_size), no classes anywhere.

x, y = iter(train_loader).next()
print(y.shape)
torch.Size([32])

Is this a bug with PyTorch, or am I missing something?

The tensor y will contain the target class index(from 0-9) instead of one hot encoded vector. That’s why the shape is of batch_size.

1 Like