-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtrain_mlp_script.py
44 lines (36 loc) · 1.51 KB
/
train_mlp_script.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
# training script
import sys, os, argparse, cPickle
import pylearn2.config.yaml_parse as yaml_parse
import pdb
if __name__=="__main__":
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
description='''Script to train a DNN with a variable number of units and the possibility of using dropout.
''')
parser.add_argument('fold_config', help='Path to dataset partition configuration file (generated with prepare_dataset.py)')
parser.add_argument('yaml_file')
parser.add_argument('--nunits', type=int, help='Number of units in each hidden layer')
# parser.add_argument('--dropout', action='store_true', help='Set this flag if you want to use dropout regularization')
parser.add_argument('--output', help='Name of output model')
args = parser.parse_args()
if args.nunits is None:
parser.error('Please specify number of hidden units per layer with --nunits flag')
if args.output is None:
parser.error('Please specify the name that the trained model file should be saved as (.pkl file)')
# if args.dropout:
# print 'Using dropout'
# yaml_file = 'mlp_rlu_dropout.yaml'
# else:
# print 'Not using dropout'
# yaml_file = 'mlp_rlu.yaml'
hyper_params = { 'dim_h0' : args.nunits,
'dim_h1' : args.nunits,
'dim_h2' : args.nunits,
'fold_config' : args.fold_config,
'best_model_save_path' : args.output,
'save_path' : '/tmp/save.pkl'
}
with open(args.yaml_file) as f:
train_yaml = f.read()
train_yaml = train_yaml % (hyper_params)
train = yaml_parse.load(train_yaml)
train.main_loop()