Skip to content

Instantly share code, notes, and snippets.

@Blaizzy
Last active April 10, 2019 10:07
Show Gist options
  • Select an option

  • Save Blaizzy/67a7dd67d9ef7596c1d1fca586cfadee to your computer and use it in GitHub Desktop.

Select an option

Save Blaizzy/67a7dd67d9ef7596c1d1fca586cfadee to your computer and use it in GitHub Desktop.
# Getting Data
from keras.datasets import mnist
from keras.utils import to_categorical
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
train_images = train_images.reshape((60000,28,28,1)) # (n_imgs, h, w, channels)
train_images = train_images.astype('float32')/ 255.
test_images = test_images.reshape((10000,28,28,1))
test_images = test_images.astype('float32') / 255.
model.compile(optimizer = 'rmsprop',
loss = 'categorical_crossentropy',
metrics = ['accuracy'])
model.fit(train_images, train_labels, epochs = 5, batch_size = 64)
# Testing
test_loss, test_acc = model.evaluate(test_images, test_labels)
print('{}% accurate'.format(test_acc*100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment