Help me with the reasoning because I am at the moment a bit lost since I saw many different approaches.
I need to calculate accuracy the best possible way, let’s use some of the predefined datasets in PyTorch like cifar10, cifar100, … so single label classification problem.
I saw many different approaches. What is the best approach.
approach 1 (keep track of correct and total labels on cpu)
I think this approach is not optimal because you need to convert to cpu to some numpy array possible the number of correct examples. Why not keeping it on gpu.
approach 2 (using the formula for a single batch)
It may be just the correct labels we need. The totals we may get based on the batch enumerator and batch size.
However, this is a single batch accuracy formula.
def accuracy(preds, true): 
   preds = preds.argmax(dim=-1) 
   return (preds==true).float().mean()

This can work for all full dataset  if we concatentate preds and true arrays.
I also think this is a wrong approach for cifar10, or ciffar100 because just keeping the single number of correct is enough.
You are welcome to comment.