annotate deep/convolutional_dae/run_exp.py @ 603:eb6244c6d861

aistats submission
author Yoshua Bengio <bengioy@iro.umontreal.ca>
date Sun, 31 Oct 2010 22:40:33 -0400
parents 01445a75c702
children
rev   line source
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
1 from ift6266.deep.convolutional_dae.scdae import *
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
2
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
3 class dumb(object):
333
69109e41983e Adapt parameters (especially the number of epochs) to P07
Arnaud Bergeron <abergeron@gmail.com>
parents: 300
diff changeset
4 COMPLETE = None
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
5 def save(self):
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
6 pass
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
7
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
8 def go(state, channel):
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
9 from ift6266 import datasets
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
10 from ift6266.deep.convolutional_dae.sgd_opt import sgd_opt
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
11 import pylearn, theano, ift6266
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
12 import pylearn.version
293
d89820070ea0 Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents: 292
diff changeset
13 import sys
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
14
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
15 # params: bsize, pretrain_lr, train_lr, nfilts1, nfilts2, nftils3, nfilts4
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
16 # pretrain_rounds, noise, mlp_sz
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
17
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
18 pylearn.version.record_versions(state, [theano, ift6266, pylearn])
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
19 # TODO: maybe record pynnet version?
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
20 channel.save()
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
21
333
69109e41983e Adapt parameters (especially the number of epochs) to P07
Arnaud Bergeron <abergeron@gmail.com>
parents: 300
diff changeset
22 dset = datasets.nist_P07()
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
23
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
24 nfilts = []
376
01445a75c702 Fix filter sizes to have meaningful networks with more that 2 layers.
Arnaud Bergeron <abergeron@gmail.com>
parents: 333
diff changeset
25 fsizes = []
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
26 if state.nfilts1 != 0:
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
27 nfilts.append(state.nfilts1)
376
01445a75c702 Fix filter sizes to have meaningful networks with more that 2 layers.
Arnaud Bergeron <abergeron@gmail.com>
parents: 333
diff changeset
28 fsizes.append((5,5))
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
29 if state.nfilts2 != 0:
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
30 nfilts.append(state.nfilts2)
376
01445a75c702 Fix filter sizes to have meaningful networks with more that 2 layers.
Arnaud Bergeron <abergeron@gmail.com>
parents: 333
diff changeset
31 fsizes.append((3,3))
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
32 if state.nfilts3 != 0:
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
33 nfilts.append(state.nfilts3)
376
01445a75c702 Fix filter sizes to have meaningful networks with more that 2 layers.
Arnaud Bergeron <abergeron@gmail.com>
parents: 333
diff changeset
34 fsizes.append((3,3))
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
35 if state.nfilts4 != 0:
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
36 nfilts.append(state.nfilts4)
376
01445a75c702 Fix filter sizes to have meaningful networks with more that 2 layers.
Arnaud Bergeron <abergeron@gmail.com>
parents: 333
diff changeset
37 fsizes.append((2,2))
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
38
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
39 subs = [(2,2)]*len(nfilts)
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
40 noise = [state.noise]*len(nfilts)
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
41
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
42 pretrain_funcs, trainf, evalf, net = build_funcs(
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
43 img_size=(32, 32),
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
44 batch_size=state.bsize,
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
45 filter_sizes=fsizes,
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
46 num_filters=nfilts,
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
47 subs=subs,
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
48 noise=noise,
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
49 mlp_sizes=[state.mlp_sz],
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
50 out_size=62,
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
51 dtype=numpy.float32,
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
52 pretrain_lr=state.pretrain_lr,
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
53 train_lr=state.train_lr)
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
54
298
a222af1d0598 - Adapt to scdae to input_shape change in pynnet
Arnaud Bergeron <abergeron@gmail.com>
parents: 294
diff changeset
55 t_it = repeat_itf(dset.train, state.bsize)
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
56 pretrain_fs, train, valid, test = massage_funcs(
298
a222af1d0598 - Adapt to scdae to input_shape change in pynnet
Arnaud Bergeron <abergeron@gmail.com>
parents: 294
diff changeset
57 t_it, t_it, dset, state.bsize,
292
8108d271c30c Fix stuff (imports, ...) so that it can run under jobman properly.
Arnaud Bergeron <abergeron@gmail.com>
parents: 291
diff changeset
58 pretrain_funcs, trainf,evalf)
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
59
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
60 series = create_series()
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
61
293
d89820070ea0 Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents: 292
diff changeset
62 print "pretraining ..."
d89820070ea0 Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents: 292
diff changeset
63 sys.stdout.flush()
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
64 do_pretrain(pretrain_fs, state.pretrain_rounds, series['recons_error'])
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
65
293
d89820070ea0 Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents: 292
diff changeset
66 print "training ..."
d89820070ea0 Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents: 292
diff changeset
67 sys.stdout.flush()
294
8babd43235dd Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents: 293
diff changeset
68 best_valid, test_score = sgd_opt(train, valid, test,
333
69109e41983e Adapt parameters (especially the number of epochs) to P07
Arnaud Bergeron <abergeron@gmail.com>
parents: 300
diff changeset
69 training_epochs=800000, patience=2000,
294
8babd43235dd Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents: 293
diff changeset
70 patience_increase=2.,
8babd43235dd Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents: 293
diff changeset
71 improvement_threshold=0.995,
300
6eab220a7d70 Adjust sgd_opt parameters and use nist_all.
Arnaud Bergeron <abergeron@gmail.com>
parents: 298
diff changeset
72 validation_frequency=500,
294
8babd43235dd Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents: 293
diff changeset
73 series=series, net=net)
8babd43235dd Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents: 293
diff changeset
74 state.best_valid = best_valid
8babd43235dd Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents: 293
diff changeset
75 state.test_score = test_score
8babd43235dd Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents: 293
diff changeset
76 channel.save()
8babd43235dd Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents: 293
diff changeset
77 return channel.COMPLETE
291
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
78
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
79 if __name__ == '__main__':
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
80 st = dumb()
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
81 st.bsize = 100
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
82 st.pretrain_lr = 0.01
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
83 st.train_lr = 0.1
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
84 st.nfilts1 = 4
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
85 st.nfilts2 = 4
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
86 st.nfilts3 = 0
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
87 st.pretrain_rounds = 500
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
88 st.noise=0.2
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
89 st.mlp_sz = 500
7d1fa2d7721c Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
90 go(st, dumb())