section 3: shape error #612
-
I try to pass a random tensor through FashionMNISTModelV2 but it always comes up with the same error. In the viedeo it also appears but is fixed by "hidden_unitits * 7 * 7" which is not the case for me. Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 I hope this helps and please correct me if I`m wrong. |
Beta Was this translation helpful? Give feedback.
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 ofmodel_2(random_image_tensor)
I hope this helps and please correct me if I`m wrong.