This tutorial guides you through installing and using a Jupyter* notebook to set up and execute a TensorFlow* machine learning example using the MNIST data for handwriting recognition using the Clear Linux* OS for Intel® Architecture. The initial steps will have you set up a Jupyter kernel and run a notebook on a bare-metal Clear Linux system.
Install and configure a Clear Linux Host OS on bare metal
First, follow our instructions to install Clear Linux on bare metal.
Once the bare metal installation and initial configuration are complete, add the following two bundles to your system:
- machine-learning-web-ui: This bundle contains the Jupyter application.
- machine-learning-basic: This bundle contains TensorFlow and other useful tools.
To install the bundles, run the following commands in your $HOME directory:
sudo swupd bundle-add machine-learning-web-ui sudo swupd bundle-add machine-learning-basic
Set up a Jupyter notebook
With all required packages and libraries installed, set up the file structure for the Jupyter Notebook.
In the $HOME directory, create a directory for the Jupyter Notebooks named Notebooks.
Within Notebooks, create a directory named Handwriting.
Change to the new directory.
Copy the MNIST_example.ipynb file into the Handwriting directory.
After installing the machine-learning basic bundle, you can find the example code under /usr/share/doc/tensorflow/MNIST_example.ipynb.
The example code downloads and decompresses the MNIST data directly into the ./mnist directory. Alternatively, download the four files directly from the Yann LeCun’s MNIST Database website and save them into a mnist directory within the Handwriting directory.
The files needed are:
Run the Jupyter machine learning example code
With Clear Linux, Jupyter, and TensorFlow installed and configured, we can run the example code.
Go to the ($HOME)/Notebooks directory and start Jupyter with the following commands:
cd ~/Notebooks jupyter notebook
The Jupyter server starts and opens a web browser showing the Jupyter file manager with a list of files in the current directory, see figure 1.
Click on the Handwriting directory. The MNIST_example.ipynb file created earlier should be listed there, see figure 2.
To run the hand writing example, click on the MNIST_example.ipynb file to load the notebook, see figure 3.
Click the button to execute the code in the current cell and move to the next.
Select the In  cell and click the button to load the MNIST data. The successful output is shown on figure 4.
After the MNIST data was successfully downloaded and extracted into the mnist directory within the ($HOME)/Notebooks/Handwriting directory, four .gz files are present and the four data sets were created: trainX, trainY, testX and testY.
To inspect the imported data, the function in In  first instructs Jupyter to reshape the data into an array of 28 x 28 images and to plot the area in a 28 x 28 grid. Click the button twice to show the first two digits in the trainX dataset, see figure 5.
The In  cell defines the neural network. It provides the inputs, defines the hidden layers, runs the training model, and sets up the output layer, see figure 6. Click the button four times to perform these operations.
To test the accuracy of the prediction the system makes, select the In  cell and click the button. In this example, the number 6 was predicted with a 99% accuracy, see figure 7.
To retest the accuracy of a random data point’s prediction, run the cell In  again. It will take another random data point and predict its value.
To check the accuracy for the whole dataset, select the In  cell and click the button. Our example’s accuracy is calculated as 97.17%, see figure 8.
You have successfully installed a Jupyter kernel on Clear Linux. Furthermore, you trained a neural network to successfully predict the values contained in a data set of hand-written number images.