MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / test_SdA

Function test_SdA

code/SdA.py:329–487  ·  view source on GitHub ↗

Demonstrates how to train and test a stochastic denoising autoencoder. This is demonstrated on MNIST. :type learning_rate: float :param learning_rate: learning rate used in the finetune stage (factor for the stochastic gradient) :type pretraining_epochs: int :param pr

(finetune_lr=0.1, pretraining_epochs=15,
             pretrain_lr=0.001, training_epochs=1000,
             dataset='mnist.pkl.gz', batch_size=1)

Source from the content-addressed store, hash-verified

327
328
329def test_SdA(finetune_lr=0.1, pretraining_epochs=15,
330 pretrain_lr=0.001, training_epochs=1000,
331 dataset='mnist.pkl.gz', batch_size=1):
332 """
333 Demonstrates how to train and test a stochastic denoising autoencoder.
334
335 This is demonstrated on MNIST.
336
337 :type learning_rate: float
338 :param learning_rate: learning rate used in the finetune stage
339 (factor for the stochastic gradient)
340
341 :type pretraining_epochs: int
342 :param pretraining_epochs: number of epoch to do pretraining
343
344 :type pretrain_lr: float
345 :param pretrain_lr: learning rate to be used during pre-training
346
347 :type n_iter: int
348 :param n_iter: maximal number of iterations ot run the optimizer
349
350 :type dataset: string
351 :param dataset: path the the pickled dataset
352
353 """
354
355 datasets = load_data(dataset)
356
357 train_set_x, train_set_y = datasets[0]
358 valid_set_x, valid_set_y = datasets[1]
359 test_set_x, test_set_y = datasets[2]
360
361 # compute number of minibatches for training, validation and testing
362 n_train_batches = train_set_x.get_value(borrow=True).shape[0]
363 n_train_batches //= batch_size
364
365 # numpy random generator
366 # start-snippet-3
367 numpy_rng = numpy.random.RandomState(89677)
368 print('... building the model')
369 # construct the stacked denoising autoencoder class
370 sda = SdA(
371 numpy_rng=numpy_rng,
372 n_ins=28 * 28,
373 hidden_layers_sizes=[1000, 1000, 1000],
374 n_outs=10
375 )
376 # end-snippet-3 start-snippet-4
377 #########################
378 # PRETRAINING THE MODEL #
379 #########################
380 print('... getting the pretraining functions')
381 pretraining_fns = sda.pretraining_functions(train_set_x=train_set_x,
382 batch_size=batch_size)
383
384 print('... pre-training the model')
385 start_time = timeit.default_timer()
386 ## Pre-train layer-wise

Callers 1

SdA.pyFile · 0.70

Calls 5

pretraining_functionsMethod · 0.95
load_dataFunction · 0.90
SdAClass · 0.85
train_fnFunction · 0.85

Tested by

no test coverage detected