Skip to content
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
Closed

Tensorflow on Raspberry Pi #254

boje opened this issue Nov 17, 2015 · 59 comments
Labels
stat:community support Status - Community Support type:build/install Build and install issues

Comments

@boje
Copy link

boje commented Nov 17, 2015

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

@vrv
Copy link

vrv commented Nov 17, 2015

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

@danbri
Copy link

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 Compiling bazel natively on armv7l 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
Copy link

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
Copy link

danbri commented Nov 27, 2015

Nearby w.r.t. bazel, #326

@danbri
Copy link

danbri commented Dec 1, 2015

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

@vmayoral
Copy link

vmayoral commented Dec 8, 2015

Some progress at #445.

@nlothian
Copy link

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
Copy link

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
Copy link

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
Copy link
Contributor

bhack commented Feb 5, 2016

👍

@nlothian
Copy link

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
Copy link
Contributor

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
Copy link

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

@danbri
Copy link

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
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

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
Copy link

danbri commented Mar 19, 2016

Just to share the Python vs C++ links for others:

@danbri
Copy link

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
Copy link
Contributor

@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
Copy link

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
Copy link

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
Copy link

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
Copy link

danbri commented May 4, 2016

@austinsteamboat
Copy link

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
Copy link
Contributor

@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
Copy link

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 :-)

@danbri
Copy link

danbri commented Jul 22, 2016

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

@samjabrahams
Copy link
Contributor

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

@aselle aselle added stat:community support Status - Community Support and removed triaged labels Jul 28, 2016
@puchiko939393
Copy link

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

@samjabrahams
Copy link
Contributor

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
Copy link

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
Copy link

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:

@Khoa-NT
Copy link

Khoa-NT 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
Copy link
Contributor

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.

@aselle aselle added type:build/install Build and install issues and removed installation/startup labels Jan 28, 2017
@bhack
Copy link
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
Copy link
Contributor

I've released unofficial Raspberry Pi binaries for version 1.0.1 here.

@pczekalski
Copy link

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
Copy link
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
Copy link
Contributor

Unofficial Raspberry Pi binaries for version 1.1.0.

@girving
Copy link
Contributor

girving commented Jun 16, 2017

Closing since Raspberry Pi binaries exist.

@girving girving closed this as completed Jun 16, 2017
@danbri
Copy link

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
Copy link
Contributor

@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
Fixed bug test failed on parser_trainer_test
@kranthisai
Copy link

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
Copy link

danbri commented Aug 8, 2017 via email

@kranthisai
Copy link

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

@spidi123q
Copy link

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

@letarg0
Copy link

letarg0 commented Mar 2, 2018

whatt about Mali 400 and more and tensorflow

tensorflow-copybara pushed a commit that referenced this issue Nov 21, 2019
Add include of ADT/SmallVector.h.
Fixes #254.

PiperOrigin-RevId: 281721705
Change-Id: I59bfc916fc243973d6b4b556b34e22f17db5c7a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:community support Status - Community Support type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests