Community Articles

Find and share helpful community-sourced technical articles.
Celebrating as our community reaches 100,000 members! Thank you!
Labels (1)
Master Guru

Preparing a Raspberry PI to Run TensorFlow Image Recognition

I can easily have a Python script that polls my webcam (use official Raspberry Pi webcam) , calls TensorFlow and then sends the results to NiFi via MQTT.

You need to install Python MQTT Library (

For setting up Python, Raspberry PI with Camera, see

Raspberry Pi 3 B+ preparation

Buy a good quality 16 GIG SD Card and from OSX, Run SD Formatter to Overwrite Format the device at FAT, download here: Download the BerryBoot image from here. Unzip it and then copy it to your complete SD card.

For examples of RPi TensorFlow You Can Run:

You need to build tensorflow for pi, which took me over 4 hours.



wget install -y libjpeg-devcd tensorflow-mastertensorflow/contrib/makefile/download_dependencies.shsudo apt-get install -y autoconf automake libtool gcc-4.8
g++-4.8cd tensorflow/contrib/makefile/downloads/protobuf/./ make installsudo ldconfig  #
refresh shared library cachecd ../../../../..make -f tensorflow/contrib/makefile/Makefile HOST_OS=PI
-mfpu=neon-vfpv4 -funsafe-math-optimizations -ftree-vectorize" CXX=g++-4.8curl
\-o /tmp/inception_dec_2015_stripped.zipunzip /tmp/ \-d tensorflow/contrib/pi_examples/label_image/data/make -f tensorflow/contrib/pi_examples/label_image/Makefile
tensorflow/contrib/pi_examples/label_image/gen/bin/label_image2017-01-28 01:46:48: I tensorflow/contrib/pi_examples/label_image/]
Loaded JPEG: 512x600x32017-01-28 01:46:50: W
tensorflow/core/framework/] Op
BatchNormWithGlobalNormalization is deprecated. It will cease to work in
GraphDef version 9. Use tf.nn.batch_normalization().2017-01-28 01:46:52: I
tensorflow/contrib/pi_examples/label_image/] Running model
succeeded!2017-01-28 01:46:52: I
tensorflow/contrib/pi_examples/label_image/] military uniform
(866): 0.6242942017-01-28 01:46:52: I
tensorflow/contrib/pi_examples/label_image/] suit (794):
0.04739812017-01-28 01:46:52: I
tensorflow/contrib/pi_examples/label_image/] academic gown
(896): 0.02809252017-01-28 01:46:52: I tensorflow/contrib/pi_examples/label_image/]
bolo tie (940): 0.01569552017-01-28 01:46:52: I
tensorflow/contrib/pi_examples/label_image/] bearskin (849):

It took over 4 hours to build. But only 4 seconds to run and gave good results for analyzing a picture of Computer Legend Grace Hopper.

tensorflow/contrib/pi_examples/label_image/gen/bin/label_image --help2017-01-28 01:51:26: E
tensorflow/contrib/pi_examples/label_image/]usage: tensorflow/contrib/pi_examples/label_image/gen/bin/label_imageFlags:  --image="tensorflow/contrib/pi_examples/label_image/data/grace_hopper.jpg"  string  image to be processed  --graph="tensorflow/contrib/pi_examples/label_image/data/tensorflow_inception_stripped.pb"  string  graph
to be executed  --labels="tensorflow/contrib/pi_examples/label_image/data/imagenet_comp_graph_label_strings.txt"  string  name
of file containing labels  --input_width=299    int32  resize image to this
width in pixels  --input_height=299    int32  resize image to this height in pixels  --input_mean=128   int32  scale pixel values to
this mean  --input_std=128    int32  scale pixel values to this std deviation  --input_layer="Mul"   string  name of input layer  --output_layer="softmax"    string  name of output layer  --self_test=false    bool  run a self test  --root_dir=""    string  interpret image and graph file names relative
to this directory