Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3 - Making Predictions Method from Chapter 2 does not work #78

Closed
Mahosaurus opened this issue Nov 16, 2022 · 4 comments
Closed

Comments

@Mahosaurus
Copy link

Mahosaurus commented Nov 16, 2022

Replacing the model from Chapter 2 with the one of Chapter 3, results in the following message when the prediction algorithm is called:
RuntimeError: mat1 and mat2 shapes cannot be multiplied (256x36 and 9216x4096)
EDIT: Found solution, using .unsqueeze(0)

@MarcusFra
Copy link
Contributor

Hi @Mahosaurus!
Could you please elaborate a bit more what issue has arisen?
Did you need to replace the model in order to run the code?
Have you replaced the code line

img = torch.unsqueeze(img, 0)

in https://github.com/falloutdurham/beginners-pytorch-deep-learning/blob/master/chapter2/Chapter%202.ipynb?

If you still have the stacktrace I'd be thankful if you can share it.

@MarcusFra
Copy link
Contributor

Ah, sorry my fault. You were referring to chapter 3. World you like to share your whole notebook with your solution?

@Mahosaurus
Copy link
Author

Mahosaurus commented Nov 22, 2022

Hi @MarcusFra: Thanks for responding. I cant share the notebook as I have been using it for further experimentation.
The prediction part for chapter 3, I changed as follows in comp to chapter 2.


img = Image.open("file.jpg") 
img = img_transforms(img).unsqueeze(0)

prediction = F.softmax(alexcnnmodel(img))
prediction = prediction.argmax()

labels[prediction]

@Mahosaurus
Copy link
Author

@MarcusFra : My mistake was to look into the old repository and mix the code up. This one here has the correct syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants