-
Notifications
You must be signed in to change notification settings - Fork 0
/
MnistTest.py
31 lines (28 loc) · 911 Bytes
/
MnistTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
np.random.seed(1337)
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Dense,Activation
from keras.optimizers import RMSprop
(X_train,y_train),(X_test,y_test)=mnist.load_data()
X_train=X_train.reshape(X_train.shape[0],-1)/255
X_test=X_test.reshape(X_test.shape[0],-1)/255
y_train=np_utils.to_categorical(y_train,num_classes=10)
y_test=np_utils.to_categorical(y_test,num_classes=10)
model=Sequential([
Dense(32,input_dim=784),
Activation('relu'),
Dense(10),
Activation("softmax")
])
rmsprop=RMSprop()
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
print("Training...")
model.fit(X_train,y_train,nb_epoch=2)
print("Test...")
loss,accuracy=model.evaluate(X_test,y_test)
print("test loss : ",loss)
print("test accuracy : ",accuracy)