Ejemplo n.º 1
0
        if brick.name == 'encoder':
            encoder = brick
        if brick.name == 'decoder':
            generator = brick

    # Copy-pasted from https://github.com/fchollet/keras/blob/master/examples/variational_autoencoder.py
    x_test, y_test = MNIST(("test", )).get_data(state=None,
                                                request=range(10000))
    a = T.matrix(u'features')
    b = encoder.apply(a)
    c = generator.apply(a)
    encode = theano.function([a], [b])
    generate = theano.function([a], [c])

    # display a 2D plot of the digit classes in the latent space
    x_test_encoded = encode(x_test.reshape((10000, 784)))[0]
    y_test = y_test.reshape((10000, )).astype('uint8')
    #import ipdb; ipdb.set_trace()
    plt.figure(figsize=(6, 6))
    plt.scatter(x_test_encoded[:, 0], x_test_encoded[:, 1], c=y_test)
    plt.colorbar()
    plt.show()

    # display a 2D manifold of the digits
    n = 15  # figure with 15x15 digits
    digit_size = 28
    figure = np.zeros((digit_size * n, digit_size * n))
    # we will sample n points within [-15, 15] standard deviations
    grid_x = np.linspace(-15, 15, n)
    grid_y = np.linspace(-15, 15, n)