annotate deep/stacked_dae/v_youssouf/train_error.py @ 425:c06a3d9b5664

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