-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
54 lines (44 loc) · 1.37 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# class AverageMeter(object):
# """Computes and stores the average and current value"""
# def __init__(self):
# self.initialized = False
# self.val = None
# self.avg = None
# self.sum = None
# self.count = None
# def initialize(self, val, weight):
# self.val = val
# self.avg = val
# self.sum = val * weight
# self.count = weight
# self.initialized = True
# def update(self, val, weight=1):
# if not self.initialized:
# self.initialize(val, weight)
# else:
# self.add(val, weight)
# def add(self, val, weight):
# self.val = val
# self.sum += val * weight
# self.count += weight
# self.avg = self.sum / self.count
# def value(self):
# return self.val
# def average(self):
# return self.avg
# def summation(self):
# return self.sum
class AverageMeter(object):
"""Computes and stores the average and current value"""
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