misc.py 939 Bytes
Newer Older
Hang Zhang's avatar
Hang Zhang committed
1
2
3
4
5
6
7
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## Created by: Hang Zhang
## Email: zhanghang0704@gmail.com
## Copyright (c) 2020
##
## LICENSE file in the root directory of this source tree 
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hang Zhang's avatar
Hang Zhang committed
8
9
import warnings

Hang Zhang's avatar
Hang Zhang committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
__all__ = ['AverageMeter', 'EncodingDeprecationWarning']

class AverageMeter(object):
    """Computes and stores the average and current value"""
    def __init__(self):
        self.reset()

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

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

    @property
    def avg(self):
        avg = 0 if self.count == 0 else self.sum / self.count
        return avg
Hang Zhang's avatar
Hang Zhang committed
31
32
33
34
35

class EncodingDeprecationWarning(DeprecationWarning):
    pass

warnings.simplefilter('once', EncodingDeprecationWarning)