-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathutils.py
43 lines (32 loc) · 865 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
39
40
41
42
43
import time
import numpy as np
class Adder(object):
def __init__(self):
self.count = 0
self.num = float(0)
def reset(self):
self.count = 0
self.num = float(0)
def __call__(self, num):
self.count += 1
self.num += num
def average(self):
return self.num / self.count
class Timer(object):
def __init__(self, option='s'):
self.tm = 0
self.option = option
if option == 's':
self.devider = 1
elif option == 'm':
self.devider = 60
else:
self.devider = 3600
def tic(self):
self.tm = time.time()
def toc(self):
return (time.time() - self.tm) / self.devider
def check_lr(optimizer):
for i, param_group in enumerate(optimizer.param_groups):
lr = param_group['lr']
return lr