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

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 128 and 32 in dimension 2 at /opt/conda/conda-bld/pytorch_1549624239588/work/aten/src/TH/generic/THTensorMoreMath.cpp:1307 #1

Open
hinash88 opened this issue Apr 1, 2019 · 1 comment

Comments

@hinash88
Copy link

hinash88 commented Apr 1, 2019

Hi there,

Thank you for sharing the code. I am new to learn GAN and when I run this code I face this following issue:

Traceback (most recent call last): File "main.py", line 341, in <module> G_log, D_log = train(epoch_max, batch_size) File "main.py", line 316, in train D_loss = train_D(real_images, real_labels) File "main.py", line 218, in train_D real_outputs = D.forward(real_images,real_labels_fill) File "main.py", line 137, in forward x = torch.cat((x, y), dim=1) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 128 and 32 in dimension 2 at /opt/conda/conda-bld/pytorch_1549624239588/work/aten/src/TH/generic/THTensorMoreMath.cpp:1307

My batch size is 16 and i am running the code for 2 classes with 698 and 500 images respectively. My input images are 256x256 and I did not change any other parameter. These are the size of my x and y respectively where the problem occurs (main.py line 137)

torch.Size([16, 64, 128, 128]) torch.Size([16, 64, 32, 32])

Another problem is this code gives error when more than 2 classes are arranged in data folder.

Any kind of help is much appreciated!!!

@hinash88
Copy link
Author

hinash88 commented Apr 1, 2019

Got it solved. The input image must be 64x64 in size. Replace this code:

data_transform = transforms.Compose([transforms.ToTensor()])

with the following:
img_size = 64

data_transform = transforms.Compose([transforms.Resize(img_size), transforms.CenterCrop(img_size), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5)),])

But still could not figure out how to deal with more than 2 classes :(

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

1 participant