-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
63 lines (50 loc) · 1.93 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
import yaml
import os
import numpy as np
import shutil
def recreate_dirs(*dirs):
for d in dirs:
if os.path.exists(d):
shutil.rmtree(d)
os.makedirs(d)
class Config:
def __init__(self, cfg_id, fold, create_dirs=True):
self.id = cfg_id
self.fold = fold
cfg_name = 'configs/%s.yml' % cfg_id
if not os.path.exists(cfg_name):
print("Config file doesn't exist: %s" % cfg_name)
exit(0)
with open(cfg_name, 'r') as stream:
cfg = yaml.safe_load(stream)
# res dir for pytorch lighting
self.base_dir = os.path.expanduser(cfg['results_dir'])
self.cfg_dir = '%s/%s/%s' % (self.base_dir, cfg_id, fold)
self.res_dir = '%s/%s/results' % (self.base_dir, cfg_id)
self.test_dir = '%s/test' % self.cfg_dir
os.makedirs(self.base_dir, exist_ok=True)
os.makedirs(self.res_dir, exist_ok=True)
# param
self.gpus = cfg['gpus']
self.n_channels = cfg['n_channels']
self.n_classes = cfg['n_classes']
self.shuffle = cfg['shuffle']
self.lr = cfg['learning_rate']
self.batchsize = cfg['batchsize']
self.val_batchsize = cfg['val_batchsize']
self.seq_len = cfg['seq_len']
self.bilinear = cfg['bilinear']
self.patience = cfg['patience']
self.lambdaLayer = cfg['lambdaLayer']
self.sig = cfg.get('sigmoid',False)
self.uplambdaLayer = cfg.get('uplambdaLayer',[False, False, False, False])
self.temporal = cfg['temporal']
self.cut_marginal = cfg['cut_marginal']
self.lr_scheduler = cfg['lr_scheduler']
self.val_train = cfg['val_train']
self.kernel_size = cfg['kernel_size']
self.seed = cfg['seed']
self.norm = cfg.get('norm', 'BatchNorm2d')
self.tr = cfg.get('tr', 3)
self.step_val = cfg.get('step_val', False)
self.var_t = cfg['var_t']