View on GitHub

MNIST

MNIST Digits Classification with numpy only

by Valentyn Sichkar     Academia.edu     YouTube

MNIST Digits Classification with numpy only

Example on Digits Classification with the help of MNIST dataset of handwritten digits and Convolutional Neural Network.
DOI

Test online here

Content

Short description of the content. Full codes you can find inside the course by link above:


MNIST Digits Classification with numpy only

In this example we’ll test CNN for Digits Classification with the help of MNIST dataset.
Following standard and most common parameters can be used and tested:

Parameter Description
Weights Initialization HE Normal
Weights Update Policy Vanilla SGD, Momentum SGD, RMSProp, Adam
Activation Functions ReLU, Sigmoid
Regularization L2, Dropout
Pooling Max, Average
Loss Functions Softmax, SVM


Contractions:


For current example following architecture will be used:
Input –> Conv –> ReLU –> Pool –> Affine –> ReLU –> Affine –> Softmax


For current example following parameters will be used:

Parameter Description
Weights Initialization HE Normal
Weights Update Policy Vanilla SGD
Activation Functions ReLU
Regularization L2
Pooling Max
Loss Functions Softmax


Loading MNIST dataset

After downloading files from official resource, there has to be following files:


Plotting examples of digits from MNIST dataset

After dataset was load, it is possible to show examples of training images.

Result can be seen on the image below.

MNIST_examples


Preprocessing loaded MNIST dataset

Next, creating function for preprocessing MNIST dataset for further use in classifier.

As a result there will be following:


Saving and Loading serialized models

Saving loaded and preprocessed data into ‘pickle’ file.


Functions for dealing with CNN layers

Creating functions for CNN layers:


Creating Classifier - model of CNN

Creating model of CNN Classifier:


Defining Functions for Optimization

Using different types of optimization rules to update parameters of the Model.

Vanilla SGD updating method

Rule for updating parameters is as following:

Vanilla SGD


Creating Solver Class

Creating Solver class for training classification models and for predicting:


Overfitting Small Data

Overfitting Small Data


Training Results

Training process of Model #1 with 12 000 iterations is shown on the figure below:

Training Model 1

Initialized Filters and Trained Filters for ConvNet Layer is shown on the figure below:

Filters Cifar10

Training process for Filters of ConvNet Layer is shown on the figure below:

Training Filters Cifar10


MIT License

github.com/sichkar-valentyn

Reference to:

Valentyn N Sichkar. Neural Networks for computer vision in autonomous vehicles and robotics // GitHub platform. DOI: 10.5281/zenodo.1317904