Getting Error (is invalid for input of size 102400)

I am trying to implement the GAN on CIFAR 10 data set.

I am following this tutorial The actual tutorial was on MNIST but I am doing this on CIFAR Data Set.

The code is below:

‘’'sample_vectors = torch.randn(batch_size, latent_size).to(device)

def save_fake_images(index):
fake_images = G(sample_vectors)
fake_images = fake_images.reshape(fake_images.size(0), 3, 32,32)
fake_fname = ‘fake_images-{0:0=4d}.png’.format(index)
print(‘Saving’, fake_fname)
save_image(denorm(fake_images), os.path.join(sample_dir, fake_fname), nrow=10)

Before training

Image(os.path.join(sample_dir, ‘fake_images-0000.png’))‘’’

I am getting this error "shape ‘[100, 3, 32, 32]’ is invalid for input of size 102400 "
100 is a batch size
3 is numbe of channel
32 is the size
I have the idea that I had to reshape the tensor in to 3 dimension Since I am new to Pytorch .

if I change the dimension from 3 to 1 this block of code will run but later in the training loop it shows the error and I am sure the error is because of the previous issue.

Error which is shows in trainging loop.

mat1 and mat2 shapes cannot be multiplied (100x3072 and 1024x256)

Based on the error:

I am getting this error "shape ‘[100, 3, 32, 32]’ is invalid for input of size 102400 "

it seems your output might have a single channel and have the shape [100, 1, 32, 32] which would correspond to 102400 elements.

This error is raised in a linear layer, which expects 1024 input features, while your input activation has 3072 features. Change in_features to 3072 in this layer and it should work.

Dear @ptrblck Thank you for the response.

since the code which I was using as the tutorial is has the data set of MNIST which has one channel and cifar images has 3 channels.

I was giving wrong input I thought

32 * 32 = 1024 but I forgot that it has 3 channels
so I need to multiply it by three

32 *32 * 3 = 3072

so now my code is working.

Thank you for pointing out at right direction