I am getting following error when using MNIST dataset in Torchvision
RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]
Here is my code:
import torch
from torchvision import datasets, transforms
transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
])
trainset = datasets.MNIST('~/.pytorch/MNIST_data/', download=True, train=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)
images, labels = next(iter(trainloader))
MNIST
dataset has only 1 channel. You need to changetransforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
(it is for 3 channels) – Selway