Mercurial > ift6266
comparison deep/stacked_dae/v2/stacked_dae.py @ 239:42005ec87747
Mergé (manuellement) les changements de Sylvain pour utiliser le code de dataset d'Arnaud, à cette différence près que je n'utilse pas les givens. J'ai probablement une approche différente pour limiter la taille du dataset dans mon débuggage, aussi.
author | fsavard |
---|---|
date | Mon, 15 Mar 2010 18:30:21 -0400 |
parents | 02eb98d051fe |
children |
comparison
equal
deleted
inserted
replaced
238:9fc641d7adda | 239:42005ec87747 |
---|---|
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 | 204 |
208 for i in xrange( self.n_layers ): | 205 for i in xrange( self.n_layers ): |
245 updates = {} | 242 updates = {} |
246 for param, gparam in zip(dA_layer.params, gparams): | 243 for param, gparam in zip(dA_layer.params, gparams): |
247 updates[param] = param - gparam * pretrain_lr | 244 updates[param] = param - gparam * pretrain_lr |
248 | 245 |
249 # create a function that trains the dA | 246 # create a function that trains the dA |
250 update_fn = theano.function([index], dA_layer.cost, \ | 247 update_fn = theano.function([self.x], dA_layer.cost, \ |
251 updates = updates, | 248 updates = updates)#, |
252 givens = { | 249 # givens = { |
253 self.x : train_set_x[index*batch_size:(index+1)*batch_size] / self.shared_divider}) | 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}) | |
254 # collect this function into a list | 256 # collect this function into a list |
255 self.pretrain_functions += [update_fn] | 257 self.pretrain_functions += [update_fn] |
256 | 258 |
257 | 259 |
258 # 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 |
271 # compute list of updates | 273 # compute list of updates |
272 updates = {} | 274 updates = {} |
273 for param,gparam in zip(self.params, gparams): | 275 for param,gparam in zip(self.params, gparams): |
274 updates[param] = param - gparam*finetune_lr | 276 updates[param] = param - gparam*finetune_lr |
275 | 277 |
276 self.finetune = theano.function([index], cost, | 278 self.finetune = theano.function([self.x,self.y], cost, |
277 updates = updates, | 279 updates = updates)#, |
278 givens = { | 280 # givens = { |
279 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, |
280 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]} ) |
281 | 283 |
282 # 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 |
283 # minibatch given by self.x and self.y | 285 # minibatch given by self.x and self.y |
284 | 286 |
285 self.errors = self.logLayer.errors(self.y) | 287 self.errors = self.logLayer.errors(self.y) |