MNIST Digits Convolutional Neural Network

Convolutional neural networks are extremely powerful to extract spatial features. This network architecture allows us to build deep networks, with multiple convolution and pooling layers. Each convolution filter extracts important features regarding patterns, borders and neighborhood while the pooling kernels reduce the data size, applying pooling functions as max-pool or average-pool to mantain local informations.

Usually this type of network has several layers and filters and easily can sum up above hundreds of thousands of parameters. If the model is applied to analyze bigger sized colorful images, it can easily reach millions of parameters. It takes much more time to fit the model than the regular feedforward network and also may require thousands of epochs for training, which may take hours to days of training.

We will start by analyzing simpler classification problems and scale up to the full training set.

Initial analysis

Since we are creating and evaluating several neural network models, we define first some functions, for creating and training models and plotting their metrics.

Binary classification: digits 2 and 7

We start our convolutional network analysis by using it for a binary classification between digits 2 and 7. A binary classification involves simpler functions and less features than the entire dataset. Regarding our model, the significant differences between a binary and multi-class classification are:

Our first model has: 3 convolutional layers, interleaved by 2 pooling layers, and a full connection to a binary classification, 1 for digit "2", 0 for digit "7".

The first convolutional layer has 16 filters with 3x3 kernel while the other two have 32 filters with 3x3 kernel. The pooling layers are max-pooling with 2x2 kernel. Before flattening the data, we have 32 kernels 3x3, which them are fully connected to the hidden layer. This layer has 32 nodes with activation function ReLU and binary classification with sigmoidal function. For optimizer we use the Adam algorithm, an extension to stochastic gradient descent method, which is the most recommended one for general problems.

For the model training we apply the entire training set containing digits 2 and 7.