From 4b6c0e31385f5f27a151088c0a2b614495c4e589 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 14 Oct 2021 12:47:50 -0400 Subject: initial commit, including theme --- ...rflow-on-a-raspberry-pi-zero-w-is-a-bad-idea.md | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 content/posts/2019-04-06-tensorflow-on-a-raspberry-pi-zero-w-is-a-bad-idea.md (limited to 'content/posts/2019-04-06-tensorflow-on-a-raspberry-pi-zero-w-is-a-bad-idea.md') diff --git a/content/posts/2019-04-06-tensorflow-on-a-raspberry-pi-zero-w-is-a-bad-idea.md b/content/posts/2019-04-06-tensorflow-on-a-raspberry-pi-zero-w-is-a-bad-idea.md new file mode 100644 index 0000000..14cba0f --- /dev/null +++ b/content/posts/2019-04-06-tensorflow-on-a-raspberry-pi-zero-w-is-a-bad-idea.md @@ -0,0 +1,105 @@ +--- +date: "2019-04-06T10:22:40Z" +title: TensorFlow on a Raspberry Pi Zero is a Bad Idea +--- + +A recent question from the [Something Awful Forums][saf]: + + Can I run TensorFlow on a Raspberry Pi Zero? + +The answer? You can, but it's a bad idea. + +The [Raspberry Pi Zero][pizerow] is a single core [ARMv6][], with no +[NEON][]. Which means it's slow: + +| System | Package | Install Time | Test Time | +| ------ | ------- | ------------:| ----------:| +| [Raspberry Pi Zero W][pizerow] | [Virtualenv/Pip][tf-pip] | >1 hour | 40 seconds | +| [Raspberry Pi 3 Model B+][pi3bp] | [Virtualenv/Pip][tf-pip] | 10 minutes | 10 seconds | +| [AMD ThreadRipper 1950X][cpu] ([KVM][] VM, 8 cores) | [Docker image][tf-img] | **2 minutes** | **1.8 seconds** | + +**Details** + +Below are the steps I took to install [TensorFlow][] on a +[Raspberry Pi Zero W][pizerow]. 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][pizerow]): + +``` +(venv) pabs@zero:~> time python -c "import tensorflow as tf; + tf.enable_eager_execution(); + 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+][pi3bp]): + +``` +(venv) pabs@peach:~> time python -c "import tensorflow as tf; + tf.enable_eager_execution(); + 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][cpu], 8 core [KVM][] VM, [Docker image][tf-img]): + +``` +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 +``` + +[pip]: https://pip.pypa.io/en/stable/installing/ "Python package manager" +[virtualenv]: https://virtualenv.pypa.io/en/stable/ "Tool to create isolated Python environments" +[pizerow]: https://www.raspberrypi.org/products/raspberry-pi-zero-w/ "Raspberry Pi Zero W" +[pi3bp]: https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/ "Raspberry Pi 3 Model B+" +[cpu]: https://www.amd.com/en/products/cpu/amd-ryzen-threadripper-1950x "AMD Ryzen ThreadRipper 1950x" +[saf]: https://forums.somethingawful.com/ "Something Awful Forums" +[kvm]: https://www.linux-kvm.org/ "Linux Kernel Virtual Machine" +[docker]: https://www.docker.com/ "Docker" +[tensorflow]: https://www.tenssorflow.org/ "TensorFlow machine learning framework" +[tf-img]: https://hub.docker.com/r/tensorflow/tensorflow/ "TensorFlow Docker image" +[tf-pip]: https://www.tensorflow.org/install/pip "Install TensorFlow using Virtualenv and Pip" +[simd]: https://en.wikipedia.org/wiki/SIMD "Single Instruction, Multiple Data" +[raspbian]: https://www.raspberrypi.org/downloads/raspbian/ "Raspbian" +[armv6]: https://en.wikipedia.org/wiki/ARM_architecture +[neon]: https://en.wikipedia.org/wiki/ARM_architecture#Advanced_SIMD_(NEON) "ARM SIMD instruction set" -- cgit v1.2.3