Created
October 17, 2017 21:20
-
-
Save bzamecnik/149460c110a612dcef45e7df33db263b to your computer and use it in GitHub Desktop.
Tiny MLP on MNIST with Keras - stripped down from Keras examples, functional model API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.datasets import mnist | |
from keras.models import Model | |
from keras.layers import Dense, Input | |
from keras.utils import to_categorical | |
num_classes = 10 | |
(x_train, y_train), (x_test, y_test) = mnist.load_data() | |
x_train = x_train.reshape(60000, 784).astype('float32') / 255 | |
y_train = to_categorical(y_train, num_classes) | |
image = Input(shape=(784,)) | |
x = Dense(512, activation='relu')(image) | |
digit = Dense(num_classes, activation='softmax')(x) | |
model = Model(inputs=image, outputs=digit) | |
model.compile(optimizer='sgd', loss='categorical_crossentropy') | |
history = model.fit(x_train, y_train, batch_size=128, epochs=1, verbose=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment