-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhyperparameter.py
More file actions
43 lines (40 loc) · 1.65 KB
/
hyperparameter.py
File metadata and controls
43 lines (40 loc) · 1.65 KB
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 json
import codecs
import os
class HyperParams:
def __init__(self, param_dict=None, param_json_path=None):
self.sample_rate = 16000
self.waveform_bits = 8
self.waveform_categories = 1 << self.waveform_bits
self.waveform_center_cat = 1 << (self.waveform_bits - 1)
self.dilation_blocks = [10] * 1
self.kernel_size = 2
self.residual_channels = 32
self.skip_dims = 256
self.dilated_causal_use_bias = True
self.residual_use_bias = True
self.skip_use_bias = True
self.learning_rate = 0.001
self.clip_norm = 1.
self.batch_size = 1
self.split_nums = 16
self.max_global_steps = 1E5
self.train_meta_path = './train_meta.pkl'
self.log_dir = './log'
self.save_path = './save'
if isinstance(param_dict, dict):
self._update_from_dict(param_dict)
elif isinstance(param_json_path, str) and os.path.exists(param_json_path):
with codecs.open(param_json_path, 'r', encoding='utf-8') as f:
param_dict = json.load(f)
self._update_from_dict(param_dict)
else:
print('Use default setup.')
def _update_from_dict(self, param_dict):
for k, v in param_dict.items():
assert hasattr(self, k),\
'[E] param: \"{}\" is not valid.'.format(k)
assert isinstance(type(v), type(getattr(self, k))),\
'[E] param: \"{}\" should have type: \"{}\", ' \
'while got type: \"{}\".'.format(k, type(getattr(self, k)), type(v))
setattr(self, k, v)