Example #1
0
import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt
from neupy import algorithms, layers, environment


environment.reproducible()
environment.speedup()

mnist = datasets.fetch_mldata('MNIST original')

data = (mnist.data / 255.).astype(np.float32)

np.random.shuffle(data)
x_train, x_test = data[:60000], data[60000:]
x_train_4d = x_train.reshape((60000, 1, 28, 28))
x_test_4d = x_test.reshape((10000, 1, 28, 28))

conv_autoencoder = algorithms.Momentum(
    [
        layers.Input((1, 28, 28)),

        layers.Convolution((16, 3, 3)) > layers.Relu(),
        layers.Convolution((16, 3, 3)) > layers.Relu(),
        layers.MaxPooling((2, 2)),

        layers.Convolution((32, 3, 3)) > layers.Relu(),
        layers.MaxPooling((2, 2)),

        layers.Reshape(),
Example #2
0
import numpy as np

from sklearn.model_selection import train_test_split
from neupy import algorithms, layers, environment
from neupy.datasets import reber

environment.reproducible()
environment.speedup()


def add_padding(data):
    n_sampels = len(data)
    max_seq_length = max(map(len, data))

    data_matrix = np.zeros((n_sampels, max_seq_length))
    for i, sample in enumerate(data):
        data_matrix[i, -len(sample):] = sample

    return data_matrix


# An example of possible values for the `data` and `labels`
# variables
#
# >>> data
# array([array([1, 3, 1, 4]),
#        array([0, 3, 0, 3, 0, 4, 3, 0, 4, 4]),
#        array([0, 3, 0, 0, 3, 0, 4, 2, 4, 1, 0, 4, 0])], dtype=object)
# >>>
# >>> labels
# array([1, 0, 0])
Example #3
0
    def test_speedup_environment(self):
        environment.speedup()

        self.assertEqual(theano.config.floatX, 'float32')
        self.assertEqual(theano.config.allow_gc, False)