Introduction
We will train the Apache MXNet* Gluon model in Amazon SageMaker* to read handwritten numbers of MNIST dataset and then run the prediction for ten random handwritten numbers on IEI Tank* AIoT Developer Kit. More information about IEI Tank* AIoT Developer Kit.
Amazon SageMaker is a platform that enables easy deployment of machine learning models, using Jupyter* Notebooks and AWS* S3 object storage. More information about Amazon SageMaker.
Gluon is a new MXNet library that provides a simple API for prototyping, building, and training deep learning models. We will need MXNet estimator in order to run a MXNet model in Amazon SageMaker. More information about MXNet Gluon models.
Prerequisites
- IEI Tank* AIoT Developer Kit
- Linux* Ubuntu* 16.04 OS
- Python* 2.7
- AWS account
Train a Model
Sign in to your AWS account and go to the Amazon SageMaker.
Create a notebook instance:
Fill out notebook instance name, add the IAM role, and select Create notebook instance:
You will see the confirmation on top of the page and the new notebook instance:
Create a new notebook file by selecting New > conda_mxnet_p27:
Select Untitled and change the name to training. Select Insert > Insert Cell Below to add cells.
Copy each cell of the Jupyter* Notebook training.ipynb into the cell of your notebook. Find training.ipynb at the end of the tutorial in the Sample Code section. Go to notebook instance and add mxnet-mnist.py (find it in the Sample Code section) by selecting Upload.
Select Upload:
Go back to training.ipynb and run it by selecting Cell > Run All:
Get the information about S3 bucket and training job name:
Wait for the all cells to complete running. You will see output similar to this:
Run Prediction
Go to the Amazon S3 > S3 bucket > training job > output:
Download the model.tar.gz by clicking on the check box next to it and selecting Download from the right-side menu.
On the Tank, extract the model.params file from the downloaded archive.
tar –xzvf model.tar.gz
If needed, install dependencies.
sudo pip2 install mxnet matplotlib
Save load.py (find it in the Sample Code) in the same folder as model.params.
Run load.py:
python load.py
You will see the images of ten random handwritten numbers and the model’s predictions for them:
Conclusion
We have successfully trained the MXNet Gluon model in Amazon SageMaker to read handwritten numbers and got a great prediction for the validation set on Tank.
Sample Code
training.ipynb:
mxnet-mnist.py:
load.py:
About the Author
Rosalia Nyurguhun is a software engineer at Intel in the Core and Visual Computing Group working on scale enabling projects for Internet of Things.