Mercurial > ift6266
annotate deep/convolutional_dae/run_exp.py @ 352:cfb79f9fd1a4
Ajout d'une fonctionnalite pour pouvoir avoir un taux d'apprentissage decroissant dans le pretrain
author | SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca> |
---|---|
date | Wed, 21 Apr 2010 14:50:59 -0400 |
parents | 69109e41983e |
children | 01445a75c702 |
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 = [] |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
25 if state.nfilts1 != 0: |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
26 nfilts.append(state.nfilts1) |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
27 if state.nfilts2 != 0: |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
28 nfilts.append(state.nfilts2) |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
29 if state.nfilts3 != 0: |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
30 nfilts.append(state.nfilts3) |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
31 if state.nfilts4 != 0: |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
32 nfilts.append(state.nfilts4) |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
33 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
34 fsizes = [(5,5)]*len(nfilts) |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
35 subs = [(2,2)]*len(nfilts) |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
36 noise = [state.noise]*len(nfilts) |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
37 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
38 pretrain_funcs, trainf, evalf, net = build_funcs( |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
39 img_size=(32, 32), |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
40 batch_size=state.bsize, |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
41 filter_sizes=fsizes, |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
42 num_filters=nfilts, |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
43 subs=subs, |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
44 noise=noise, |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
45 mlp_sizes=[state.mlp_sz], |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
46 out_size=62, |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
47 dtype=numpy.float32, |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
48 pretrain_lr=state.pretrain_lr, |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
49 train_lr=state.train_lr) |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
50 |
298
a222af1d0598
- Adapt to scdae to input_shape change in pynnet
Arnaud Bergeron <abergeron@gmail.com>
parents:
294
diff
changeset
|
51 t_it = repeat_itf(dset.train, state.bsize) |
291
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
52 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
|
53 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
|
54 pretrain_funcs, trainf,evalf) |
291
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
55 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
56 series = create_series() |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
57 |
293
d89820070ea0
Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents:
292
diff
changeset
|
58 print "pretraining ..." |
d89820070ea0
Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents:
292
diff
changeset
|
59 sys.stdout.flush() |
291
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
60 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
|
61 |
293
d89820070ea0
Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents:
292
diff
changeset
|
62 print "training ..." |
d89820070ea0
Add some prints to see the current step.
Arnaud Bergeron <abergeron@gmail.com>
parents:
292
diff
changeset
|
63 sys.stdout.flush() |
294
8babd43235dd
Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents:
293
diff
changeset
|
64 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
|
65 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
|
66 patience_increase=2., |
8babd43235dd
Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents:
293
diff
changeset
|
67 improvement_threshold=0.995, |
300
6eab220a7d70
Adjust sgd_opt parameters and use nist_all.
Arnaud Bergeron <abergeron@gmail.com>
parents:
298
diff
changeset
|
68 validation_frequency=500, |
294
8babd43235dd
Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents:
293
diff
changeset
|
69 series=series, net=net) |
8babd43235dd
Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents:
293
diff
changeset
|
70 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
|
71 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
|
72 channel.save() |
8babd43235dd
Save best valid score and test score in the db.
Arnaud Bergeron <abergeron@gmail.com>
parents:
293
diff
changeset
|
73 return channel.COMPLETE |
291
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
74 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
75 if __name__ == '__main__': |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
76 st = dumb() |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
77 st.bsize = 100 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
78 st.pretrain_lr = 0.01 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
79 st.train_lr = 0.1 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
80 st.nfilts1 = 4 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
81 st.nfilts2 = 4 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
82 st.nfilts3 = 0 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
83 st.pretrain_rounds = 500 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
84 st.noise=0.2 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
85 st.mlp_sz = 500 |
7d1fa2d7721c
Split out the run_exp method.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff
changeset
|
86 go(st, dumb()) |