Skip to content

TensorFlow Object Detection API on Raspberry Pi Zero

David Salek edited this page Nov 21, 2017 · 3 revisions

Install TensorFlow

As of August 2017, TensorFlow binaries for Raspberry Pi Zero are available. Read the blog by Pete Warden on how to build the binaries by cross-compiling on x86 Linux machine: https://petewarden.com/2017/08/20/cross-compiling-tensorflow-for-the-raspberry-pi/

The binaries can be easily obtained in the following way:

sudo apt-get install libblas-dev liblapack-dev python-dev libatlas-base-dev gfortran python-setuptools
sudo pip install http://ci.tensorflow.org/view/Nightly/job/nightly-pi-zero/lastSuccessfulBuild/artifact/output-artifacts/tensorflow-1.4.0-cp27-none-any.whl

Install TensorFlow Object Detection API

git clone https://github.com/tensorflow/models.git

The Tensorflow Object Detection API uses Protobufs to configure model and training parameters. Before the framework can be used, the Protobuf libraries must be compiled.

sudo apt-get install -y protobuf-compiler
cd models/research/
protoc object_detection/protos/*.proto --python_out=.

Add libraries to PYTHONPATH in .bashrc as explained in https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md#add-libraries-to-pythonpath

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

Download pre-trained model

This page lists the available pre-trained models for the object detection: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md

The models are trained on the COCO dataset http://mscoco.org/

wget http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_11_06_2017.tar.gz
tar -zxvf ssd_mobilenet_v1_coco_11_06_2017.tar.gz

Get ready for testing the object detection by installing the packages below

sudo apt-get install libjpeg-dev
sudo pip install Pillow

and run the test from this repository:

python object_detection_test.py