DANN: RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]
When I run your code, I have met a error when executing data_source = data_source_iter.next()
:
RuntimeError: output with shape [1, 28, 28] doesn’t match the broadcast shape [3, 28, 28].
I have no idea why this error occurs. Could you please give some suggestions. Besides, I’m using Python3.6 and Pytorch 1.0. My operating system is Ubuntu 16.04. Thanks.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 23 (8 by maintainers)
Commits related to this issue
- fix the shape mismatch in #8 — committed to fungtion/DANN by fungtion 5 years ago
- fix transform У меня была такая ошибка: `RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]` Вот [тут](https://github.com/fungtion/DANN/issues/8#issuecomm... — committed to alex13sh/pytorch-mnist-GAN by alex13sh 4 years ago
I’m working on Ubuntu 16.04 version and using torch version 1.3.1 It’s that MNIST data set consists of grey images.
transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5)), ])
can be changed to
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))])
Let me clarify, if the img has three channels, you should have three number for mean, for example, img is RGB, mean is [0.5, 0.5, 0.5], the normalize result is Rx0.5, Gx0.5, Bx0.5. If img is grey type that only one channel, so mean should be [0.5], the normalize result is R*0.5
Downgrading torch and torchvision to 0.2.0 and 0.2.1 solved this issue for me.
Ooooooh, finally, I run the code successfully. I add a new transform like this
And I replace the original transform of source data
mnist
withimg_transform1
. By do so, themnist
images can be converted to [3, *, *] tensors. I am curious about why the code is OK under your settings. In my opinion, is there a difference abouttorchvision.datasets.MNIST()
function between torch 0.4 and torch 1.0???