pytorch-adda icon indicating copy to clipboard operation
pytorch-adda copied to clipboard

error about mnist data shape

Open SpiritBear000 opened this issue 5 years ago • 7 comments

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] `

SpiritBear000 avatar Jun 03 '19 08:06 SpiritBear000

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 ?

Dr-Zhou avatar Jun 25 '19 06:06 Dr-Zhou

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

mvivekc avatar Jun 26 '19 11:06 mvivekc

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

Dr-Zhou avatar Jun 26 '19 11:06 Dr-Zhou

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

mvivekc avatar Jun 26 '19 11:06 mvivekc

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

Dr-Zhou avatar Jun 26 '19 11:06 Dr-Zhou

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

mvivekc avatar Jun 26 '19 14:06 mvivekc

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

MiZhiLiang avatar Mar 16 '20 12:03 MiZhiLiang