-
Notifications
You must be signed in to change notification settings - Fork 38
/
utils.py
40 lines (33 loc) · 801 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
import time
import cPickle
import tensorflow as tf
def timeit(f):
def timed(*args, **kwargs):
start_time = time.time()
result = f(*args, **kwargs)
end_time = time.time()
print(" [-] %s : %2.5f sec" % (f.__name__, end_time - start_time))
return result
return timed
def get_time():
return time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())
@timeit
def save_pkl(obj, path):
with open(path, 'w') as f:
cPickle.dump(obj, f)
print(" [*] save %s" % path)
@timeit
def load_pkl(path):
with open(path) as f:
obj = cPickle.load(f)
print(" [*] load %s" % path)
return obj
@timeit
def save_npy(obj, path):
np.save(path, obj)
print(" [*] save %s" % path)
@timeit
def load_npy(path):
obj = np.load(path)
print(" [*] load %s" % path)
return obj