Hi Kaustubh!



 Kaustubh_Kulkarni:

            matches = [torch.argmax(i) == torch.argmax(j) for i, j in zip(outputs, y)]
    
            loss = loss_fn(outputs, y)



These two lines of code are in conflict with one another.
Your loss_fn, CrossEntropyLoss, expects its outputs argument to
have shape [nBatch, nClass], and its y argument to have shape
[nBatch] (no class dimension).
On the other hand, your torch.argmax(i) == torch.argmax(j)
test suggests that outputs and y have the same shape.  I’m guessing
that your y has shape [nBatch] (because you don’t report that
CrossEntropyLoss has thrown an error), and therefore that your
matches test is incorrect.
What you want is for outputs to have shape [nBatch, nClass] (and
be the predicted logits for the nClass classes), and for y to have
shape [nBatch] and be integer class labels for each of the samples
in the batch.  Then you want your test to be:
matches = (torch.argmax (outputs, dim = 1) == y).sum()

matches will now be the number of correct predictions in your batch.
Best.
K. Frank