Example #1
0
import numpy as np
from keras.models import Sequential  # Keras Model
from keras.layers import Dense, Dropout, Activation, Flatten  # Keras Layers
from keras.layers import Convolution2D, MaxPooling2D  # Keras CNN Layers
from keras.utils import np_utils
from matplotlib import pyplot as plt
from keras.datasets import mnist
from dataset import MNIST
from tempo_layer import DigitTempotronLayer

# With 50 training images and 50 testing images
# x_train should be 50*10*10 matrix, x_test should be 50*10*10 matrix
# y_train should be 50*1 vector, y_test should be 50*1 vector
dtl = DigitTempotronLayer()
dataset = MNIST(n_components=100, reshape=False)
np.random.seed(7)  # for reproducibility
max_voltage = 64

# Training data
x_train, y_train = dtl.get_layer_output()
X_train = x_train.astype('float32') / max_voltage # normalize
Y_train = np_utils.to_categorical(y_train) # 50*10 one hot matrix (encoded outputs)

# Testing data
y_test = np.array(y_train, copy=True)
x_test = np.array(x_train, copy=True)

new_x = []
for digit in range(10): # 0->9
    for vector in dataset.new_sample(1, digit):
        print('c**k {}'.format(digit))
Example #2
0
import numpy as np
from keras.models import Sequential  # Keras Model
from keras.layers import Dense, Dropout, Activation, Flatten  # Keras Layers
from keras.layers import Convolution2D, MaxPooling2D  # Keras CNN Layers
from keras.utils import np_utils
from matplotlib import pyplot as plt
from keras.datasets import mnist
from tempo_layer import DigitTempotronLayer

np.random.seed(7)  # for reproducibility

# load data, output matrices from tempotron
# With 50 training images and 50 testing images
# x_train should be 50*10 matrix, x_test should be 50*10 matrix
# y_train should be 50*1 vector, y_test should be 50*1 vector
dtl = DigitTempotronLayer()
x_train = dtl.get_layer_output()[0]
x_test = x_train
y_train = dtl.get_layer_output()[1]
y_test = y_train
#(x_train, y_train), (x_test, y_test) = mnist.load_data()
#x_train = x_train.reshape(x_train.shape[0], 784)
#x_test = x_test.reshape(x_test.shape[0], 784)

# Preprocess Input Matrices
X_train = x_train.astype('float32')
X_test = x_test.astype('float32')

# normalize voltage inputs
max_voltage = 90
X_train = X_train / max_voltage
Example #3
0
from keras.layers import Dense, Dropout, Activation, Flatten  # Keras Layers
from keras.layers import Convolution2D, MaxPooling2D  # Keras CNN Layers
from keras.utils import np_utils
from matplotlib import pyplot as plt
from keras.datasets import mnist
from tempo_layer import DigitTempotronLayer
from dataset import MNIST


np.random.seed(7)  # for reproducibility

# With 50 training images and 50 testing images
# x_train should be 50*10*10 matrix, x_test should be 50*10*10 matrix
# y_train should be 50*1 vector, y_test should be 50*1 vector

dtl = DigitTempotronLayer()
dataset = MNIST(n_components=100, reshape=False)

y_train, y_test = [dtl.get_layer_output()[1] for i in range(2)]
samples = []
for digit in range(10): # 0->9
    for ten_by_ten_matrix in dataset.sample(5, digit, digit): # 5 x 'digit'
        samples.append(ten_by_ten_matrix)
samples = np.asarray(samples)
samples = samples.reshape(50, 100)

# Preprocess Input Matrices
X_train, X_test = [samples.astype('float32') for i in range(2)]

# Y_train should be 50*10 one hot matrix (encoded outputs)
# Y_test should be 50*10 one hot matrix (encoded outputs)