-
Notifications
You must be signed in to change notification settings - Fork 0
/
DLExperiment.py
72 lines (53 loc) · 1.87 KB
/
DLExperiment.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
import sys,os,argparse
# Configuration of this job
parser = argparse.ArgumentParser()
# Start by creating a new config file and changing the line below
parser.add_argument('-C', '--config',default="DefaultConfig.py")
parser.add_argument('-L', '--LoadModel',default=False)
parser.add_argument('--gpu', dest='gpuid', default="")
parser.add_argument('--cpu', action="store_true")
parser.add_argument('--NoTrain', action="store_true")
parser.add_argument('-s',"--hyperparamset", default="0")
args = parser.parse_args()
UseGPU=not args.cpu
gpuid=args.gpuid
if args.hyperparamset:
HyperParamSet = int(args.hyperparamset)
ConfigFile=args.config
if UseGPU:
os.environ['THEANO_FLAGS'] = "mode=FAST_RUN,device=gpu%s,floatX=float32,force_device=True" % (gpuid)
# Process the ConfigFile
execfile(ConfigFile)
# Now put config in the current scope. Must find a prettier way.
if "Config" in dir():
for a in Config:
exec(a+"="+str(Config[a]))
# Load the Data
from RandomData import RandomSequenceData
(Train_X, Test_X) = RandomSequenceData(N_Examples,N_Inputs)
# Build the Model
from AutoEncoders import LSTMAutoEncoder
# Instantiate a LSTM AutoEncoder
MyModel=LSTMAutoEncoder(Name,
InputShape=InputShape,
Widths=Widths,
EncodeActivation=EncodeActivation,
DecodeActivation=DecodeActivation,
Loss=Loss,
Optimizer=Optimizer)
# Print out the Model Summary
MyModel.model.summary()
# Compile The Model
print "Compiling Model."
MyModel.Compile(loss=loss
optimizer=optimizer)
# Train
if Train:
print "Training."
MyModel.Train(X_train, X_train, Epochs, BatchSize)
# Evaluate Score on Test sample
score = MyModel.model.evaluate(X_test, X_test)
print "Final Score:", score
# Analysis
# Save Model
MyModel.Save()