Type of train_labels in CIFAR10 and MNIST

Type of train_labels and train_data in CIFAR10 are <type ‘list’> and <type ‘numpy.ndarray’> respectively. While they are <class ‘torch.LongTensor’> and <class ‘torch.ByteTensor’> in MNIST. Why did you choose different types for different datasets? Both is fine of course, I just wanted to know if there is any specific reason for these choices.
Thanks.

I think it is because MNIST is provided as a CSV in which the first column is the label and the other 784 columns are the pixels, while for cifar10 (https://www.kaggle.com/c/cifar-10) images and class labels are provided separately. Of course, you can write your own Dataset loader.

Is it normal that I get when working with MNIST because of that type of tensor?

RuntimeError: Expected object of type torch.FloatTensor but found type torch.ByteTensor for argument #4 ‘mat1’

It is just a simple Linear layer.

It seems you loaded the images as uint8 and just transformed them into tensors.
If you are using the torchvision.datasets.MNIST data, you can just pass a transformation to it:

dataset = datasets.MNIST(
    root=YOUR_PATH,
    download=False,
    transform=transforms.ToTensor())

Otherwise you should call x = x.float() on the image tensor.

1 Like