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

Function test_DBN

code/DBN.py:281–433  ·  view source on GitHub ↗

Demonstrates how to train and test a Deep Belief Network. This is demonstrated on MNIST. :type finetune_lr: float :param finetune_lr: learning rate used in the finetune stage :type pretraining_epochs: int :param pretraining_epochs: number of epoch to do pretraining :ty

(finetune_lr=0.1, pretraining_epochs=100,
             pretrain_lr=0.01, k=1, training_epochs=1000,
             dataset='mnist.pkl.gz', batch_size=10)

Source from the content-addressed store, hash-verified

279
280
281def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
282 pretrain_lr=0.01, k=1, training_epochs=1000,
283 dataset='mnist.pkl.gz', batch_size=10):
284 """
285 Demonstrates how to train and test a Deep Belief Network.
286
287 This is demonstrated on MNIST.
288
289 :type finetune_lr: float
290 :param finetune_lr: learning rate used in the finetune stage
291 :type pretraining_epochs: int
292 :param pretraining_epochs: number of epoch to do pretraining
293 :type pretrain_lr: float
294 :param pretrain_lr: learning rate to be used during pre-training
295 :type k: int
296 :param k: number of Gibbs steps in CD/PCD
297 :type training_epochs: int
298 :param training_epochs: maximal number of iterations ot run the optimizer
299 :type dataset: string
300 :param dataset: path the the pickled dataset
301 :type batch_size: int
302 :param batch_size: the size of a minibatch
303 """
304
305 datasets = load_data(dataset)
306
307 train_set_x, train_set_y = datasets[0]
308 valid_set_x, valid_set_y = datasets[1]
309 test_set_x, test_set_y = datasets[2]
310
311 # compute number of minibatches for training, validation and testing
312 n_train_batches = train_set_x.get_value(borrow=True).shape[0] // batch_size
313
314 # numpy random generator
315 numpy_rng = numpy.random.RandomState(123)
316 print('... building the model')
317 # construct the Deep Belief Network
318 dbn = DBN(numpy_rng=numpy_rng, n_ins=28 * 28,
319 hidden_layers_sizes=[1000, 1000, 1000],
320 n_outs=10)
321
322 # start-snippet-2
323 #########################
324 # PRETRAINING THE MODEL #
325 #########################
326 print('... getting the pretraining functions')
327 pretraining_fns = dbn.pretraining_functions(train_set_x=train_set_x,
328 batch_size=batch_size,
329 k=k)
330
331 print('... pre-training the model')
332 start_time = timeit.default_timer()
333 # Pre-train layer-wise
334 for i in range(dbn.n_layers):
335 # go through pretraining epochs
336 for epoch in range(pretraining_epochs):
337 # go through the training set
338 c = []

Callers 1

DBN.pyFile · 0.85

Calls 5

pretraining_functionsMethod · 0.95
load_dataFunction · 0.90
DBNClass · 0.85
train_fnFunction · 0.85

Tested by

no test coverage detected