Build TensorFlow Lite for Raspberry Pi

This page describes how to build the TensorFlow Lite static library for Raspberry Pi. If you just want to start using TensorFlow Lite to execute your models, the fastest option is to install the TensorFlow Lite runtime package as shown in the Python quickstart.

Cross-compile for Raspberry Pi

Instruction has been tested on Ubuntu 16.04.3 64-bit PC (AMD64) and TensorFlow devel docker image tensorflow/tensorflow:nightly-devel.

To cross compile TensorFlow Lite follow the steps:

  1. Clone official Raspberry Pi cross-compilation toolchain:
git clone <a href="https://github.com/raspberrypi/tools.git">https://github.com/raspberrypi/tools.git</a> rpi_tools
  1. Clone TensorFlow repository:
git clone <a href="https://github.com/tensorflow/tensorflow.git">https://github.com/tensorflow/tensorflow.git</a> tensorflow_src
Note: If you're using the TensorFlow Docker image, the repo is already
provided in `/tensorflow_src/`.
  1. Run following script at the root of the TensorFlow repository to download all the build dependencies:
cd tensorflow_src && ./tensorflow/lite/tools/make/download_dependencies.sh
Note: You only need to do this once.
  1. To build ARMv7 binary for Raspberry Pi 2, 3 and 4 execute:
PATH=../rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin:$PATH ./tensorflow/lite/tools/make/build_rpi_lib.sh
Note: This should compile a static library in:
`tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a`.
  1. To build ARMv6 binary for Raspberry Pi Zero execute:
PATH=../rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin:$PATH ./tensorflow/lite/tools/make/build_rpi_lib.sh TARGET_ARCH=armv6
Note: This should compile a static library in:
`tensorflow/lite/tools/make/gen/rpi_armv6/lib/libtensorflow-lite.a`.

Compile natively on Raspberry Pi

Instruction has been tested on Raspberry Pi Zero, Raspbian GNU/Linux 10 (buster), gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1):

To natively compile TensorFlow Lite follow the steps:

  1. Log in to your Raspberry Pi and install the toolchain:
sudo apt-get install build-essential
  1. Clone TensorFlow repository:
git clone <a href="https://github.com/tensorflow/tensorflow.git">https://github.com/tensorflow/tensorflow.git</a> tensorflow_src
  1. Run following script at the root of the TensorFlow repository to download all the build dependencies:
cd tensorflow_src && ./tensorflow/lite/tools/make/download_dependencies.sh
Note: You only need to do this once.
  1. You should then be able to compile TensorFlow Lite with:
./tensorflow/lite/tools/make/build_rpi_lib.sh
Note: This should compile a static library in:
`tensorflow/lite/tools/make/gen/lib/rpi_armv6/libtensorflow-lite.a`.