Mercurial > ift6266
annotate deep/stacked_dae/v_guillaume/train_error.py @ 619:ea31fee25147
review response
author | Yoshua Bengio <bengioy@iro.umontreal.ca> |
---|---|
date | Sun, 09 Jan 2011 14:15:04 -0500 |
parents | 0ca069550abd |
children |
rev | line source |
---|---|
436
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
2 # coding: utf-8 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
3 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
4 import ift6266 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
5 import pylearn |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
6 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
7 import numpy |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
8 import theano |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
9 import time |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
10 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
11 import pylearn.version |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
12 import theano.tensor as T |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
13 from theano.tensor.shared_randomstreams import RandomStreams |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
14 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
15 import copy |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
16 import sys |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
17 import os |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
18 import os.path |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
19 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
20 from jobman import DD |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
21 import jobman, jobman.sql |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
22 from pylearn.io import filetensor |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
23 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
24 from utils import produit_cartesien_jobs |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
25 from copy import copy |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
26 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
27 from sgd_optimization import SdaSgdOptimizer |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
28 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
29 #from ift6266.utils.scalar_series import * |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
30 from ift6266.utils.seriestables import * |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
31 import tables |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
32 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
33 from ift6266 import datasets |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
34 from config import * |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
35 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
36 ''' |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
37 Function called by jobman upon launching each job |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
38 Its path is the one given when inserting jobs: see EXPERIMENT_PATH |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
39 ''' |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
40 def jobman_entrypoint(state, channel): |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
41 # record mercurial versions of each package |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
42 pylearn.version.record_versions(state,[theano,ift6266,pylearn]) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
43 # TODO: remove this, bad for number of simultaneous requests on DB |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
44 channel.save() |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
45 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
46 # For test runs, we don't want to use the whole dataset so |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
47 # reduce it to fewer elements if asked to. |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
48 rtt = None |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
49 if state.has_key('reduce_train_to'): |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
50 rtt = state['reduce_train_to'] |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
51 elif REDUCE_TRAIN_TO: |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
52 rtt = REDUCE_TRAIN_TO |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
53 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
54 n_ins = 32*32 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
55 n_outs = 62 # 10 digits, 26*2 (lower, capitals) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
56 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
57 examples_per_epoch = NIST_ALL_TRAIN_SIZE |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
58 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
59 PATH = '' |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
60 maximum_exemples=int(500000) #Maximum number of exemples seen |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
61 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
62 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
63 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
64 print "Creating optimizer with state, ", state |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
65 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
66 optimizer = SdaSgdOptimizer(dataset=datasets.nist_all(), |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
67 hyperparameters=state, \ |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
68 n_ins=n_ins, n_outs=n_outs,\ |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
69 examples_per_epoch=examples_per_epoch, \ |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
70 max_minibatches=rtt) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
71 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
72 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
73 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
74 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
75 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
76 if os.path.exists(PATH+'params_finetune_NIST.txt'): |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
77 print ('\n finetune = NIST ') |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
78 optimizer.reload_parameters(PATH+'params_finetune_NIST.txt') |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
79 print "For" + str(maximum_exemples) + "over the NIST training set: " |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
80 optimizer.training_error(datasets.nist_all(maxsize=maximum_exemples)) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
81 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
82 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
83 if os.path.exists(PATH+'params_finetune_P07.txt'): |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
84 print ('\n finetune = P07 ') |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
85 optimizer.reload_parameters(PATH+'params_finetune_P07.txt') |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
86 print "For" + str(maximum_exemples) + "over the P07 training set: " |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
87 optimizer.training_error(datasets.nist_P07(maxsize=maximum_exemples)) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
88 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
89 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
90 if os.path.exists(PATH+'params_finetune_NIST_then_P07.txt'): |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
91 print ('\n finetune = NIST then P07') |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
92 optimizer.reload_parameters(PATH+'params_finetune_NIST_then_P07.txt') |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
93 print "For" + str(maximum_exemples) + "over the NIST training set: " |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
94 optimizer.training_error(datasets.nist_all(maxsize=maximum_exemples)) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
95 print "For" + str(maximum_exemples) + "over the P07 training set: " |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
96 optimizer.training_error(datasets.nist_P07(maxsize=maximum_exemples)) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
97 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
98 if os.path.exists(PATH+'params_finetune_P07_then_NIST.txt'): |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
99 print ('\n finetune = P07 then NIST') |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
100 optimizer.reload_parameters(PATH+'params_finetune_P07_then_NIST.txt') |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
101 print "For" + str(maximum_exemples) + "over the P07 training set: " |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
102 optimizer.training_error(datasets.nist_P07(maxsize=maximum_exemples)) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
103 print "For" + str(maximum_exemples) + "over the NIST training set: " |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
104 optimizer.training_error(datasets.nist_all(maxsize=maximum_exemples)) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
105 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
106 channel.save() |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
107 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
108 return channel.COMPLETE |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
109 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
110 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
111 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
112 if __name__ == '__main__': |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
113 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
114 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
115 chanmock = DD({'COMPLETE':0,'save':(lambda:None)}) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
116 jobman_entrypoint(DD(DEFAULT_HP_NIST), chanmock) |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
117 |
0ca069550abd
Added : single class version of SDA
Guillaume Sicard <guitch21@gmail.com>
parents:
diff
changeset
|
118 |