meters.py 497 B

1234567891011121314151617181920212223
  1. from __future__ import absolute_import
  2. class AverageMeter(object):
  3. """Computes and stores the average and current value"""
  4. def __init__(self):
  5. self.val = 0
  6. self.avg = 0
  7. self.sum = 0
  8. self.count = 0
  9. def reset(self):
  10. self.val = 0
  11. self.avg = 0
  12. self.sum = 0
  13. self.count = 0
  14. def update(self, val, n=1):
  15. self.val = val
  16. self.sum += val * n
  17. self.count += n
  18. self.avg = self.sum / self.count