Mercurial > ift6266
comparison deep/stacked_dae/v_sylvain/stacked_dae.py @ 251:02b141a466b4
ajout de fonctionnalite pour different finetune dataset
author | SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca> |
---|---|
date | Tue, 16 Mar 2010 21:24:30 -0400 |
parents | ecb69e17950b |
children | c77ffb11f91d |
comparison
equal
deleted
inserted
replaced
250:6d49cf134a40 | 251:02b141a466b4 |
---|---|
163 | 163 |
164 self.params = [ self.W, self.b, self.b_prime ] | 164 self.params = [ self.W, self.b, self.b_prime ] |
165 | 165 |
166 | 166 |
167 class SdA(object): | 167 class SdA(object): |
168 def __init__(self, train_set_x, train_set_y, batch_size, n_ins, | 168 def __init__(self, batch_size, n_ins, |
169 hidden_layers_sizes, n_outs, | 169 hidden_layers_sizes, n_outs, |
170 corruption_levels, rng, pretrain_lr, finetune_lr, input_divider=1.0): | 170 corruption_levels, rng, pretrain_lr, finetune_lr): |
171 # Just to make sure those are not modified somewhere else afterwards | 171 # Just to make sure those are not modified somewhere else afterwards |
172 hidden_layers_sizes = copy.deepcopy(hidden_layers_sizes) | 172 hidden_layers_sizes = copy.deepcopy(hidden_layers_sizes) |
173 corruption_levels = copy.deepcopy(corruption_levels) | 173 corruption_levels = copy.deepcopy(corruption_levels) |
174 | 174 |
175 update_locals(self, locals()) | 175 update_locals(self, locals()) |
188 print "corruption_levels", corruption_levels | 188 print "corruption_levels", corruption_levels |
189 print "n_ins", n_ins | 189 print "n_ins", n_ins |
190 print "n_outs", n_outs | 190 print "n_outs", n_outs |
191 print "pretrain_lr", pretrain_lr | 191 print "pretrain_lr", pretrain_lr |
192 print "finetune_lr", finetune_lr | 192 print "finetune_lr", finetune_lr |
193 print "input_divider", input_divider | |
194 print "----" | 193 print "----" |
195 | |
196 #self.shared_divider = theano.shared(numpy.asarray(input_divider, dtype=theano.config.floatX)) | |
197 | 194 |
198 if len(hidden_layers_sizes) < 1 : | 195 if len(hidden_layers_sizes) < 1 : |
199 raiseException (' You must have at least one hidden layer ') | 196 raiseException (' You must have at least one hidden layer ') |
200 | 197 |
201 | 198 |
202 # allocate symbolic variables for the data | 199 # allocate symbolic variables for the data |
203 ##index = T.lscalar() # index to a [mini]batch | 200 #index = T.lscalar() # index to a [mini]batch |
204 self.x = T.matrix('x') # the data is presented as rasterized images | 201 self.x = T.matrix('x') # the data is presented as rasterized images |
205 self.y = T.ivector('y') # the labels are presented as 1D vector of | 202 self.y = T.ivector('y') # the labels are presented as 1D vector of |
206 # [int] labels | 203 # [int] labels |
207 ensemble = T.matrix('ensemble') | |
208 ensemble_x = T.matrix('ensemble_x') | |
209 ensemble_y = T.ivector('ensemble_y') | |
210 | 204 |
211 for i in xrange( self.n_layers ): | 205 for i in xrange( self.n_layers ): |
212 # construct the sigmoidal layer | 206 # construct the sigmoidal layer |
213 | 207 |
214 # the size of the input is either the number of hidden units of | 208 # the size of the input is either the number of hidden units of |
248 updates = {} | 242 updates = {} |
249 for param, gparam in zip(dA_layer.params, gparams): | 243 for param, gparam in zip(dA_layer.params, gparams): |
250 updates[param] = param - gparam * pretrain_lr | 244 updates[param] = param - gparam * pretrain_lr |
251 | 245 |
252 # create a function that trains the dA | 246 # create a function that trains the dA |
253 update_fn = theano.function([ensemble], dA_layer.cost, \ | 247 update_fn = theano.function([self.x], dA_layer.cost, \ |
254 updates = updates, | 248 updates = updates)#, |
255 givens = { | 249 # givens = { |
256 self.x : ensemble}) | 250 # self.x : ensemble}) |
251 # collect this function into a list | |
252 #update_fn = theano.function([index], dA_layer.cost, \ | |
253 # updates = updates, | |
254 # givens = { | |
255 # self.x : train_set_x[index*batch_size:(index+1)*batch_size] / self.shared_divider}) | |
257 # collect this function into a list | 256 # collect this function into a list |
258 self.pretrain_functions += [update_fn] | 257 self.pretrain_functions += [update_fn] |
259 | 258 |
260 | 259 |
261 # We now need to add a logistic layer on top of the MLP | 260 # We now need to add a logistic layer on top of the MLP |
274 # compute list of updates | 273 # compute list of updates |
275 updates = {} | 274 updates = {} |
276 for param,gparam in zip(self.params, gparams): | 275 for param,gparam in zip(self.params, gparams): |
277 updates[param] = param - gparam*finetune_lr | 276 updates[param] = param - gparam*finetune_lr |
278 | 277 |
279 self.finetune = theano.function([ensemble_x,ensemble_y], cost, | 278 self.finetune = theano.function([self.x,self.y], cost, |
280 updates = updates, | 279 updates = updates)#, |
281 givens = { | 280 # givens = { |
282 #self.x : train_set_x[index*batch_size:(index+1)*batch_size]/self.shared_divider, | 281 # self.x : train_set_x[index*batch_size:(index+1)*batch_size]/self.shared_divider, |
283 #self.y : train_set_y[index*batch_size:(index+1)*batch_size]} ) | 282 # self.y : train_set_y[index*batch_size:(index+1)*batch_size]} ) |
284 self.x : ensemble_x, | |
285 self.y : ensemble_y} ) | |
286 | 283 |
287 # symbolic variable that points to the number of errors made on the | 284 # symbolic variable that points to the number of errors made on the |
288 # minibatch given by self.x and self.y | 285 # minibatch given by self.x and self.y |
289 | 286 |
290 self.errors = self.logLayer.errors(self.y) | 287 self.errors = self.logLayer.errors(self.y) |
288 | |
291 | 289 |
292 if __name__ == '__main__': | 290 if __name__ == '__main__': |
293 import sys | 291 import sys |
294 args = sys.argv[1:] | 292 args = sys.argv[1:] |
295 | 293 |