forked from CSTR-Edinburgh/merlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_classes.py
More file actions
53 lines (42 loc) · 1.44 KB
/
Copy pathtest_classes.py
File metadata and controls
53 lines (42 loc) · 1.44 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
44
45
46
47
48
49
50
51
52
53
# Test the classes used in Merlin pipeline
# TODO run some very simple training on random data)
import sys
import os
sys.path.append('../src')
import errno
import numpy as np
import cPickle
import logging
def makedir(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
def build_model(hidden_layer_type):
logger.info(' DeepRecurrentNetwork '+str(hidden_layer_type))
nnmodel = DeepRecurrentNetwork(8, 16*np.ones(len(hidden_layer_type)), 4, L1_reg=0.0, L2_reg=0.00001, hidden_layer_type=hidden_layer_type)
# Always try to save it and reload it
modelfile = 'log/model.pkl'
makedir('log')
cPickle.dump(nnmodel, open(modelfile, 'wb'))
nnmodel = cPickle.load(open(modelfile, 'rb'))
logger.info(' OK')
return nnmodel
if __name__ == '__main__':
# Get a logger for these tests
logging.basicConfig(format='%(asctime)s %(levelname)8s%(name)15s: %(message)s')
logger = logging.getLogger("test")
logger.setLevel(logging.DEBUG)
logger.info('Testing Merlin classes')
# Build various models
logger.info('Build models without training')
from models.deep_rnn import DeepRecurrentNetwork
nnmodel = build_model(['TANH'])
del nnmodel
nnmodel = build_model(['TANH', 'TANH'])
del nnmodel
nnmodel = build_model(['LSTM', 'LSTM'])
del nnmodel
nnmodel = build_model(['SLSTM', 'SLSTM'])
del nnmodel