Install requirements

There are a few Python packages that TensorFlow requires that need to be installed:

pip3 install --upgrade Pillow numpy pygame

Install the Speech Output package

sudo apt install -y festival

Install rpi-vision

Now to install an Adafruit fork of a program originally written by Leigh Johnson that uses the MobileNet V2 model to detect objects. While there is a MobileNet V3, it isn't as accurate as V2. This part will take a few minutes to complete.

cd ~
git clone --depth 1
cd rpi-vision
pip3 install -e .

Install TensorFlow 2.x

Next you can download and install Tensorflow 2. There are a nice set of releases over on PINTO0309's GitHub Releases Page. To install TensorFlow 2.10.0, run the following commands. This cryptic bit of shell code figures out the current version of CPython running on your Pi, substitutes that in, and then downloads and installs the appropriate release file.

CPVER=$(python --version | grep -Eo '3\.[0-9]{1,2}' | tr -d '.')
pip install $(echo "$RELEASE" | sed -e "s/cp[0-9]\{3\}/CP$CPVER/g")

After this, go ahead and reboot the Pi.

sudo reboot
If you get a warning with "No module named 'rpi_vision'", this means Python couldn't load the module. Either the module wasn't installed correctly or the Python binding likely wasn't.
Make sure you have set the FKMS Driver enabled and the TFT as the default display as described on the Display Setup page.

Running the Graphic Labeling Demo

Finally you are ready to run the detection software. To run a program that will display the object it sees on screen, type in the following:

cd rpi-vision
python3 tests/ --tflite

You should see a bunch of text scrolling in your SSH window.

Now start holding up various items in front of the camera and it should display what it thinks it sees, which isn't actually what the item may be. Some items that it's pretty good about identifying are coffee mugs and animals.

Speech Output

As an added bonus, you can hook up a pair of headphones or a speaker to the Raspberry Pi and it will actually tell you what it is detecting. Make sure you don't have any HDMI cords plugged in though or the audio will go through the monitor.

If you don't hear anything, make sure the sound source you are expecting is selected. With the Raspberry Pi Desktop, you have a couple of ways to do this. If you have a mouse connected, you can right-click the speaker icon in the upper right-hand corner and choose your source.

If you prefer the command line, you can also run raspi-config, and go to System Options Audio to select it.

If you still don't hear anything, make sure your volume is turned up by using alsamixer. For the BrainCraft HAT, this is described in more detail on the Audio Setup page.

Finally, you can test the text to speech from the command line by running the following command:

echo "This is a test" | festival --tts

This guide was first published on Sep 04, 2019. It was last updated on Sep 04, 2019.

This page (TensorFlow 2 Setup) was last updated on Aug 28, 2019.

Text editor powered by tinymce.