importtime,sysimportnumpyasnpclassAverageMeter(object):"""Computes and stores the average and current value"""def__init__(self):self.reset()defreset(self):self.val=0.0self.avg=0.0self.sum=0.0self.count=0.0defupdate(self,val,n=1):self.val=valself.sum+=val*nself.count+=nself.avg=self.sum/self.countdef__repr__(self):return('{name}(val={val}, avg={avg}, count={count})'.format(name=self.__class__.__name__,**self.__dict__))