Skip to content

Instantly share code, notes, and snippets.

@clarkngo
Created November 30, 2020 04:51
Show Gist options
  • Save clarkngo/5c9781bf2816b0f1eebe6b4b3fa58f37 to your computer and use it in GitHub Desktop.
Save clarkngo/5c9781bf2816b0f1eebe6b4b3fa58f37 to your computer and use it in GitHub Desktop.
from keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
from keras import models
from keras import layers
network = models.Sequential()
network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,)))
network.add(layers.Dense(10, activation='softmax'))
network.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
train_images = train_images.reshape((60000, 28 * 28))
train_images = train_images.astype('float32') / 255
test_images = test_images.reshape((10000, 28 * 28))
test_images = test_images.astype('float32') / 255
from keras.utils import to_categorical
train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)
network.fit(train_images, train_labels, epochs=5, batch_size=128)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment