annotate deep/convolutional_dae/salah_exp/sgd_optimization_new.py @ 527:5492becbab0d

Small mistake on previous update to chart, corrected.
author fsavard
date Tue, 01 Jun 2010 20:22:42 -0400
parents c05680f8c92f
children
rev   line source
364
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
1 #!/usr/bin/python
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
2 # coding: utf-8
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
3
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
4 import numpy
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
5 import theano
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
6 import time
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
7 import datetime
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
8 import theano.tensor as T
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
9 import sys
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
10 import pickle
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
11
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
12 from jobman import DD
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
13 import jobman, jobman.sql
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
14 from copy import copy
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
15
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
16 from stacked_convolutional_dae_uit import CSdA
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
17
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
18 from ift6266.utils.seriestables import *
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
19
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
20 buffersize=1000
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
21
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
22 default_series = { \
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
23 'reconstruction_error' : DummySeries(),
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
24 'training_error' : DummySeries(),
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
25 'validation_error' : DummySeries(),
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
26 'test_error' : DummySeries(),
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
27 'params' : DummySeries()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
28 }
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
29
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
30 def itermax(iter, max):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
31 for i,it in enumerate(iter):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
32 if i >= max:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
33 break
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
34 yield it
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
35 def get_conv_shape(kernels,imgshp,batch_size,max_pool_layers):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
36 # Returns the dimension at the output of the convoluational net
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
37 # and a list of Image and kernel shape for every
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
38 # Convolutional layer
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
39 conv_layers=[]
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
40 init_layer = [ [ kernels[0][0],1,kernels[0][1],kernels[0][2] ],\
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
41 [ batch_size , 1, imgshp[0], imgshp[1] ],
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
42 max_pool_layers[0] ]
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
43 conv_layers.append(init_layer)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
44
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
45 conv_n_out = int((32-kernels[0][2]+1)/max_pool_layers[0][0])
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
46
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
47 for i in range(1,len(kernels)):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
48 layer = [ [ kernels[i][0],kernels[i-1][0],kernels[i][1],kernels[i][2] ],\
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
49 [ batch_size, kernels[i-1][0],conv_n_out,conv_n_out ],
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
50 max_pool_layers[i] ]
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
51 conv_layers.append(layer)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
52 conv_n_out = int( (conv_n_out - kernels[i][2]+1)/max_pool_layers[i][0])
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
53 conv_n_out=kernels[-1][0]*conv_n_out**2
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
54 return conv_n_out,conv_layers
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
55
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
56
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
57
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
58
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
59
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
60 class CSdASgdOptimizer:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
61 def __init__(self, dataset, hyperparameters, n_ins, n_outs,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
62 examples_per_epoch, series=default_series, max_minibatches=None):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
63 self.dataset = dataset
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
64 self.hp = hyperparameters
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
65 self.n_ins = n_ins
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
66 self.n_outs = n_outs
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
67 self.parameters_pre=[]
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
68
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
69 self.max_minibatches = max_minibatches
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
70 print "CSdASgdOptimizer, max_minibatches =", max_minibatches
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
71
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
72 self.ex_per_epoch = examples_per_epoch
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
73 self.mb_per_epoch = examples_per_epoch / self.hp.minibatch_size
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
74
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
75 self.series = series
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
76
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
77 self.rng = numpy.random.RandomState(1234)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
78 self.init_classifier()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
79
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
80 sys.stdout.flush()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
81
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
82 def init_classifier(self):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
83 print "Constructing classifier"
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
84
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
85 n_ins,convlayers = get_conv_shape(self.hp.kernels,self.hp.imgshp,self.hp.minibatch_size,self.hp.max_pool_layers)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
86
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
87 self.classifier = CSdA(n_ins_mlp = n_ins,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
88 batch_size = self.hp.minibatch_size,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
89 conv_hidden_layers_sizes = convlayers,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
90 mlp_hidden_layers_sizes = self.hp.mlp_size,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
91 corruption_levels = self.hp.corruption_levels,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
92 rng = self.rng,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
93 n_out = self.n_outs,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
94 pretrain_lr = self.hp.pretraining_lr,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
95 finetune_lr = self.hp.finetuning_lr)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
96
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
97
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
98
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
99 #theano.printing.pydotprint(self.classifier.pretrain_functions[0], "function.graph")
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
100
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
101 sys.stdout.flush()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
102
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
103 def train(self):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
104 self.pretrain(self.dataset)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
105 self.finetune(self.dataset)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
106
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
107 def pretrain(self,dataset):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
108 print "STARTING PRETRAINING, time = ", datetime.datetime.now()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
109 sys.stdout.flush()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
110
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
111 un_fichier=int(819200.0/self.hp.minibatch_size) #Number of batches in a P07 file
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
112
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
113 start_time = time.clock()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
114 ## Pre-train layer-wise
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
115 for i in xrange(self.classifier.n_layers):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
116 # go through pretraining epochs
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
117 for epoch in xrange(self.hp.pretraining_epochs_per_layer):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
118 # go through the training set
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
119 batch_index=0
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
120 count=0
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
121 num_files=0
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
122 for x,y in dataset.train(self.hp.minibatch_size):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
123 if x.shape[0] != self.hp.minibatch_size:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
124 continue
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
125 c = self.classifier.pretrain_functions[i](x)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
126 count +=1
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
127
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
128 self.series["reconstruction_error"].append((epoch, batch_index), c)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
129 batch_index+=1
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
130
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
131 #if batch_index % 100 == 0:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
132 # print "100 batches"
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
133
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
134 # useful when doing tests
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
135 if self.max_minibatches and batch_index >= self.max_minibatches:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
136 break
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
137
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
138 #When we pass through the data only once (the case with P07)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
139 #There is approximately 800*1024=819200 examples per file (1k per example and files are 800M)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
140 if self.hp.pretraining_epochs_per_layer == 1 and count%un_fichier == 0:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
141 print 'Pre-training layer %i, epoch %d, cost '%(i,num_files),c
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
142 num_files+=1
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
143 sys.stdout.flush()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
144 self.series['params'].append((num_files,), self.classifier.all_params)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
145
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
146 #When NIST is used
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
147 if self.hp.pretraining_epochs_per_layer > 1:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
148 print 'Pre-training layer %i, epoch %d, cost '%(i,epoch),c
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
149 sys.stdout.flush()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
150
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
151 self.series['params'].append((epoch,), self.classifier.all_params)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
152 end_time = time.clock()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
153
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
154 print ('Pretraining took %f minutes' %((end_time-start_time)/60.))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
155 self.hp.update({'pretraining_time': end_time-start_time})
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
156
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
157 sys.stdout.flush()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
158
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
159 #To be able to load them later for tests on finetune
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
160 self.parameters_pre=[copy(x.value) for x in self.classifier.params]
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
161 f = open('params_pretrain.txt', 'w')
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
162 pickle.dump(self.parameters_pre,f)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
163 f.close()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
164 def finetune(self,dataset,dataset_test,num_finetune,ind_test,special=0,decrease=0):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
165
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
166 if special != 0 and special != 1:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
167 sys.exit('Bad value for variable special. Must be in {0,1}')
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
168 print "STARTING FINETUNING, time = ", datetime.datetime.now()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
169
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
170 minibatch_size = self.hp.minibatch_size
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
171 if ind_test == 0 or ind_test == 20:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
172 nom_test = "NIST"
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
173 nom_train="P07"
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
174 else:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
175 nom_test = "P07"
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
176 nom_train = "NIST"
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
177
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
178
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
179 # create a function to compute the mistakes that are made by the model
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
180 # on the validation set, or testing set
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
181 test_model = \
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
182 theano.function(
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
183 [self.classifier.x,self.classifier.y], self.classifier.errors)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
184 # givens = {
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
185 # self.classifier.x: ensemble_x,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
186 # self.classifier.y: ensemble_y]})
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
187
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
188 validate_model = \
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
189 theano.function(
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
190 [self.classifier.x,self.classifier.y], self.classifier.errors)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
191 # givens = {
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
192 # self.classifier.x: ,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
193 # self.classifier.y: ]})
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
194 # early-stopping parameters
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
195 patience = 10000 # look as this many examples regardless
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
196 patience_increase = 2. # wait this much longer when a new best is
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
197 # found
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
198 improvement_threshold = 0.995 # a relative improvement of this much is
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
199 # considered significant
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
200 validation_frequency = min(self.mb_per_epoch, patience/2)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
201 # go through this many
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
202 # minibatche before checking the network
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
203 # on the validation set; in this case we
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
204 # check every epoch
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
205 if self.max_minibatches and validation_frequency > self.max_minibatches:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
206 validation_frequency = self.max_minibatches / 2
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
207 best_params = None
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
208 best_validation_loss = float('inf')
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
209 test_score = 0.
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
210 start_time = time.clock()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
211
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
212 done_looping = False
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
213 epoch = 0
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
214
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
215 total_mb_index = 0
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
216 minibatch_index = 0
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
217 parameters_finetune=[]
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
218 learning_rate = self.hp.finetuning_lr
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
219
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
220
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
221 while (epoch < num_finetune) and (not done_looping):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
222 epoch = epoch + 1
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
223
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
224 for x,y in dataset.train(minibatch_size,bufsize=buffersize):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
225
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
226 minibatch_index += 1
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
227
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
228 if x.shape[0] != self.hp.minibatch_size:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
229 print 'bim'
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
230 continue
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
231
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
232 cost_ij = self.classifier.finetune(x,y)#,learning_rate)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
233 total_mb_index += 1
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
234
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
235 self.series["training_error"].append((epoch, minibatch_index), cost_ij)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
236
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
237 if (total_mb_index+1) % validation_frequency == 0:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
238 #minibatch_index += 1
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
239 #The validation set is always NIST (we want the model to be good on NIST)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
240
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
241 iter=dataset_test.valid(minibatch_size,bufsize=buffersize)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
242
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
243
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
244 if self.max_minibatches:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
245 iter = itermax(iter, self.max_minibatches)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
246
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
247 validation_losses = []
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
248
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
249 for x,y in iter:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
250 if x.shape[0] != self.hp.minibatch_size:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
251 print 'bim'
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
252 continue
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
253 validation_losses.append(validate_model(x,y))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
254
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
255 this_validation_loss = numpy.mean(validation_losses)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
256
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
257 self.series["validation_error"].\
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
258 append((epoch, minibatch_index), this_validation_loss*100.)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
259
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
260 print('epoch %i, minibatch %i, validation error on NIST : %f %%' % \
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
261 (epoch, minibatch_index+1, \
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
262 this_validation_loss*100.))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
263
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
264
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
265 # if we got the best validation score until now
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
266 if this_validation_loss < best_validation_loss:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
267
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
268 #improve patience if loss improvement is good enough
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
269 if this_validation_loss < best_validation_loss * \
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
270 improvement_threshold :
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
271 patience = max(patience, total_mb_index * patience_increase)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
272
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
273 # save best validation score, iteration number and parameters
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
274 best_validation_loss = this_validation_loss
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
275 best_iter = total_mb_index
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
276 parameters_finetune=[copy(x.value) for x in self.classifier.params]
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
277
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
278 # test it on the test set
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
279 iter = dataset.test(minibatch_size,bufsize=buffersize)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
280 if self.max_minibatches:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
281 iter = itermax(iter, self.max_minibatches)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
282 test_losses = []
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
283 test_losses2 = []
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
284 for x,y in iter:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
285 if x.shape[0] != self.hp.minibatch_size:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
286 print 'bim'
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
287 continue
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
288 test_losses.append(test_model(x,y))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
289
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
290 test_score = numpy.mean(test_losses)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
291
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
292 #test it on the second test set
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
293 iter2 = dataset_test.test(minibatch_size,bufsize=buffersize)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
294 if self.max_minibatches:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
295 iter2 = itermax(iter2, self.max_minibatches)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
296 for x,y in iter2:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
297 if x.shape[0] != self.hp.minibatch_size:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
298 continue
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
299 test_losses2.append(test_model(x,y))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
300
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
301 test_score2 = numpy.mean(test_losses2)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
302
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
303 self.series["test_error"].\
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
304 append((epoch, minibatch_index), test_score*100.)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
305
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
306 print((' epoch %i, minibatch %i, test error on dataset %s (train data) of best '
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
307 'model %f %%') %
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
308 (epoch, minibatch_index+1,nom_train,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
309 test_score*100.))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
310
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
311 print((' epoch %i, minibatch %i, test error on dataset %s of best '
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
312 'model %f %%') %
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
313 (epoch, minibatch_index+1,nom_test,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
314 test_score2*100.))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
315
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
316 if patience <= total_mb_index:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
317 done_looping = True
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
318 break #to exit the FOR loop
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
319
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
320 sys.stdout.flush()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
321
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
322 # useful when doing tests
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
323 if self.max_minibatches and minibatch_index >= self.max_minibatches:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
324 break
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
325
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
326 if decrease == 1:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
327 learning_rate /= 2 #divide the learning rate by 2 for each new epoch
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
328
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
329 self.series['params'].append((epoch,), self.classifier.all_params)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
330
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
331 if done_looping == True: #To exit completly the fine-tuning
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
332 break #to exit the WHILE loop
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
333
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
334 end_time = time.clock()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
335 self.hp.update({'finetuning_time':end_time-start_time,\
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
336 'best_validation_error':best_validation_loss,\
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
337 'test_score':test_score,
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
338 'num_finetuning_epochs':epoch})
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
339
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
340 print(('\nOptimization complete with best validation score of %f %%,'
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
341 'with test performance %f %% on dataset %s ') %
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
342 (best_validation_loss * 100., test_score*100.,nom_train))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
343 print(('The test score on the %s dataset is %f')%(nom_test,test_score2*100.))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
344
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
345 print ('The finetuning ran for %f minutes' % ((end_time-start_time)/60.))
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
346
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
347 sys.stdout.flush()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
348
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
349 #Save a copy of the parameters in a file to be able to get them in the future
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
350
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
351 if special == 1: #To keep a track of the value of the parameters
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
352 f = open('params_finetune_stanford.txt', 'w')
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
353 pickle.dump(parameters_finetune,f)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
354 f.close()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
355
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
356 elif ind_test == 0 | ind_test == 20: #To keep a track of the value of the parameters
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
357 f = open('params_finetune_P07.txt', 'w')
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
358 pickle.dump(parameters_finetune,f)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
359 f.close()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
360
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
361
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
362 elif ind_test== 1: #For the run with 2 finetunes. It will be faster.
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
363 f = open('params_finetune_NIST.txt', 'w')
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
364 pickle.dump(parameters_finetune,f)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
365 f.close()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
366
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
367 elif ind_test== 21: #To keep a track of the value of the parameters
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
368 f = open('params_finetune_P07_then_NIST.txt', 'w')
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
369 pickle.dump(parameters_finetune,f)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
370 f.close()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
371 #Set parameters like they where right after pre-train or finetune
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
372 def reload_parameters(self,which):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
373
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
374 #self.parameters_pre=pickle.load('params_pretrain.txt')
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
375 f = open(which)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
376 self.parameters_pre=pickle.load(f)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
377 f.close()
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
378 for idx,x in enumerate(self.parameters_pre):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
379 if x.dtype=='float64':
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
380 self.classifier.params[idx].value=theano._asarray(copy(x),dtype=theano.config.floatX)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
381 else:
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
382 self.classifier.params[idx].value=copy(x)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
383
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
384 def training_error(self,dataset):
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
385 # create a function to compute the mistakes that are made by the model
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
386 # on the validation set, or testing set
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
387 test_model = \
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
388 theano.function(
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
389 [self.classifier.x,self.classifier.y], self.classifier.errors)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
390
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
391 iter2 = dataset.train(self.hp.minibatch_size,bufsize=buffersize)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
392 train_losses2 = [test_model(x,y) for x,y in iter2]
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
393 train_score2 = numpy.mean(train_losses2)
c05680f8c92f Fixing a wrong commit and committing more files.
humel
parents:
diff changeset
394 print "Training error is: " + str(train_score2)