This lab started out its life as a Keras practical developed for the VLC group based on Jason Brownlee’s “Handwritten Digit Recognition using Convolutional Neural Networks in Python with Keras” tutorial. It subsequently evolved as it was used in tutorials run for external organisations including Ordnance Survey, Lloyds Register and DISCNet.
This version is refocussed on using PyTorch with Torchbearer. A number of changes have been made to ensure that it better fits our format and I’ve also added additional information and exercises throughout.
A popular demonstration of the capability of deep learning techniques is object recognition in image data. The “hello world” of object recognition for machine learning and deep learning is the MNIST dataset for handwritten digit recognition.
In this lab you will discover how to develop a simple neural network model to achieve good performance on the MNIST handwritten digit recognition task in Python using the PyTorch deep learning library.
Through this lab you’ll learn how to:
To work through this lab you’ll use the Python 3 language in a Jupyter Notebook environment, with the
pytorch tensor library, the
torchvision utility library and the
torchbearer model training library. We’ll also use the
numpy packages. We will primarily be using Google Colab to run the notebooks as this gives you access to an environment with all the tools required. If you wish to run the notebooks locally, see the information in the section below.
The following is a list of the notebooks for this lab, with links to open directly in Google Colab (once opened you should immediately save a copy in your Google Drive otherwise anything you do will be lost once the browser closes), or to download locally. You should work through the notebooks in numeric order as they follow on from each other.
|4.1 Introducing MNIST||preview||download|
|4.2 Implementing an MLP classifier||preview||download|
|4.3 Training and evaluating an MLP classifier with Torchbearer||preview||download|
|4.4 Using GPU acceleration with PyTorch||preview||download|
You’ll need access to a computer with the following installed:
If you want to work on your own machine we recommend using the Anaconda python distribution. Running
conda install pytorch torchvision -c pytorch (see https://pytorch.org/get-started/locally/ for more options) will install both pytorch and torchvision. Torchbearer can be installed with
pip install torchbearer. With the exception of the part of the tutorial that looks at enabling hardware acceleration, the entire lab can be performed on the CPU - some bits of training could take up to a couple of minutes however.