Skip to content
Discussion options

You must be logged in to vote

I'm not totally sure as I am also going through the course and got this error but I believe it has to do with squeezing the tensor. When looking at the documentation (https://pytorch.org/docs/stable/generated/torch.nn.Flatten.html) you can see that nn.Flatten does not flatten the first dimension to 1 by default so if you have not created the extra 1 dimension with the unsqueeze you`ll end up with a tensor of 10x49 instead of 1x490.

In other words when passing the image through the model do model_2(rand_image_tensor.unsqueeze(0)) instead of
model_2(random_image_tensor)

I hope this helps and please correct me if I`m wrong.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mrdbourke
Comment options

Answer selected by mrdbourke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants