Classifying MNIST Images using CNTK v2.0

Microsoft’s CNTK is a code library that can do advanced machine learning. Version 2.0 is in Release Candidate mode as I’m writing this blog post. I thought I’d revisit the CNTK documentation at and run the MNIST image classification demo.

The MNIST (Modified National Institute of Standards and Technology) data set consists of 60,000 training images and 10,000 test images. Each image is 28-by-28 = 784 pixels of a handwritten digit between ‘0’ and ‘9’. See In the screenshot below, the data is for a digit ‘5’ (0 0 0 0 0 1 0 0 0 0) followed by the 784 pixel gray-scale values.

The goal is to create a neural network classifier that can accept an image and tell you what digit it represents.

The CNTK tutorial consists of two parts. The first part downloads all the MNIST data and then saves it in two text files using a special format that CNTK understands. CNTK is not directly used in the first part.

The second part actually creates a NN classifier with two hidden layers, each of which has 400 nodes.

The CNTK tutorials are presented as interactive Jupyter files. I’m not a fan of Jupyter when it comes to understanding code, so I refactored the tutorial code into plain Python. (CNTK is written in C++ for good performance but has a Python API for programming sanity).

The bottom line: CNTK v2.0 has a moderately steep learning curve; the curve depends to a large extent on your background in ML concepts and Python experience. It’s a serious library for serious ML work.

This entry was posted in CNTK, Machine Learning. Bookmark the permalink.