The result is a bit weird. Could you run some sanity checks and see, what numbers total_train and correct_train have after a couple of iterations?
The second approach would only calculate the accuracy of the last batch, if I’m not mistaken.