-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.py
97 lines (80 loc) · 3.12 KB
/
config.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
import json
import glob
"""
Created on Tue Jul 3 20:41:01 2018
@author: Marcel Himmelreich
"""
"""
Config Layout
Network Setting
Network Layout
"""
class Config():
def __init__(self):
self._epochs = [500]
self._sequence_length = [10,50,100]
self._batch_size = [256]
self._validation = [True]
self._validation_split = [0.3]
self._activation = ['softmax', 'sigmoid']
self._optimizer = ['rmsprop', 'adam']
self._loss = ['categorical_crossentropy']
self._metrics = ['accuracy']
self._layout = ['default','multi','bidirectional', 'multibidirectional']
self._dropout = [0.3, 0.6]
self._config = None
def saveConfig(self, filepath):
try:
setting = {
'epoch' : self._epochs,
'sequencelength' : self._sequence_length,
'batchsize' : self._batch_size,
'validation' : self._validation,
'validationsplit' : self._validation_split,
'activation' : self._activation,
'optimizer' : self._optimizer,
'loss' : self._loss,
'metrics' : self._metrics,
'layout' : self._layout,
'dropout': self._dropout
}
self._config = {
'setting' : setting,
}
filenameout = filepath + "/config" + ".jsonl"
with open(filenameout, "w") as outfile:
outfile.write(json.dumps(self._config))
outfile.write("\n")
except:
print("Writing Config Failed!")
def loadConfig(self, filepath):
try:
with open(filepath + "*.jsonl", "r") as jsonfile:
jdata = json.loads(jsonfile)
self._config = jdata
setting = jdata['setting']
self._epochs = setting['epoch']
self._sequence_length = setting['sequencelength']
self._batch_size = setting['batchsize']
self._validation = setting['validation']
self._validation_split = setting['validationsplit']
self._activation = setting['activation']
self._optimizer = setting['optimizer']
self._loss = setting['loss']
self._metrics = setting['metrics']
self._layout = setting['layout']
self._dropout = setting['dropout']
print("Config Loaded...")
except:
print("Unable to load config")
def loadMultipleConfig(self,filepath):
try:
settings = None
for file in glob.glob(filepath + "*.jsonl"):
with open(file, "r") as jsonfile:
for index, item in enumerate(jsonfile):
jdata = json.loads(item)
return settings
except:
print("error")