Error: inner dimensions differ

Hi guys, I am very new to pytorch. I am trying to build an NN for digit and alphabet recignition with ReLU as the recognition function. The error message confuses me a lot. I am wondering if it has anything to do with my images in the dataset (torch.Size([64, 3, 32, 32])). I would appreciate any type of hint and help.
Thanks in advance:)

Flatten (64, 3, 32, 32) would be (64, 3072).
If you want to use nn.Linear as you wrote, in_feature should be 3072 which is the same as your input dimension.

In short, the first ‘nn.Linear’ should be
nn.Linear(3072, 512) instead of nn.Linear(1024, 512)

1 Like

Thanks for the explanation. Sounds like linear is not the best approach here, is there a better way to set up the network for 3 dimensional image?

Convolution is the most popular way to do that.
See Training a Classifier — PyTorch Tutorials 1.13.1+cu117 documentation
to know how to classify the image with cifar10 tutorial

1 Like