-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
43 lines (30 loc) · 913 Bytes
/
utils.py
File metadata and controls
43 lines (30 loc) · 913 Bytes
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
import pickle as pkl
def save_obj(file_name, obj):
file_name = file_name if '.pkl' in file_name else file_name + '.pkl'
with open(file_name, 'wb') as file:
pkl.dump(obj, file)
def load_obj(file_name):
file_name = file_name if '.pkl' in file_name else file_name + '.pkl'
with open(file_name, 'rb') as file:
obj = pkl.load(file)
return obj
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
def clean_line():
# pass
print(' ' * 80, end='\r')
def clean_print(*args, **kwargs):
clean_line()
print(*args, **kwargs)