meter.py 455 B

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