forked from Julie-tang00/Point-BERT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AverageMeter.py
42 lines (36 loc) · 1.33 KB
/
AverageMeter.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
class AverageMeter(object):
def __init__(self, items=None):
self.items = items
self.n_items = 1 if items is None else len(items)
self.reset()
def reset(self):
self._val = [0] * self.n_items
self._sum = [0] * self.n_items
self._count = [0] * self.n_items
def update(self, values):
if type(values).__name__ == 'list':
for idx, v in enumerate(values):
self._val[idx] = v
self._sum[idx] += v
self._count[idx] += 1
else:
self._val[0] = values
self._sum[0] += values
self._count[0] += 1
def val(self, idx=None):
if idx is None:
return self._val[0] if self.items is None else [self._val[i] for i in range(self.n_items)]
else:
return self._val[idx]
def count(self, idx=None):
if idx is None:
return self._count[0] if self.items is None else [self._count[i] for i in range(self.n_items)]
else:
return self._count[idx]
def avg(self, idx=None):
if idx is None:
return self._sum[0] / self._count[0] if self.items is None else [
self._sum[i] / self._count[i] for i in range(self.n_items)
]
else:
return self._sum[idx] / self._count[idx]