from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.datasets import mnist
from keras.layers.core import Reshape
import numpy as np
(X_train, y_train), (X_test, y_test) = mnist.load_data()
model = Sequential()
model.add(Reshape((28*28,), input_shape=(28,28)))
model.add(Dense(60000, input_dim=28*28, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adagrad',
metrics=['accuracy'])
# y_train and y_test is simple integer of 0 to 9
# Need to be transformed to array
y_train_array = np.zeros((60000, 10))
y_test_array = np.zeros((10000, 10))
for i in range(60000):
y_train_array[i][y_train[i]] = 1
for i in range(10000):
y_test_array[i][y_test[i]] = 1
model.fit(X_train, y_train_array,
nb_epoch=3,
batch_size=16)
score = model.evaluate(X_test, y_test_array, batch_size=10000)
# TODO
print(score)