-
Notifications
You must be signed in to change notification settings - Fork 121
/
config.py
71 lines (55 loc) · 2.18 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
from datetime import datetime
import pprint
import os
import numpy as np
from util import mkdir
from data import FEATURE_DIR
mkdir(FEATURE_DIR)
class Config(object):
def __init__(self, layers, cnf=None):
self.layers = layers
self.cnf = cnf
pprint.pprint(cnf)
def get(self, k, default=None):
return self.cnf.get(k, default)
@property
def weights_epoch(self):
path = "weights/{}/epochs".format(self.cnf['name'])
mkdir(path)
return os.path.join(path, '{epoch}_{timestamp}_{loss}.pkl')
@property
def weights_best(self):
path = "weights/{}/best".format(self.cnf['name'])
mkdir(path)
return os.path.join(path, '{epoch}_{timestamp}_{loss}.pkl')
@property
def weights_file(self):
path = "weights/{}".format(self.cnf['name'])
mkdir(path)
return os.path.join(path, 'weights.pkl')
@property
def retrain_weights_file(self):
path = "weights/{}/retrain".format(self.cnf['name'])
mkdir(path)
return os.path.join(path, 'weights.pkl')
@property
def final_weights_file(self):
path = "weights/{}".format(self.cnf['name'])
mkdir(path)
return os.path.join(path, 'weights_final.pkl')
def get_features_fname(self, n_iter, skip=0, test=False):
fname = '{}_{}_mean_iter_{}_skip_{}.npy'.format(
self.cnf['name'], ('test' if test else 'train'), n_iter, skip)
return os.path.join(FEATURE_DIR, fname)
def get_std_fname(self, n_iter, skip=0, test=False):
fname = '{}_{}_std_iter_{}_skip_{}.npy'.format(
self.cnf['name'], ('test' if test else 'train'), n_iter, skip)
return os.path.join(FEATURE_DIR, fname)
def save_features(self, X, n_iter, skip=0, test=False):
np.save(open(self.get_features_fname(n_iter, skip=skip,
test=test), 'wb'), X)
def save_std(self, X, n_iter, skip=0, test=False):
np.save(open(self.get_std_fname(n_iter, skip=skip,
test=test), 'wb'), X)
def load_features(self, test=False):
return np.load(open(self.get_features_fname(test=test)))