Skip to content

Instantly share code, notes, and snippets.

@mjbhobe
Created September 27, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjbhobe/8545167809a03bcb68b22e97464d69a3 to your computer and use it in GitHub Desktop.
Save mjbhobe/8545167809a03bcb68b22e97464d69a3 to your computer and use it in GitHub Desktop.
# some variables...
image_height = train_digits.shape[1]
image_width = train_digits.shape[2]
num_channels = 1 # we have grayscale images
# NOTE: image_height == image_width == 28
# re-shape the images data
train_data = np.reshape(train_digits, (train_digits.shape[0], image_height, image_width, num_channels))
test_data = np.reshape(test_digits, (test_digits.shape[0],image_height, image_width, num_channels))
# re-scale the image data to values between (0.0,1.0]
train_data = train_data.astype('float32') / 255.
test_data = test_data.astype('float32') / 255.
# one-hot encode the labels - we have 10 output classes
# so 3 -> [0 0 0 1 0 0 0 0 0 0], 5 -> [0 0 0 0 0 1 0 0 0 0] & so on
from keras.utils import to_categorical
num_classes = 10
train_labels_cat = to_categorical(train_labels,num_classes)
test_labels_cat = to_categorical(test_labels,num_classes)
train_labels_cat.shape, test_labels_cat.shape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment