Change dimensions of image when creating custom dataloader in pytorch
I was training my CNN on the CIFAR10 dataset. I extracted the 50,000 images of dimensions (32 x 32 x 3) and read them in a list. I converted them into numpy arrays and stored them in a list.  I did the same with the labels for my training and testing.

I then constructed my CNN of two layers and a single FC in pytorch. Before doing this I created my own custom data loader. While doing so, the dimensions of the image that I am feeding in it are changing. The dimensions (32 x 32 x 3) are changing to (3 x 32 x 32) and I am not being able to train my neural network.

tensor_x = torch.stack([torch.Tensor(i) for i in train_images])
tensor_y = torch.stack([torch.Tensor(i) for i in train_labels])
dataset = data_utils.TensorDataset(tensor_x , tensor_y)
train_dataloader = data_utils.DataLoader(dataset=dataset)

tensor_x = torch.stack([torch.Tensor(i) for i in test_images])
tensor_y = torch.stack([torch.Tensor(i) for i in test_labels])
dataset = data_utils.TensorDataset(tensor_x , tensor_y)
test_dataloader = data_utils.DataLoader(dataset=dataset)




RuntimeError: Given groups=1, weight[64, 3, 3, 3], so expected input[1, 32, 32, 3] to have 3 channels, but got 32 channels instead


In PyTorch image, the channels come first, so your image should be 3, 32, 32 and not 32, 32, 3.

If image is a numpy array, then you can do something like this 

image = image.transpose((2, 0, 1))

