-
Notifications
You must be signed in to change notification settings - Fork 15
/
utils_log.py
executable file
·48 lines (42 loc) · 1.55 KB
/
utils_log.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
44
45
46
47
48
import tensorflow as tf
### PARAMETER LOGGING
def save_logging(dictionary, log_name):
with open(log_name, 'w') as f:
for key, value in dictionary.items():
if 'activate_fn' in key:
value = str(value).split(' ')[1]
f.write('%s:%s\n' % (key, value))
def load_logging(filename):
data = dict()
with open(filename) as f:
def is_float(input):
try:
num = float(input)
except ValueError:
return False
return True
for line in f.readlines():
if ':' in line:
key,value = line.strip().split(':', 1)
if 'activate_fn' in key:
if value == 'relu':
value = tf.nn.relu
elif value == 'elu':
value = tf.nn.elu
elif value == 'tanh':
value = tf.nn.tanh
else:
raise ValueError('ERROR: wrong choice of activation function!')
data[key] = value
else:
if value.isdigit():
data[key] = int(value)
elif is_float(value):
data[key] = float(value)
elif value == 'None':
data[key] = None
else:
data[key] = value
else:
pass # deal with bad lines of text here
return data