Install Tensorflow on Raspberry pi

Jump to: navigation, search

Information is taken from


[edit] Update the Raspberry Pi

sudo apt-get update
sudo apt-get dist-upgrade

[edit] Install TensorFlow

sudo pip3 install setuptools --upgrade
sudo apt-get install libatlas-base-dev
sudo pip3 install tensorflow
sudo pip3 install pillow lxml jupyter matplotlib cython
sudo apt-get install python-tk

[edit] Install OpenCV

sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install qt4-dev-tools libatlas-base-dev
sudo pip3 install opencv-python==

[edit] Compile and Install Protobuf

sudo apt-get install protobuf-compiler
protoc --version

[edit] Set up TensorFlow Directory Structure and PYTHONPATH Variable

mkdir tensorflow1
cd tensorflow1
git clone --depth 1
sudo vi ~/.bashrc


export PYTHONPATH=$PYTHONPATH:/home/pi/tensorflow1/models/research:/home/pi/tensorflow1/models/research/slim

Save and exit the session.

After login:

cd /home/pi/tensorflow1/models/research
protoc object_detection/protos/*.proto --python_out=.
cd /home/pi/tensorflow1/models/research/object_detection

Download the SSDLite-MobileNet model and unpack it:

tar -xzvf ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz

[edit] Use a model you trained yourself

Here's a guide that shows you how to train your own model.

By adding the frozen inference graph into the object_detection directory and changing the model path in the script.

  • Copy object_detection\inference_graph directory to object_detection directory in Raspberry Pi.
  • Copy object_detection\training\lablemap.pbtxt to object_detection\data\ directory in Raspberry Pi.

Then, open the script in a text editor.

  • Go to the line where MODEL_NAME is set and change the string to match the name of the new model folder.
  • Then, on the line where PATH_TO_LABELS is set, change the name of the labelmap file to match the new label map.
  • Change the NUM_CLASSES variable to the number of classes your model can identify.
Personal tools
MediaWiki Appliance - Powered by TurnKey Linux