In this example, we are going to implement a complete deep convolutional network using Keras and the original MNIST handwritten digits dataset (available through a Keras utility function). It is made up of 60,000 grayscale 28 × 28 images for training and 10,000 for testing the model. An example is shown in the following screenshot:
Samples extracted from the original MNIST dataset
The first step consists in loading and normalizing the dataset so that each sample contains values bounded between 0 and 1:
from keras.datasets import mnist
(X_train, Y_train), (X_test, Y_test) = mnist.load_data()
width = height = X_train.shape[1]
X_train = X_train.reshape((X_train.shape[0], width, height, 1)).astype(np.float32) / 255.0
X_test = X_test.reshape((X_test.shape[0], width, height, 1)).astype(np.float32) / 255.0
The labels can be obtained...