Skip to content

koenvervloesem/tensorflow-addons-on-arm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TensorFlow Addons on ARM

Continous Integration GitHub license

TensorFlow Addons is a repository of community contributions that implement new functionality not available in the open source machine learning platform TensorFlow. Unfortunately, the TensorFlow Addons project doesn't provide a PyPI package for armhf.

However, with some patches and the right combination of build requirements TensorFlow Addons can be compiled from source on the Raspberry Pi. TensorFlow Addons on ARM is a script that streamlines this and builds TensorFlow Addons for the Raspberry Pi's ARMv7 processor architecture with a single command: make tfa.

System requirements

  • Raspberry Pi (tested on Raspberry Pi 4B with 2 GB RAM)
  • 16 GB microSD card
  • Raspberry Pi OS (previously called Raspbian) Buster (10), 32-bit

If you manage to make this work on another version of Raspbian, another Linux distribution, another model of the Raspberry Pi or even another ARM computer, please let me know so I can generalize the script.

Compatibility

Currently TensorFlow Addons on ARM only builds TensorFlow Addons for the following combination:

TensorFlow Addons TensorFlow Python Architecture
0.7.1 2.1.0 3.7 armhf

If you manage to make another combination work, please contribute your patches so other people can benefit too.

Download the wheel

If you are not interested in building TensorFlow Addons yourself, you can download a pre-built wheel of TensorFlow Addons 0.7.1 for Python 3.7 and armv7l. This works with Q-engineering's TensorFlow 2.1.0 wheel, which you still have to install.

Build requirements

First make sure to have all build requirements.

Bazel

TensorFlow Addons uses Bazel as its build system. As Raspberry Pi OS (Raspbian) doesn't have a package for Bazel and the Bazel project doesn't provide a binary for armhf, you have to build Bazel yourself. You can use Bazel on ARM for this. The installation then comes down to:

git clone https://github.com/koenvervloesem/bazel-on-arm.git
cd bazel-on-arm
sudo make requirements
make bazel
sudo make install

Note that this installs a whopping 1 GB of JDK files. The build itself takes roughly half an hour on a Raspberry Pi 4B.

If you don't want to build Bazel yourself, you can download one of the binary releases of the Bazel on ARM project.

TensorFlow

I tested this project in combination with Q-engineering's Python wheel tensorflow-2.1.0-cp37-cp37m-linux_armv7l.whl in their repository TensorFlow-Raspberry-Pi. They have excellent installation instructions and they also explain how to build the wheel from source: Install TensorFlow 2.1.0 on Raspberry Pi 4.

The installation comes down to:

sudo apt install gfortran
sudo apt install libhdf5-dev libc-ares-dev libeigen3-dev
sudo apt install libatlas-base-dev libopenblas-dev libblas-dev
sudo apt install liblapack-dev cython
pip3 install pybind11
pip3 install h5py
wget https://github.com/Qengineering/Tensorflow-Raspberry-Pi/raw/master/tensorflow-2.1.0-cp37-cp37m-linux_armv7l.whl
pip3 install tensorflow-2.1.0-cp37-cp37m-linux_armv7l.whl

If the installation went well, you should be able to import TensorFlow in a Python 3 shell:

>>> import tensorflow as tf
>>> tf.__version__
'2.1.0'

You don't need to install the TensorFlow 2.1.0 C++ API (libtensorflow.so and libtensorflow_framework.so).

Usage

If all build requirements are met, building TensorFlow Addons is as easy as:

make tfa

The build script downloads TensorFlow Addons 0.7.1, patches it, configures the Bazel build file .bazelrc and then builds TensorFlow Addons. After a while (it doesn't take that long) you should see a message like this:

Sat 4 Jul 17:30:02 BST 2020 : === Output wheel file is in: /home/pi/tensorflow-addons-on-arm/addons-0.7.1/artifacts

You can then install the Python wheel with:

pip3 install addons-0.7.1/artifacts/tensorflow_addons-0.7.1-cp37-cp37m-linux_armv7l.whl

If the installation was successful, you should be able to import TensorFlow Addons in a Python 3 shell:

>>> import tensorflow_addons as tfa
>>> tfa.__version__
'0.7.1'

Motivation

I needed TensorFlow Addons because I wanted to run Rasa on my Raspberry Pi. To my big surpise I didn't find any ARM build of TensorFlow Addons, and it turned out to be a real challenge.

The current stable version of Rasa uses TensorFlow 2.1, TensorFlow Addons 0.7.1 and Python 3.7. That's why currently this is the only combination of versions this project targets. When Rasa moves on to TensorFlow 2.2, I'm planning to build the corresponding TensorFlow Addons 0.10.0 for ARM. If someone else has patches to make this happen, please contribute them so others can benefit.

References

I had to search through a lot of references to make TensorFlow Addons build on ARM. These are some of the references that I used:

Q-engineering's TensorFlow build is not the only one for ARM. Others are:

License

This project is provided by Koen Vervloesem as open source software with the MIT license. See the LICENSE file for more information.