Hey @pdobosh, welcome to the DeepLearning.AI community!
I get nothing of the sort when running the notebook
From that error message, it seems that your problem is with crit_loss.item()
.
torch.Tensor.item
only works for tensors with one element (c.f. documentation), so I believe your crit_loss
has more than just one element.
This crit_loss
comes from the get_crit_loss
function just above, so that must be returning a tensor with multiple elements.
Now, this might be because of a problem in the function itself, or its inputs — which themselves come from other functions you implemented.
One of your functions is not behaving as it should, and you’ll have to investigate it.
This should have been covered by the unit tests, but it seems that you may have found a loophole
Here are the expected shapes for some of the variables in that last code cell:
epsilon.shape = torch.Size([128, 1, 1, 1])
gradient.shape = torch.Size([128, 1, 28, 28])
gp.shape = torch.Size([])
crit_loss.shape = torch.Size([])
gp
and crit_loss
are both be scalars.
Try to see which of these is not a match for you, and investigate the function it’s coming from.
If you’re still stuck, feel free to come back with more questions or a screenshot of your tensor shapes and the function you think is not correct.
If you do find the fix, let us know what it was so we can adapt the unit test accordingly as well.
Hope this helps you, cheers!