Monitoring#
- class kornia.metrics.AverageMeter[source]#
Keep the running average of a metric over batches.
stats = AverageMeter()starts empty;stats.update(val, n)adds a value that stands fornsamples, andstats.avgreturns theirn-weighted mean as a Python float.- Convention:
update(val, n)addsval * ntosumandntocount, soavgis the mean over samples when everyvalis a batch mean andnits batch size.valkeeps the last value passed, unweighted.Values are not rescaled:
accuracy()percentages average to a percentage. A tensorvalkeepssuma tensor that holds its autograd graph; pass a detached tensor or a Python number to avoid keeping it.Float16 and bfloat16 values are weighted and accumulated in float32. Later updates can promote the accumulator to a wider dtype;
valalways retains the original value and dtype.
See also
accuracy(): a batch metric to feed it, as a percentage.
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