comparison deep/stacked_dae/stacked_dae.py @ 185:b9ea8e2d071a

Enlevé ce qui concernait la réutilisation de résultats de préentraînement (trop compliqué pour peu de bénéfice: c'est le finetuning qui est vraiment long
author fsavard
date Fri, 26 Feb 2010 17:45:52 -0500
parents 1f5937e9e530
children d364a130b221
comparison
equal deleted inserted replaced
172:4d3d3627df3e 185:b9ea8e2d071a
142 142
143 class SdA(object): 143 class SdA(object):
144 def __init__(self, train_set_x, train_set_y, batch_size, n_ins, 144 def __init__(self, train_set_x, train_set_y, batch_size, n_ins,
145 hidden_layers_sizes, n_outs, 145 hidden_layers_sizes, n_outs,
146 corruption_levels, rng, pretrain_lr, finetune_lr, input_divider=1.0): 146 corruption_levels, rng, pretrain_lr, finetune_lr, input_divider=1.0):
147 # Just to make sure those are not modified somewhere else afterwards
148 hidden_layers_sizes = copy.deepcopy(hidden_layers_sizes)
149 corruption_levels = copy.deepcopy(corruption_levels)
147 update_locals(self, locals()) 150 update_locals(self, locals())
148 151
149 self.layers = [] 152 self.layers = []
150 self.pretrain_functions = [] 153 self.pretrain_functions = []
151 self.params = [] 154 self.params = []
237 # symbolic variable that points to the number of errors made on the 240 # symbolic variable that points to the number of errors made on the
238 # minibatch given by self.x and self.y 241 # minibatch given by self.x and self.y
239 242
240 self.errors = self.logLayer.errors(self.y) 243 self.errors = self.logLayer.errors(self.y)
241 244
242 @classmethod
243 def copy_reusing_lower_layers(cls, obj, num_hidden_layers, new_finetuning_lr=None):
244 assert(num_hidden_layers <= obj.n_layers)
245
246 if not new_finetuning_lr:
247 new_finetuning_lr = obj.finetune_lr
248
249 new_sda = cls(train_set_x= obj.train_set_x, \
250 train_set_y = obj.train_set_y,\
251 batch_size = obj.batch_size, \
252 n_ins= obj.n_ins, \
253 hidden_layers_sizes = obj.hidden_layers_sizes[:num_hidden_layers], \
254 n_outs = obj.n_outs, \
255 corruption_levels = obj.corruption_levels[:num_hidden_layers],\
256 rng = obj.rng,\
257 pretrain_lr = obj.pretrain_lr, \
258 finetune_lr = new_finetuning_lr, \
259 input_divider = obj.input_divider )
260
261 # new_sda.layers contains only the hidden layers actually
262 for i, layer in enumerate(new_sda.layers):
263 original_layer = obj.layers[i]
264 for p1,p2 in zip(layer.params, original_layer.params):
265 p1.value = p2.value.copy()
266
267 return new_sda
268
269 def get_params_copy(self):
270 return copy.deepcopy(self.params)
271
272 def set_params_from_copy(self, copy):
273 # We don't want to replace the var, as the functions have pointers in there
274 # We only want to replace values.
275 for i, p in enumerate(self.params):
276 p.value = copy[i].value
277
278 def get_params_means(self):
279 s = []
280 for p in self.params:
281 s.append(numpy.mean(p.value))
282 return s
283
284 if __name__ == '__main__': 245 if __name__ == '__main__':
285 import sys 246 import sys
286 args = sys.argv[1:] 247 args = sys.argv[1:]
287 248