Skip to content

Instantly share code, notes, and snippets.

@peune
Last active January 12, 2019 14:36
Show Gist options
  • Save peune/1eaeaac16756920beae77e1a455f3ab6 to your computer and use it in GitHub Desktop.
Save peune/1eaeaac16756920beae77e1a455f3ab6 to your computer and use it in GitHub Desktop.
import os
import numpy as np
from keras.datasets import mnist
# load data and reshape the Tensors
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.astype(np.float32).reshape((X_train.shape[0],28,28)) / 255.0
X_test = X_test.astype(np.float32).reshape((X_test.shape[0],28,28)) / 255.0
# convert class vectors to binary class matrices
from keras.utils import np_utils
Y_train = np_utils.to_categorical(y_train, 10)
Y_test = np_utils.to_categorical(y_test, 10)
import matplotlib.pyplot as plt
for i in range(16):
plt.subplot(4,4,i+1)
plt.axis('off')
plt.imshow(X_train[i].reshape((28,28)))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment