That’s cool, cuts out the extra computation.
However, the batch by batch implementation is useful if logging the metrics after N batches rather than at the end of the epoch. You can simply divide the running loss by the num_images at any number of iterations to get current average.
However, if averaging is done only at the end of each epoch, your code is just okay.