I cant get the deimensions of the input right

I’ m trying to implement a simple classification network where images are of size 33x33

However, I’m getting the following error:
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [3, 1, 5, 5], but got 3-dimensional input of size [4, 33, 33] instead

Can someone tell me how to make the inputs match my image? Also why is the input [4,33,33] and not [33,33] ? Is it because I used a batch size of 4?

Yes !

If you are using convnets, then you must explicitly tell how many channels your image has. In your case, I guess you should do something like tensor_training_x = tensor_training_x.unsqueeze(1) to get a tensor of size N x 1 x 33 x 33.

I hope it helps !

You may get errors from the fact that you flatten your feature maps to pass it to a dense layer. This means that your architecture doesn’t allow arbitrary image sizes as inputs. You should do some debugging to get the dimensions right. For instance, try putting a print(x.size()) after your second convolution in your forward method. For it to work you should get a feature map of shape [5, 5, 10].

Hey thanks for your reply! I had some problems with this website and didn’t see any of your replies when I first asked my question. Also I wasn’t allowed edit my post or post more than one image at a time so I just gave up. This time hopefully it works better.

So I’ll just summarize what I’m trying to do. I have a dataframe that is 23000x1090 . Each row corresponds to a different image. The first line of the row is the label and the rest (1089=33x33) is the pixel values:

There are 23 differend classes and each class is made up of 1000 images. The first 1000 images are all class A, second thousand class B etc. My trainset will be created from the first 900 and testset from the last 100:

I then construct the testset, trainset and the loaders:

This is the network:

But when i do this:

This is the error:

If I convert the values inside the tensors to Long I get a different error (can post that too if this post works).

Can you tell me what I should do please?