Install libraries

The next step is to install the libraries and download the scripts that are needed to train a neural network.

Install TensorFlow

For a Raspbian base install, the only dependency that you need to add is TensorFlow.

  1. Install some TensorFlow prerequisites which include Python 3. Open a new terminal session and enter the following on the command line:
  2. sudo apt update
    sudo apt install python3-dev python3-pip3
    sudo apt install libatlas-base-dev     # required for numpy
    sudo apt install libhdf5-dev
    sudo pip3 install -U virtualenv         # system-wide install
  3. Install the latest version of TensorFlow:
  4. sudo pip3 install --upgrade tensorflow
  5. If you get a “Memory Error” message during the TensorFlow install, disable the cache during installation with this command:
  6. sudo pip3 install --no-cache-dir tensorflow
  7. Verify the install with this command:
  8. python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"

If the TensorFlow installation is not verified, follow the guidance at Install TensorFlow with pip page for Raspberry Pi with Python 3 as some of the requirements may have been updated.

We estimate that the installation will take 30-60 minutes.

Install the Arm training scripts

Download or clone our ML examples repository from GitHub.

Navigate to the yeah-world directory by entering the following commands:

git clone https://github.com/ARM-software/ML-examples.git
cd ML-examples/yeah-world

There is nothing special about these scripts, they are easy to understand and modify. Feel free to explore and hack them with your own changes.

Advanced information

The Python source code is easy to follow and is split across these three files:

  • record.py captures images from the camera and saves them to disk.
  • train.py loads saved images, converts them to features and trains a classifier on those features.
  • run.py captures images from the camera, converts them to features, and classifies them. A random sound is also played if the image is of someone doing a cheering gesture.

These three helper files keep the three source code files as readable as possible:

  • camera.py initializes the picamera module and optionally fluctuates the exposure and white balance during recording.
  • pinet.py loads the pretrained MobileNet with TensorFlow and uses it to convert one image at a time into a set of features.
  • randomsound.py uses pygame to play a random sound file from a directory.
Before you begin Train the AI