In [1]:
import keras
import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
import pickle
from keras.layers import Convolution2D, MaxPooling2D
from keras.utils import np_utils


Using TensorFlow backend.

In [4]:
from keras.datasets import mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()


Downloading data from https://s3.amazonaws.com/img-datasets/mnist.npz
11075584/11490434 [===========================>..] - ETA: 0s 

In [5]:
from matplotlib import pyplot as plt
plt.imshow(X_train[0])


Out[5]:
<matplotlib.image.AxesImage at 0x235543aaa20>

In [6]:
X_train = X_train.reshape(X_train.shape[0], 1, 28, 28)
X_test = X_test.reshape(X_test.shape[0], 1, 28, 28)

In [8]:
print(X_train.shape)
# (60000, 1, 28, 28)


(60000, 1, 28, 28)

In [9]:
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255

In [13]:
print(y_train.shape)
print(y_train[:10])


(60000,)
[5 0 4 1 9 2 1 3 1 4]

In [14]:
Y_train = np_utils.to_categorical(y_train, 10)
Y_test = np_utils.to_categorical(y_test, 10)

In [15]:
print(Y_train.shape)


(60000, 10)

In [ ]: