# Source code for torchreid.utils.avgmeter

    from __future__ import absolute_import
    from __future__ import division

    __all__ = ['AverageMeter']

    class AverageMeter(object):
        """Computes and stores the average and current value.

        Examples::
            >>> # Initialize a meter to record loss
            >>> losses = AverageMeter()
            >>> # Update meter after every minibatch update
            >>> losses.update(loss_value, batch_size)
        """
        def __init__(self):
            self.reset()

        def reset(self):
            self.val = 0
            self.avg = 0
            self.sum = 0
            self.count = 0

        def update(self, val, n=1):
            self.val = val
            self.sum += val * n
            self.count += n
            self.avg = self.sum / self.count