[02_pytorch_classification.ipynb] | RuntimeError: mat1 and mat2 shapes cannot be multiplied (200x5 and 2x5) #232
-
I was practicing the section, 02_pytorch_classification.ipynb and faced this issue. I used the same code from the google colab but the problem persists. # Make predictions with the model
untrained_preds = model_0(X_test.to(device))
print(f"Length of predictions: {len(untrained_preds)}, Shape: {untrained_preds.shape}")
print(f"Length of test samples: {len(Y_test)}, Shape: {Y_test.shape}")
print(f"\nFirst 10 predictions:\n{untrained_preds[:10]}")
print(f"\nFirst 10 test labels:\n{Y_test[:10]}") Error:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
As you can see the error is :
meaning that the shape of your matrices are not correct. You cannot multiply two matrices that the number of columns in the first matrix is not equal to the number of rows in the second matrix |
Beta Was this translation helpful? Give feedback.
-
Hi @prince-kha, @AlienSarlak is correct, the tensors you're trying to put into the network are incorrect shapes. I'd check the shapes of all of your inputs and make sure they line up with the matrix multiplication rule: https://www.learnpytorch.io/00_pytorch_fundamentals/#matrix-multiplication-is-all-you-need |
Beta Was this translation helpful? Give feedback.
Hi @prince-kha,
@AlienSarlak is correct, the tensors you're trying to put into the network are incorrect shapes.
I'd check the shapes of all of your inputs and make sure they line up with the matrix multiplication rule: https://www.learnpytorch.io/00_pytorch_fundamentals/#matrix-multiplication-is-all-you-need