'hidden_size': 500, 'k': 15, 'weights_init': 'uniform', 'weights_interval': 4 * numpy.sqrt(6. / 28 * 28 + 500), 'mrg': mrg } rbm = RBM(**config_args) # rbm.load_params('rbm_trained.pkl') optimizer = Optimizer(learning_rate=0.1, model=rbm, dataset=mnist, batch_size=20, epochs=15) ll = Monitor('pseudo-log', rbm.get_monitors()['pseudo-log']) # perform training! optimizer.train(monitor_channels=ll) # test it on some images! test_data = mnist.test_inputs[:25] # use the run function! preds = rbm.run(test_data) # Construct image from the test matrix image = Image.fromarray( tile_raster_images(X=test_data, img_shape=(28, 28), tile_shape=(5, 5), tile_spacing=(1, 1))) image.save('rbm_test.png')
rng = numpy.random.RandomState(1234) mrg = theano.tensor.shared_randomstreams.RandomStreams(rng.randint(2 ** 30)) config_args = { "input_size": 28 * 28, "hidden_size": 500, "k": 15, "weights_init": "uniform", "weights_interval": 4 * numpy.sqrt(6.0 / 28 * 28 + 500), "mrg": mrg, } rbm = RBM(**config_args) # rbm.load_params('rbm_trained.pkl') optimizer = Optimizer(learning_rate=0.1, model=rbm, dataset=mnist, batch_size=20, epochs=15) ll = Monitor("pseudo-log", rbm.get_monitors()["pseudo-log"]) # perform training! optimizer.train(monitor_channels=ll) # test it on some images! test_data = mnist.test_inputs[:25] # use the run function! preds = rbm.run(test_data) # Construct image from the test matrix image = Image.fromarray(tile_raster_images(X=test_data, img_shape=(28, 28), tile_shape=(5, 5), tile_spacing=(1, 1))) image.save("rbm_test.png") # Construct image from the preds matrix image = Image.fromarray(tile_raster_images(X=preds, img_shape=(28, 28), tile_shape=(5, 5), tile_spacing=(1, 1))) image.save("rbm_preds.png")