Cross and native compilation of TFLite for RPI
Why: * Describe correct cross and native compilation process for RPI. This change addresses the need by: * Updates in instruction for cross compilation. * Alignement text style across whole instruction.
This commit is contained in:
parent
9c4a71c85c
commit
74b9f9dcc9
@ -5,87 +5,89 @@ 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
|
models, the fastest option is to install the TensorFlow Lite runtime package as
|
||||||
shown in the [Python quickstart](python.md).
|
shown in the [Python quickstart](python.md).
|
||||||
|
|
||||||
Note: This page shows how to compile only the C++ static library for
|
**Note:** This page shows how to compile only the C++ static library for
|
||||||
TensorFlow Lite. Alternative install options include: [install just the Python
|
TensorFlow Lite. Alternative install options include: [install just the Python
|
||||||
interpreter API](python.md) (for inferencing only); [install the full
|
interpreter API](python.md) (for inferencing only); [install the full
|
||||||
TensorFlow package from pip](https://www.tensorflow.org/install/pip);
|
TensorFlow package from pip](https://www.tensorflow.org/install/pip);
|
||||||
or [build the full TensorFlow package](
|
or [build the full TensorFlow package](
|
||||||
https://www.tensorflow.org/install/source_rpi).
|
https://www.tensorflow.org/install/source_rpi).
|
||||||
|
|
||||||
|
|
||||||
## Cross-compile for Raspberry Pi
|
## Cross-compile for Raspberry Pi
|
||||||
|
|
||||||
This has been tested on Ubuntu 16.04.3 64bit and TensorFlow devel docker image
|
Instruction has been tested on Ubuntu 16.04.3 64-bit PC (AMD64) and TensorFlow devel
|
||||||
|
docker image
|
||||||
[tensorflow/tensorflow:nightly-devel](https://hub.docker.com/r/tensorflow/tensorflow/tags/).
|
[tensorflow/tensorflow:nightly-devel](https://hub.docker.com/r/tensorflow/tensorflow/tags/).
|
||||||
|
|
||||||
To cross compile TensorFlow Lite, first install the toolchain and libs:
|
To cross compile TensorFlow Lite follow the steps:
|
||||||
|
|
||||||
```bash
|
1. Clone official Raspberry Pi cross-compilation toolchain:
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install crossbuild-essential-armhf
|
|
||||||
# The following is only needed for Pi Zero build.
|
|
||||||
sudo apt-get install crossbuild-essential-armel
|
|
||||||
```
|
|
||||||
|
|
||||||
If you are using Docker, you may not use `sudo`.
|
```bash
|
||||||
|
git clone --depth 1 https://github.com/raspberrypi/tools.git rpi_tools
|
||||||
|
```
|
||||||
|
|
||||||
Now git-clone the TensorFlow repository
|
2. Clone TensorFlow repository:
|
||||||
(`https://github.com/tensorflow/tensorflow`)—if you're using the TensorFlow
|
|
||||||
Docker image, the repo is already provided in `/tensorflow_src/`—and then run
|
```bash
|
||||||
this script at the root of the TensorFlow repository to download all the
|
git clone --depth 1 https://github.com/tensorflow/tensorflow.git tensorflow_src
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** If you're using the TensorFlow Docker image, the repo is already provided in `/tensorflow_src/`.
|
||||||
|
|
||||||
|
3. Run following script at the root of the TensorFlow repository to download all the
|
||||||
build dependencies:
|
build dependencies:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./tensorflow/lite/tools/make/download_dependencies.sh
|
cd tensor_src && ./tensorflow/lite/tools/make/download_dependencies.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that you only need to do this once.
|
**Note:** You only need to do this once.
|
||||||
|
|
||||||
You should then be able to compile:
|
4. To build ARMv7 binary for Raspberry Pi 2, 3 and 4 execute:
|
||||||
|
|
||||||
To build ARMv7 binary for Raspberry Pi 2, 3 and 4:
|
```bash
|
||||||
|
PATH=$PATH:../rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/ ./tensorflow/lite/tools/make/build_rpi_lib.sh
|
||||||
|
```
|
||||||
|
|
||||||
```bash
|
**Note:** This should compile a static library in:
|
||||||
./tensorflow/lite/tools/make/build_rpi_lib.sh
|
`tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a`.
|
||||||
```
|
|
||||||
|
|
||||||
This should compile a static library in:
|
5. To build ARMv6 binary for Raspberry Pi Zero execute:
|
||||||
`tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a`.
|
|
||||||
|
|
||||||
To build ARMv6 binary for Raspberry Pi Zero:
|
```bash
|
||||||
|
PATH=$PATH:../rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/ ./tensorflow/lite/tools/make/build_rpi_lib.sh TARGET_ARCH=armv6
|
||||||
|
```
|
||||||
|
|
||||||
```bash
|
**Note:** This should compile a static library in:
|
||||||
./tensorflow/lite/tools/make/build_rpi_lib.sh TARGET_ARCH=armv6
|
`tensorflow/lite/tools/make/gen/rpi_armv6/lib/libtensorflow-lite.a`.
|
||||||
```
|
|
||||||
|
|
||||||
This should compile a static library in:
|
|
||||||
`tensorflow/lite/tools/make/gen/rpi_armv6/lib/libtensorflow-lite.a`.
|
|
||||||
|
|
||||||
## Compile natively on Raspberry Pi
|
## Compile natively on Raspberry Pi
|
||||||
|
|
||||||
This has been tested on Raspberry Pi 3b, Raspbian GNU/Linux 9.1 (stretch), gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1).
|
Instruction has been tested on Raspberry Pi 3b, Raspbian GNU/Linux 9.1 (stretch), gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1):
|
||||||
|
|
||||||
Log in to your Raspberry Pi and install the toolchain:
|
To natively compile TensorFlow Lite follow the steps:
|
||||||
|
|
||||||
```bash
|
1. Log in to your Raspberry Pi and install the toolchain:
|
||||||
sudo apt-get install build-essential
|
|
||||||
```
|
|
||||||
|
|
||||||
Now git-clone the TensorFlow repository
|
```bash
|
||||||
(`https://github.com/tensorflow/tensorflow`) and run this at the root of
|
sudo apt-get install build-essential
|
||||||
the repository:
|
```
|
||||||
|
|
||||||
```bash
|
2. Run following script at the root of the TensorFlow repository to download all the
|
||||||
./tensorflow/lite/tools/make/download_dependencies.sh
|
build dependencies:
|
||||||
```
|
|
||||||
|
|
||||||
Note that you only need to do this once.
|
```bash
|
||||||
|
cd tensor_src && ./tensorflow/lite/tools/make/download_dependencies.sh
|
||||||
|
```
|
||||||
|
|
||||||
You should then be able to compile:
|
**Note:** You only need to do this once.
|
||||||
|
|
||||||
```bash
|
3. You should then be able to compile TensorFlow Lite with:
|
||||||
./tensorflow/lite/tools/make/build_rpi_lib.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
This should compile a static library in:
|
```bash
|
||||||
`tensorflow/lite/tools/make/gen/lib/rpi_armv7/libtensorflow-lite.a`.
|
./tensorflow/lite/tools/make/build_rpi_lib.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** This should compile a static library in:
|
||||||
|
`tensorflow/lite/tools/make/gen/lib/rpi_armv7/libtensorflow-lite.a`.
|
||||||
|
Loading…
Reference in New Issue
Block a user