-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
75 lines (61 loc) · 1.61 KB
/
util.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class AverageMeter(object):
"""Computes and stores the average and current value.
ref: https://github.com/chrischute/glow/blob/master/util/shell_util.py
"""
def __init__(self):
self.val = 0.
self.avg = 0.
self.sum = 0.
self.count = 0.
self.val1 = 0.
self.avg1 = 0.
self.sum1 = 0.
self.count1 = 0.
self.val2 = 0.
self.avg2 = 0.
self.sum2 = 0.
self.count2 = 0.
self.val3 = 0.
self.avg3 = 0.
self.sum3 = 0.
self.count3 = 0.
def reset(self):
self.val = 0.
self.avg = 0.
self.sum = 0.
self.count = 0.
def reset1(self):
self.val1 = 0.
self.avg1 = 0.
self.sum1 = 0.
self.count1 = 0.
def reset2(self):
self.val2 = 0.
self.avg2 = 0.
self.sum2 = 0.
self.count2 = 0.
def reset3(self):
self.val3 = 0.
self.avg3 = 0.
self.sum3 = 0.
self.count3 = 0.
def update(self, val, n=1):
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
def update1(self, val, n=1):
self.val1 = val
self.sum1 += val * n
self.count1 += n
self.avg1 = self.sum1 / self.count1
def update2(self, val, n=1):
self.val2 = val
self.sum2 += val * n
self.count2 += n
self.avg2 = self.sum2 / self.count2
def update3(self, val, n=1):
self.val3 = val
self.sum3 += val * n
self.count3 += n
self.avg3 = self.sum3 / self.count3