Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error about mnist data shape #21

Open
SpiritBear000 opened this issue Jun 3, 2019 · 7 comments
Open

error about mnist data shape #21

SpiritBear000 opened this issue Jun 3, 2019 · 7 comments

Comments

@SpiritBear000
Copy link

SpiritBear000 commented Jun 3, 2019

when i run 'main.py', i got following error.

`Traceback (most recent call last):

File "Domain_Adaption/pytorch-adda/main.py", line 41, in
src_encoder, src_classifier, src_data_loader)
File "Domain_Adaption/pytorch-adda/core/pretrain.py", line 32, in train_src
for step, (images, labels) in enumerate(data_loader):
File "/envs//lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 615, in next
batch = self.collate_fn([self.dataset[i] for i in indices])
File /envs/
/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 615, in
batch = self.collate_fn([self.dataset[i] for i in indices])
File "/envs/
/lib/python3.6/site-packages/torchvision/datasets/mnist.py", line 95, in getitem
img = self.transform(img)
File "/envs/
/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 60, in call
img = t(img)
File "/envs/
/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 163, in call
return F.normalize(tensor, self.mean, self.std, self.inplace)
File "/envs/
*/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 208, 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]
`

@Dr-Zhou
Copy link

Dr-Zhou commented Jun 25, 2019

I also meet

when i run 'main.py', i got following error.

`Traceback (most recent call last):

File "Domain_Adaption/pytorch-adda/main.py", line 41, in
src_encoder, src_classifier, src_data_loader)
File "Domain_Adaption/pytorch-adda/core/pretrain.py", line 32, in train_src
for step, (images, labels) in enumerate(data_loader):
File "/envs//lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 615, in next batch = self.collate_fn([self.dataset[i] for i in indices]) File /envs//lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 615, in batch = self.collate_fn([self.dataset[i] for i in indices]) File "/envs//lib/python3.6/site-packages/torchvision/datasets/mnist.py", line 95, in getitem img = self.transform(img) File "/envs//lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 60, in call img = t(img) File "/envs//lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 163, in call return F.normalize(tensor, self.mean, self.std, self.inplace) File "/envs/*/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 208, 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]
`

I also meet the same problem。How do you solve it ?

@mvivekc
Copy link

mvivekc commented Jun 26, 2019

Seems like same as #20 but with more details. Also, i'm facing the same error.

@Dr-Zhou
Copy link

Dr-Zhou commented Jun 26, 2019

Seems like same as #20 but with more details. Also, i'm facing the same error.

you can use this solution。https://stackoverflow.com/questions/56033173/kmnist-runtimeerror-output-with-shape-1-28-28-doesnt-match-the-broadcast

@mvivekc
Copy link

mvivekc commented Jun 26, 2019

@Dr-Zhou Do you mean, solution can be provided on Stackoverflow? OR the solution is already there? -- there are no answers for the Question.

@Dr-Zhou
Copy link

Dr-Zhou commented Jun 26, 2019

you can see this。https://blog.csdn.net/weixin_43159148/article/details/88778371。but I also meet other problem

@mvivekc
Copy link

mvivekc commented Jun 26, 2019

Downgrading torch and torchvision to 0.2.0 and 0.2.1 solved this issue for me.

@MiZhiLiang
Copy link

MiZhiLiang commented Mar 16, 2020

transforms.Normalize([0.5],[0.5]) This way in my settings can work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants