DCGAN issue with training with input size/shape

Hello I am working on learning how to build GANS and was trying Pytroch DCGAN from both the training material and from a GitRepo I found.

I am using Kaggle to run this and this is my code right now

Everything seems to be fine with my dataset and my dataloaders but not with the training. I copied the code as I was running into errors thinking it was my implementation of it, but still had the same issue.

RuntimeError: Expected 4-dimensional input for 4-dimensional weight [64, 3, 4, 4], but got 3-dimensional input of size [3, 64, 64] instead

I know what this means but when i look at what my dataloader is producing it is fine [batch_size, 3, 64, 64]
So that should work out fine I would think.

I not quite sure what is going wrong with this.

Here are the place where I am working from for the code

Thank you for any help with this.

It seems the posted Kaggle Kernel runs without any issues or am I missing the error message?
In any case, as you’ve already described, the batch dimension is missing, so you could check, if you are indexing the batch somewhere before passing it to the conv layer.

1 Like

I was working on this for a bit, and found out what the error was and it was two things I was doing wrong.
The first was the label i made needed to be a float like this

real_label = 1.0
fake_label = 0.0

And then by following the other code lead me down a wrong road
The error came from this line

real_cpu = data[0].to(device)

And I fixed it by simple doing this

real_cpu = data.to(device)

I still dont know how to tutorial and the github code I looked at worked then.
I appreciate you looking at this.