L1aoXingyu / pytorch-beginner

pytorch tutorial for beginners
3k stars 1.09k forks source link

RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28] #31

Open taiji1985 opened 5 years ago

taiji1985 commented 5 years ago

RuntimeError: Caught RuntimeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop data = fetcher.fetch(index) File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batchedindex] File "/usr/local/lib/python3.6/dist-packages/torchvision/datasets/mnist.py", line 95, in getitem img = self.transform(img) File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py", line 70, in call img = t(img) File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py", line 175, in call return F.normalize(tensor, self.mean, self.std, self.inplace) File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/functional.py", line 217, in normalize tensor.sub(mean[:, None, None]).div_(std[:, None, None]) RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]

taiji1985 commented 5 years ago

conv_gan.py

hai-h-nguyen commented 5 years ago

I fixed it by replacing the transform part by:

img_transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,)) ])