New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow on Raspberry Pi #254

Closed
boje opened this Issue Nov 17, 2015 · 59 comments

Comments

Projects
None yet
@boje

boje commented Nov 17, 2015

Hi,
Is it possible to install Tensorflow on a Raspberry Pi? OS Ubuntu Mate, Python2.7

@vrv

This comment has been minimized.

Contributor

vrv commented Nov 17, 2015

We have not tried -- if you (or someone else) gives it a shot, let us know!

@danbri

This comment has been minimized.

danbri commented Nov 26, 2015

Quick notes from a quick look...

  1. According to https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md a source build requires Bazel. There is currently a live thread on this in bazelbuild/bazel#606 /cc @vmayoral
  2. re other dependencies - os_setup.md mentions 'python-numpy swig python-dev'; of these, the scariest looking is numpy but http://raspberrypi.stackexchange.com/questions/8308/how-to-install-last-scipy-version-on-raspberry-pi and http://www.pyimagesearch.com/2015/02/23/install-opencv-and-python-on-your-raspberry-pi-2-and-b/ seems optimistic...

Anyone get any further?

@vmayoral

This comment has been minimized.

vmayoral commented Nov 27, 2015

Thanks @danbri for summarizing it. I'm currently trying different things but there seems to be serious issues with bazel and ARM.

It's great seeing several developers interested on the Pi and although the hardware has constrained resources, the interest seems relevant. Hope Google reacts here.

@danbri

This comment has been minimized.

danbri commented Nov 27, 2015

Nearby w.r.t. bazel, #326

@danbri

This comment has been minimized.

danbri commented Dec 1, 2015

bazelbuild/bazel#606 is looking more promising than last week...

@vmayoral

This comment has been minimized.

vmayoral commented Dec 8, 2015

Some progress at #445.

@nlothian

This comment has been minimized.

nlothian commented Dec 31, 2015

On the Bazel build part, http://cudamusing.blogspot.com.au/2015/11/building-tensorflow-for-jetson-tk1.html has instructions for an Arm32 build that may work on the Pi.

@tjacobs

This comment has been minimized.

tjacobs commented Jan 1, 2016

Would love to see this too. Is it possible to just run TensorFlow compiled things on Raspberry Pi 2?

@philipz

This comment has been minimized.

philipz commented Feb 5, 2016

Hi @nlothian, I follow this Jetson build step, use the whl file to install on RPi, but Tensorflow will include CUDA lib so file. So, it is not work.

@bhack

This comment has been minimized.

Contributor

bhack commented Feb 5, 2016

👍

@nlothian

This comment has been minimized.

nlothian commented Feb 6, 2016

@philipz I meant those instructions maybe helpful for getting Bazel building on the Pi as a necessary step towards getting TensorFlow working. If you got past that point it maybe worth looking at #445 where the specific problems around that were being tracked.

You shouldn't be linking against CUDA for a Pi build!

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Mar 14, 2016

Just to spread some work that's been done in #445, we've managed to get TensorFlow compiled and running on the Raspberry Pi running Raspbian (although there hasn't been extensive testing yet). I've posted an unofficial pre-built Python wheel as well as step-by-step instructions on building from source yourself here.

@tmccrmck

This comment has been minimized.

tmccrmck commented Mar 16, 2016

Thanks! I can confirm that it works with Ubuntu MATE on a Pi 3.

@danbri

This comment has been minimized.

danbri commented Mar 16, 2016

I'm also successfully running @samjabrahams 's build on a Pi 3 (Linux raspberrypi 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux).

https://twitter.com/danbri/status/709889859029213184

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Mar 18, 2016

Since #445 is now closed, I'm going to post progress and updates for running TensorFlow on Raspberry Pi here. I did some very basic benchmarking on the Inception-v3 model to explore whether the build is working properly. Interestingly, the Pi appears to have similar performance to a MacBook Pro when it comes to using a compiled C++ model, but much worse when using the Python version (granted, the C++ version also runs slower on the Mac, which raises a separate set of questions).

I haven't gotten a good look at how Python binds to C++ in the code, but I'll do my best to figure out what's going on. My hope is that there is something screwy on the Pi that can be fixed which would lead to an order-of-magnitude time increase. I don't have much experience with C++ and its compile settings, so any ideas would be much appreciated!

@petewarden - you mentioned here that you thought some slowdown could be due to the compiler not using NEON options. Do you think that's worth exploring here?

@danbri - Could you send over the pixel dimensions of the pictures captured and used by your Raspberry Pi camera? I want to try testing images around that size to see if I end up with similar run-times

@danbri

This comment has been minimized.

danbri commented Mar 18, 2016

All I had time to try so far was default output of raspiutil via the Python wrapper code. I started trying to build the C++ but didn't finish yet. For realtime camera access (staying within python) I believe http://picamera.readthedocs.org/en/latest/api_camera.html would be the way to go. The camera needs some warmup time to judge light balance, I read. And I didn't break down the python timings yet either into setup vs inference. Anyway:

tensorflow/tensorflow/models/image/imagenet $

time raspistill --timeout 3 --nopreview -o ~/Desktop/headless.jpg

real 0m0.765s
user 0m0.010s
sys 0m0.030s

time python classify_image.py --model_dir $HOME/imagenet/ --image_file ~/Desktop/headless.jpg --num_top_predictions 5 2>/dev/null
hourglass (score = 0.47746)
lampshade, lamp shade (score = 0.19448)
table lamp (score = 0.06217)
four-poster (score = 0.01556)
wall clock (score = 0.00718)

real 0m33.291s
user 0m53.120s
sys 0m2.420s

file ~/Desktop/headless.jpg
/home/pi/Desktop/headless.jpg: JPEG image data, Exif standard: [TIFF image data, big-endian, direntries=10, height=0, manufacturer=RaspberryPi, model=RP_OV5647, xresolution=156, yresolution=164, resolutionunit=2, datetime=2016:03:18 11:22:43, width=0], baseline, precision 8, 2592x1944, frames 3

FWIW here's the picture http://imgur.com/UbsYZYC (upside down and truncated salt/pepperpots, so 'hourglass' was close ;)

I'm also curious about the Python wrapper being slower than plain C++ since I thought Python offloaded all TF's heavy lifting to compiled code anyway. Is it possible it's running a different build of the TF core in one case?

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Mar 18, 2016

Thanks @danbri- I'm definitely going to take a closer look at the Python and C++ Inception code to see if there are any obvious differences in implementation between the two. I ran your image through my RPi directly in Raspbian and got the same results as I did with smaller images. My gut tells me that the Pi can do better that the performance we're getting, but I'm not sure if I should be looking at compiler options first or dive into the code first.

I also checked out memory usage to cover more bases- doesn't appear to be an issue.

@danbri

This comment has been minimized.

danbri commented Apr 16, 2016

@samjabrahams ... sorry I've not had time to try your new binaries yet. Have you had any more insights into the speed issue?

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Apr 16, 2016

@danbri - Not much yet: I've been low on time myself as well. My current goal is to get Bazel 2 running on a RPi, then put out new binaries for the 0.8 release once the candidate has gone gold. Afterward, hopefully I'll have some time to dig deeper into which operations are causing headaches on the Pi.

@SepehrV

This comment has been minimized.

SepehrV commented Apr 16, 2016

Hi,
I am trying to install tensorflow on my RPi 2 with ubuntu 14.04 image.
I installed @samjabrahams package (Thanks for the effort btw). I encountered no error.
However when I'm importing tensorflow in python I run to this error:

File "/usr/local/lib/python2.7/dist-packages/tensorflow/init.py", line 23, in
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/init.py", line 45, in
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/local/lib/python2.7/dist-packages/tensorflow/python/_pywrap_tensorflow.so

I do have "libstdc++.so.6" and "libstdc++.so.6.0.19" in /usr/lib/arm-linux-gnueabihf/ and I have gcc4.8 installed.
Have you tried this package on RPi 2?

Any advice is appreciated.
Thanks

@SepehrV

This comment has been minimized.

SepehrV commented Apr 16, 2016

thanks. I tried it but didn't help. Same error.
I did this.
export LD_LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.8/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/lib/arm-linux-gnueabihf/:$LD_LIBRARY_PATH
sudo ldconfig
First two lines add the path to where an instance of libstdc++.so.6 exist.

@austinsteamboat

This comment has been minimized.

austinsteamboat commented May 4, 2016

I can confirm that @samjabrahams instructions for the RPi install also works for an Odroid Xu4 running Ubuntu 14.04, and while it did require building from source, it only took an hour or two to do so.

@danbri

This comment has been minimized.

@austinsteamboat

This comment has been minimized.

austinsteamboat commented May 4, 2016

@danbri - I ran that test case on the Odroid and my laptop, there was no noticeable difference in evaluation time, definitely same order of magnitude. Looking at resource draw, it takes 4 cores at peak and ~500 MB of RAM when evaluating that imagenet model.

I'm building custom classifiers one basic perceptron type model and a CNN and I can say the odroid runs 5x slower with the perceptron case (which is still plenty fast actually) and the CNN actually runs at about the same rate on both machines (really slow). When the CNN does run on the Odroid it eats between 4 and 7 of the 8 available cores and consumes ~1.9 GB of the 2 GB of RAM. I still have the swap partition turned on from the install and from what I've seen that's probably a good thing to have when running big CNNs like that. All in all pleasantly surprised by the performance so far.

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented May 4, 2016

@austinsteamboat Thanks for the info! I just finished putting the 0.8.0 pip release out for the Raspberry Pi, so I'm hoping to have a few spare minutes over the next few weeks to check out some of the speed issues. From your info, it sounds like the problem could be at the operating system level, as Raspbian is still a 32-bit OS. The Odroid is certainly a more powerful machine than the Pi, but if the ImageNet model only takes 4 cores on both, I don't see the Pi lagging behind that badly.

Hopefully I (or someone) can find something a bit more conclusive and precise for this.

@NickQian

This comment has been minimized.

NickQian commented May 16, 2016

I confirm that with @samjabrahams whl I can get the "panda" and "uniform" result in 15s(use python example. not sure the cpp example). Thanks a lot! building tensorflow and bazel on raspberry is not a easy job......I tried but blocked at the javac report out of memory(I already change the swap file to 2GB but I found the javac even does not consider any swap space).

  1. is it possible to put the bazel whl on github also? we need to build our own code with tensorflow.
  2. is it possible to improve the performance to such as 1s with GPU? I'm trying to let it run for a robot with ROS.if one second it can report the object it see, then it can be fun. Too long time is not fun :-)
@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Jul 18, 2016

A couple recent changes are throwing a wrench into compiling full TensorFlow binaries on RPi. These lines cause IS_MOBILE_PLATFORM to be defined when compiling RPi, which in turn causes errors in some of the image processing files (such as core/platform/png.h and core/platform/gif.h). It also prevents non-32-bit operations from being defined in this file. This may not be a bad thing, considering Raspbian is still a 32-bit OS, but it causes quirks when people try to use certain 64-bit-only Operations.

I imagine that the current setup works when using the Makefile, so I don't want to screw anything up. That said, any ideas on not defining IS_MOBILE_PLATFORM when compiling on Raspberry Pi? The best thing I could find was this answer on Stack Overflow- it seems a little clunky, so I didn't want to jump to making a PR with it without asking first.

In the meantime, the current fix is to delete this line before doing the Bazel build on the Pi. If there's no clean way to fix this up here, it's no big deal to tweak that file for builds moving forward.

@danbri

This comment has been minimized.

danbri commented Jul 22, 2016

@samjabrahams perhaps this situation merits a new dedicated bug report, as it is a very specific matter?

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Jul 22, 2016

@danbri You're right- I've opened up an issue for this #3469

@puchiko939393

This comment has been minimized.

puchiko939393 commented Sep 7, 2016

HI, would you like to make version10 of tensorflow on Pi? Because i want to try object recognition.Thanks.

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Sep 7, 2016

Hi @puchiko939393, I'm planning on building wheels for TensorFlow 0.10 as soon as it's officially released. There is only a release candidate at this time (0.10RC0), so I'm holding off until then. Feel free to use the guide to build it yourself if you simply can't wait!

@danbri

This comment has been minimized.

danbri commented Sep 27, 2016

https://www.oreilly.com/learning/how-to-build-a-robot-that-sees-with-100-and-tensorflow?twitter=@bigdata also reports success with TF on Pi, seemed worth passing along here.

@danbri

This comment has been minimized.

danbri commented Oct 7, 2016

Looks like https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/makefile wasn't shared here. Non-bazel, makefile-based compilation; there's a "Raspberry Pi" section in the readme, plus https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/pi_examples from @petewarden and @vrv has some nice examples. Main drawback seems to be lack of language bindings (esp. python). (and no GPU, but that's pretty much a given for Pi anyway)

edit:

  • #4680 helped me get the examples running
@shaolinkhoa

This comment has been minimized.

shaolinkhoa commented Oct 14, 2016

Hi,

Can I install TensorFlow on the Pi zero.

I tried "sudo pip2 install tensorflow-0.9.0-cp27-none-linux_armv7l.whl"

but it returned
tensorflow-0.9.0-cp27-none-linux_armv7l.whl is not a supported wheel on this platform.
Storing debug log for failure in /root/.pip/pip.log

I haven't try from Docker image yet. is it possible ?

thank you and regards,
Khoa

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Dec 1, 2016

Time for a benchmark update- I posted the latest Inception-v3 benchmarks for version 0.11.0 here, and I'll update them again once 0.12.0 is official.

Highlights:

  • Inception-v3 average run time is now under 2 seconds (after a few warmup runs)
  • Benchmark script is slightly fancier, giving best/worst/average times as well as flags to modify the number of samples and warmup runs
  • It seems the majority of the time doing the classify_image.py script is spent importing tensorflow and building the graph from disk

I'm still compiling the Python 3 binaries for 0.11.0, and I need to update the instructions to make sure they work on a fresh copy of Raspbian. Hopefully get all that done by the end of the weekend.

@bhack

This comment has been minimized.

Contributor

bhack commented Mar 29, 2017

Not strictly related but new optimized cpu and gpu ARM kernels could be available. See ARM-software/ComputeLibrary#7

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Apr 6, 2017

@pczekalski

This comment has been minimized.

pczekalski commented Apr 11, 2017

Dear samjabrahams
Thank you for all your effort.
Does the Raspberry Pi binaries apply to clone (particularily Orange Pi+ 2e - AllWinner H3 CPU + Mali 400 GPU)?
I'm trying to build according to your instruction but I'm stuck with compiling Bazel (java zero fails with Internal Error (os_linux_zero.cpp:254) unhandled signal 11 using OpenJDK Zero VM (25.121-b13) build 1.8.0_121-8u121-b130ubuntu1.16.04.2-b13). The OS is armbian.
In case above binaries do not apply, do you know if switching back to Java 1.7 may help?

Kind regards,

P.

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Apr 11, 2017

@pczekalski - I'm moving your question to my repo in issue 90, as this thread probably isn't the right place to discuss non-RPi TensorFlow.

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Apr 30, 2017

@girving

This comment has been minimized.

Contributor

girving commented Jun 16, 2017

Closing since Raspberry Pi binaries exist.

@girving girving closed this Jun 16, 2017

@danbri

This comment has been minimized.

danbri commented Jun 16, 2017

@samjabrahams what are your plans w.r.t. the pi binaries? is the build process any easier than last year?

@samjabrahams

This comment has been minimized.

Contributor

samjabrahams commented Jun 16, 2017

@danbri - The process is a little smoother than it was at the end of last year, but it's still pretty much the same (in terms of needing to compile on-device). We don't need to compile protoc from scratch anymore, and there's less finagling overall- there's basically only five changes you need to make to Bazel and TensorFlow, total.

I haven't had the time to put much effort into trying out cross-compilation options, unfortunately. In addition, I'm starting a new job which means that I'll need to talk to HR about continuing my efforts (I'm optimistic, but I don't make any assumptions).

On a brighter note, I'm excited to try out these MobileNets on-device!

tarasglek pushed a commit to tarasglek/tensorflow that referenced this issue Jun 20, 2017

Merge pull request tensorflow#254 from tinh1115/master
Fixed bug test failed on parser_trainer_test
@kranthisai

This comment has been minimized.

kranthisai commented Aug 8, 2017

@danbri @samjabrahams

This is, reply to @samjabrahams comment on Mar 17, 2016. Have you guys tested if the python and c++ versions have similar performance. When I ran object detection model using python, I can clearly see only one core being used and it takes 6 seconds to process 1 image(640x480 res). I tried configuring the intra_ops config parameter, but no luck. I think by default tensorflow uses all cpu cores. I am not sure if I am the only one facing performance issues..

@danbri

This comment has been minimized.

danbri commented Aug 8, 2017

@kranthisai

This comment has been minimized.

kranthisai commented Aug 8, 2017

@danbri . thanks for the reply. I hope they fix it in official release..

@spidi123q

This comment has been minimized.

spidi123q commented Sep 29, 2017

download the bazel binary for armv7l(pi 3) with this link below
https://drive.google.com/open?id=0B7NeIJaVzSxIZmZHUnVzZjBjVDg

@letarg0

This comment has been minimized.

letarg0 commented Mar 2, 2018

whatt about Mali 400 and more and tensorflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment