Giter Site home page Giter Site logo

koenvervloesem / tensorflow-addons-on-arm Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 10 KB

Build TensorFlow Addons for ARM on the Raspberry Pi

License: MIT License

Makefile 9.33% Shell 90.67%
machine-learning deep-learning tensorflow tensorflow2 tensorflow-addons neural-network python python3 arm armv7

tensorflow-addons-on-arm's Introduction

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.

tensorflow-addons-on-arm's People

Contributors

koenvervloesem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tensorflow-addons-on-arm's Issues

There is a problem executing make tfa

Hello, I am sorry to trouble you, my bazel has been installed, as shown below
root@b39582782284:/home# bazel version Build label: 3.1.0- (@non-git) Build target: bazel-out/aarch64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Sat Jul 4 04:07:38 2020 (1593835658) Build timestamp: 1593835658 Build timestamp as int: 1593835658
I don’t know if there is any problem, and then my tensorflow is also installed, and then I execute themake tfacommand to install tensorflow-addons when there is a problem
root@b39582782284:/home# make tfa make: *** No rule to make target 'tfa'. Stop.
Do I need to perform any pre-operations when I execute make tfa?

rpi 4b aarch64 build error

Build configurations successfully written to .bazelrc

Starting local Bazel server and connecting to it...
WARNING: /root/.cache/bazel/_bazel_root/05fec5a36c83f24c9f73cdaccf3bbd7b/external/local_config_tf/BUILD:2012:1: target '_pywrap_tensorflow_internal.so' is both a rule and a file; please choose another name for the rule
INFO: Analyzed target //:build_pip_pkg (37 packages loaded, 239 targets configured).
INFO: Found 1 target...
INFO: Deleting stale sandbox base /root/.cache/bazel/_bazel_root/05fec5a36c83f24c9f73cdaccf3bbd7b/sandbox
ERROR: /opt/build_soft/tensorflow-addons-on-arm/addons-0.7.1/tensorflow_addons/custom_ops/layers/BUILD:7:1: Linking of rule '//tensorflow_addons/custom_ops/layers:_correlation_cost_ops.so' failed (Exit 1)
/usr/bin/ld.gold: error: cannot find -l_pywrap_tensorflow_internal
collect2: error: ld returned 1 exit status
Target //:build_pip_pkg failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 24.981s, Critical Path: 8.54s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.