TensorFlow on a Raspberry Pi Zero is a Bad Idea

Apr 6, 2019

A recent question from the Something Awful Forums:

Can I run TensorFlow on a Raspberry Pi Zero?

The answer? You can, but it’s a bad idea.

The Raspberry Pi Zero is a single core ARMv6, with no NEON. Which means it’s slow:

System Package Install Time Test Time
Raspberry Pi Zero W Virtualenv/Pip >1 hour 40 seconds
Raspberry Pi 3 Model B+ Virtualenv/Pip 10 minutes 10 seconds
AMD ThreadRipper 1950X (KVM VM, 8 cores) Docker image 2 minutes 1.8 seconds


Below are the steps I took to install TensorFlow on a Raspberry Pi Zero W. Note: you have to use Virtualenv to install TensorFlow in Raspbian. If you try to install TensorFlow directly with Pip, the installation will bomb out with an error.

Raspberry Pi Installation Steps:

# install system pip, numpy dependencies, and virtualenv
sudo apt-get install python3-pip python3-dev libatlas-base-dev virtualenv

# at this point i tried to install tensorflow directly via pip, which does NOT work
# sudo pip3 install --upgrade tensorflow

# created virtualenv environment instead
virtualenv --system-site-packages -p python3 ./venv

# activate virtual environment "venv"
# note: after this command your shell prompt will be prefixed with "(venv) "
source ./venv/bin/activate

# install tensorflow (i also installed keras here, because I use it for other stuff)
# note: this step takes a comically long time (>1 hour)
pip install tensorflow keras

Test Results (Raspberry Pi Zero W):

(venv) pabs@zero:~> time python -c "import tensorflow as tf; 
  print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
tf.Tensor(1533.9042, shape=(), dtype=float32)

real  0m40.802s
user  0m38.283s
sys  0m1.150s

Test Results (Raspberry Pi 3 Model B+):

(venv) pabs@peach:~> time python -c "import tensorflow as tf;
  print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
tf.Tensor(800.62, shape=(), dtype=float32)

real  0m9.408s
user  0m9.227s
sys  0m0.360s

Test Results (AMD ThreadRipper 1950X, 8 core KVM VM, Docker image):

pabs@hive:~> time docker run --rm -it tensorflow/tensorflow:latest-py3 python3 -c \
	"import tensorflow as tf; tf.enable_eager_execution();
  print(tf.reduce_sum(tf.random_normal([1000, 1000])))" 
tf.Tensor(-173.73222, shape=(), dtype=float32)

real  0m1.745s
user  0m0.032s
sys  0m0.016s

Make KVM, Docker, and TensorFlow Play Nice

Apr 6, 2019

Notes on getting KVM, Docker, and TensorFlow to cooperate.

By default, a KVM VM does not have the necessary CPU flags set to run the TensorFlow Docker image. In particular, the TensorFlow Docker image is compiled with support AVX.

The solution:

  • Use virsh capabilities on the host to get a list of host CPU capabilities, then
  • Use virsh edit to manually add the necessary CPU flags as <feature> tags under the <cpu> tag.

I elected to add all of the SIMD capabilities, including FP16.

For an AMD Threadripper 1950X, the resulting <cpu> tag looks like this:

<cpu mode='host-model'>
  <model fallback='allow'/>
  <feature policy='require' name='sse4.1'/>
  <feature policy='require' name='sse4.2'/>
  <feature policy='require' name='avx'/>
  <feature policy='require' name='f16c'/>
  <feature policy='require' name='avx2'/>
  <feature policy='require' name='ssse3'/>

Test run:

pabs@hive:~> time docker run --rm -it tensorflow/tensorflow:latest-py3 \
  python3 -c "import tensorflow as tf; tf.enable_eager_execution();
              print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
2019-04-06 12:25:16.576095: I tensorflow/core/platform/cpu_feature_guard.cc:141]
 Your CPU supports instructions that this TensorFlow binary was not compiled to
 use: AVX2 FMA
2019-04-06 12:25:16.627588: I tensorflow/core/platform/profile_utils/cpu_utils.c
c:94] CPU Frequency: 3393620000 Hz
2019-04-06 12:25:16.629909: I tensorflow/compiler/xla/service/service.cc:150] XL
A service 0x395bf00 executing computations on platform Host. Devices:
2019-04-06 12:25:16.629968: I tensorflow/compiler/xla/service/service.cc:158]
StreamExecutor device (0): <undefined>, <undefined>
tf.Tensor(-95.5094, shape=(), dtype=float32)

real	0m1.780s
user	0m0.024s
sys	0m0.012s

Password Strength Tester

Apr 4, 2019

This weekend I put together a simple password strength tester. You can try it out here.


  • Simple interface.
  • Open source (MIT licensed).
  • Easy to inspect. The interface code is contained in a single, <300 line JavaScript file.
  • Self-contained. No external connections for assets, social media sites, analytics, etc.
  • Can be run offline (no internet connection) or locally (by downloading an archive of the the Git repository).

Built with:

  • zxcvbn: JavaScript password strength estimator.
  • Bulma: Open source CSS framework.
  • font-awesome: Open source font icons.


Model 3

Apr 3, 2019

Took delivery on my Tesla Model 3 (LR AWD) one week ago today.

My Tesla Model 3 (LR AWD).

So far it’s great!

I’ve been taking notes on everything, and I will share them eventually.

Hiatus Interrupted

Feb 12, 2019

I think 10 years is enough of a break.

I’ve switched the site from my own hand-rolled monstrosity to Jekyll on the backend and Bulma on the frontend.

Please excuse the cobwebs for the next few weeks…

Don't Truncate Your RSS Feed

Jun 25, 2009

Truncate articles in RSS feeds are incredibly anno...

Joggle 0.1.1 Released

May 30, 2009

Joggle version 0.1.1 is out. Joggle is a Jabber instant messenger to Twitter relay; instant messages are sent as tweets, and tweets are sent as instant messages.

This release fixes a small bug with the --daemon option when the controlling terminal is closed, and removes the advertising clause from the license.

Joggle is available via RubyGems (gem install joggle) or you can download it directly from the URLs below.

ZipStream-PHP 0.2.2 Released

May 30, 2009

I just released version 0.2.2 of ZipStream-PHP. ZipStream-PHP is a library that allows you to generate and stream zip files on the fly without writing an intermediate temporary file to the disk. It works with existing files and dynamically generated content, and has been used to dynamically generate zip files hundreds of megabytes in size.

This release of ZipStream-PHP updates the license to remove the advertising clause and fixes a few errors in the documentation. There are no code changes; if you're happy with 0.2.1 there is no immediate reason to upgrade.

Wirble 0.1.3 Released

May 30, 2009

I just released version 0.1.3 of Wirble. Wirble is a set of enhancements for Irb (the interactive Ruby shell), including tab-completion, history, and, most notably, colorized results.

This release adds Ruby 1.9 support and removes a couple of warnings. I've also added better support for non-RubyGems installations (via setup.rb) and removed the advertising clause from the license.

You can install Wirble via RubyGems or download it directly from one of the URLs below. Enjoy...

Time to Upgrade...

May 30, 2009

I just spent 30 minutes sifting through the code for this site to fix logins. They've been broken for months, and I'm using a new laptop without my old session cookie.

30 minutes to post a damn two paragraph article. Maybe redoing the site will be my weekend project.

View Archive...