U E D R , A S I H C RSS

머신러닝스터디/2016/2016_06_18 (rev. 1.1)

머신러닝스터디/2016/2016_06_18

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.datasets import mnist
from keras.layers.core import Reshape
from keras.utils.np_utils import to_categorical
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'])


model.fit(X_train, to_categorical(y_train, 10),
          nb_epoch=3,
          batch_size=200)

score = model.evaluate(X_test, to_categorical(y_test, 10), batch_size=10000)

print(score)

# output
print(model.predict(np.array([X_test[0]])))
print(y_test[0])
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:27
Processing time 0.0194 sec