I am working with Neural Nets, I want to implement it on an FPGA. I have a code working on MNIST, and I want to obtain the initial weights using float32, and then retrain the weights on the FPGA with fixed point.
I am running my simulation in python. I am looking for a way to do this conversion
from keras.datasets import mnist
from keras.layers import Dense
from keras.models import Sequential
from keras.layers import Dropout
from keras.utils import np_utils
import matplotlib.pyplot as plt
(x, y), (X, Y) = mnist.load_data()
num = x.shape[1] * x.shape[2]
x = x.reshape(x.shape[0],x.shape[1]*x.shape[2]).astype('float32')
X = X.reshape(X.shape[0],X.shape[1]*X.shape[2]).astype('float32')
x = x/255
X = X/255
y = np_utils.to_categorical(y)
Y = np_utils.to_categorical(Y)
classes = y.shape[1]
def calc():
model = Sequential()
model.add(Dense(num, input_dim = num, init = 'normal', activation = 'relu'))
model.add(Dense(classes, init = 'normal', activation = 'softmax'))
model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
return model
model = calc()
model.fit(x, y, validation_data=(X, Y), nb_epoch=10, batch_size=200,
verbose=2)
scores = model.evaluate(X, Y, verbose=0)
print("Accuracy: ", scores)