Monitoring#

class kornia.metrics.AverageMeter[source]#

Computes and stores the average and current value.

Convention:
  • update(val, n) adds val * n to sum and n to count, so avg is the n-weighted mean: the mean over samples when every val is a batch mean and n its batch size. val keeps the last value passed, unweighted.

  • Values are not rescaled: accuracy() percentages average to a percentage. A tensor val keeps sum a tensor that holds its autograd graph; pass a detached tensor or a Python number to avoid keeping it.

Example

>>> stats = AverageMeter()
>>> acc1 = torch.tensor(99.0)  # top-1 accuracy of a batch in percent, as in K.metrics.accuracy(...)[0]
>>> stats.update(acc1, n=1)  # where n is batch size usually
>>> round(stats.avg, 2)
99.0