Setting up Tensorflow on a Raspberry Pi

About a year ago I put together a robot that could recognize each of the house cats and would teach itself to avoid walls. ( Machine Learning on a Raspberry Pi ) To use Google’s mobile image recognition networks Tensorflow must be installed on the Raspberry Pi. This is intended to walk through what can be a complicated process.

Cat detecting robot

First up you’ll need a Raspberry Pi and an SD Card, I recommend 64GB

RaspberryPi.org has an excellent page on getting the the Raspbian operating system installed on your card.

Next you’ll want to attach a mouse, keyboard, and monitor to your Pi and boot it up for the first time.

Go to Preferences -> Mouse and Keyboard Settings and set the keyboard up for your language ( I use United States, English, (US, with euro on 5 )

Set your Localisation Preferences and save

Set up WiFi ( Click on top toolbar with red arrows, give it your WiFi name and your password )

Set up Emacs ( open a terminal, type
sudo apt-get install emacs
answer Y )

Turn on some useful things ( Select Raspberry Pi Configuration from menu )
Select Interfaces, Enable Camera, SSH, VNC

Save and Reboot

Change your password ( Select Raspberry Pi Configuration )
Select Change Password and save

Open a Terminal and type
sudo apt-get update
sudo apt-get dist-upgrade
( follow the directions to do the updates )

# set Python 3.5 as the default Python ( remove soft link to Python 2.7 and make a new one
to Python 3.5.x)
cd /usr/bin
sudo rm python
sudo ln -s python3.5 python

# test python version
which python
python --version

( should tell you /usr/bin/python and version 3.5.x )

Go to samjabrahams GitHub page and follow the pip install directions for Python 3.x

# For Python 3.x
sudo wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.1.0/tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl

# system is using Python 3.5 wheel file is looking for 3.4 so change the name
(fixes error: Unsupported Wheel on Platform error )
cp tensorflow-1.1.0-cp34-cp34m-linux_armv7l.whl tensorflow-1.1.0-cp35-cp35m-linux_armv7l.whl

sudo pip3 install tensorflow-1.1.0-cp35-cp35m-linux_armv7l.whl

# uninstall and reinstall mock
sudo pip3 uninstall mock
sudo pip3 install mock

# test Tensorflow
Create a new file with emacs ( open a terminal )
emacs test_tf.py

import tensorflow as tf
hello = tf.constant("Hello, World!")
sess = tf.Session()
print(sess.run(hello))

Save the file, close emacs, and run file
python test_tf.py

It’ll take Tensorflow a minute or so to set itself up when you first import it

( * Toss samjabrahams a few dollars using the donate button on his GitHub page, he saved you hours of frustration and work )

Ready to do something with your new TensorFlow install? Start here:
TensorFlow for Poets a Google Code Lab