Thank you a lot for taking the time to help me.
My idea was to use accuracy_temp to compute the average accuracy over each batch and then sum over all the computed accuracy_temp and divide by the number of batches (which I thought to be equal to len(dataloader)) to compute the overall accuracy.
I realize now that this is correct only if the number of elements in each batch is constant, which is not necessarily true. I will change the code in order to count the total number of correctly predicted samples along all batches, and divide by the total number of samples only after the for loop.
Regarding your question, I think that if the network predicted half of the elements in every batch correctly, I would get 0.5 as accuracy as expected, but maybe the code is not doing what I thought…
With respect to the loss function, I applied a similar reasoning: I wanted to compute the loss for each element and divide it by the number of elements in the dataset, and since I am working with batches, I thought of averaging it over the number of batches. What would be the common way of computing the loss value?
I hope this answer your questions.