Пример #1
0
    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. / 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,