Learn practical skills, build real-world projects, and advance your career

Handwritten Digit Recognition

Objective: Classify handwritten digits from the MNIST dataset by training a convolutional neural network (CNN) using the Keras deep learning library.

Data Preparation

We begin by downloading the data and creating training & validation sets. Keras has inbuilt helper functions to do this.

from keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
Using TensorFlow backend.

Each sample is a 28px x 28 px image, flattened out a vector of length 784 i.e. 28x28.

train_images[0].shape, train_labels[0]
((28, 28), 5)