The next step is to install the libraries and download the scripts that are needed to train a neural network.
For a Raspbian base install, the only dependency that you need to add is TensorFlow.
- Install some TensorFlow prerequisites which include Python 3. Open a new terminal session and enter the following on the command line:
- Install the latest version of TensorFlow:
- If you get a “Memory Error” message during the TensorFlow install, disable the cache during installation with this command:
- Verify the install with this command:
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
sudo pip3 install --upgrade tensorflow
sudo pip3 install --no-cache-dir tensorflow
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:
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.
The Python source code is easy to follow and is split across these three files:
record.pycaptures images from the camera and saves them to disk.
train.pyloads saved images, converts them to features and trains a classifier on those features.
run.pycaptures 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.pyinitializes the picamera module and optionally fluctuates the exposure and white balance during recording.
pinet.pyloads the pretrained MobileNet with TensorFlow and uses it to convert one image at a time into a set of features.
randomsound.pyuses pygame to play a random sound file from a directory.
|Before you begin||Train the AI|