pytorch报错:RuntimeError: mat1 and mat2 shapes cannot be multiplied (64x2500 and 3020x1600)

I believe that students will always encounter similar problems when they are new to deep learning:

This is actually the problem that the number of parameters between the convolutional layer and the fully connected layer does not correspond.

The output result of the convolutional layer is a matrix of 64*2500, so the first layer of the fully connected layer should be: 2500*n

This way two matrices can be multiplied together:

Legend: (Borrowing from other people's pictures@知诺史博)

Two matrices can be multiplied, the number of columns of the first matrix must be equal to the number of rows of the second matrix

 

 Find the wrong line:

 Then find the function used in this line:

self.liner(x)

 

 It is easy to find the place where the error is reported. His error is that 64x2500 and 3020x1600 cannot be multiplied

mat1 and mat2 shapes cannot be multiplied (64x2500 and 3020x1600)

solution:

1. Change the structure of the convolutional layer so that the final output is equal to 3020, but this is too troublesome and not recommended

self.linear = torch.nn.Linear(3020, 1600, True)

2. Directly change  3020 in the above code to 2500

self.linear = torch.nn.Linear(2500, 1600, True)

If there is any help for the beginners, please give me a thumbs up! ! !

Guess you like

Origin blog.csdn.net/weixin_53374931/article/details/130139764