-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
38 lines (29 loc) · 883 Bytes
/
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
import time
from datetime import datetime
class AverageMeter(object):
"""From https://github.com/pytorch/examples/blob/master/imagenet/main.py"""
def __init__(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
def __repr__(self):
return f'{self.avg:.2e}'
def update(self, val, n=1):
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
class dotdict(dict):
def __getattr__(self, name):
return self[name]
def get_readable_time():
timestamp = time.time()
normal_time = str(datetime.fromtimestamp(timestamp))
temp = normal_time.split()
first = temp[0].replace('-', '_')
second = temp[1].split(':')
second[-1] = second[-1].split('.')[0]
second = "_".join(second)
ret = first + "_" + second
return ret