Skip to content

Instantly share code, notes, and snippets.

@apivovarov
Last active July 29, 2019 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apivovarov/9f67fc02b84cf6d139c05aa1a8bc16f9 to your computer and use it in GitHub Desktop.
Save apivovarov/9f67fc02b84cf6d139c05aa1a8bc16f9 to your computer and use it in GitHub Desktop.
Build libtensorflow-lite.a for Atom x5-z8350 airmont silvermont target=i686-android-linux

build_libtensorflow-lite_android

Intro

This wiki explains how to build Tensorflow Lite library (libtensorflow-lite.a) for Atom x5-z8350 airmont silvermont cpu, Android OS, target=i686-android-linux, API Level 21

Instrictions were tested on Ubuntu 18.04. It is recommended to run the build on Ubuntu 18.04 but not on Mac OS. TFLite library which is built on Ubuntu will work 10-20% faster.

Preparation

Download Androind NDK

wget https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip

# unzip and move the folder to /opt
unzip android-ndk-r18b-linux-x86_64.zip
sudo mv android-ndk-r18b /opt/

# make /opt/ndk link (needed to build cpufeatures/cpu-features.c)
cd /opt
sudo ln -s android-ndk-r18b ndk

Clone Tensorflow repo

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout r1.13

Tensorflow Lite preparations

# put build_i686-linux-android21_silvermont_lib.sh to tensorflow/lite/tools/make
cd tensorflow/lite/tools/make

Get build_i686-linux-android21_silvermont_lib.sh

chmod +x build_i686-linux-android21_silvermont_lib.sh

# put i686-linux-android_makefile.inc to tensorflow/lite/tools/make/targets/
cd targets

Get i686-linux-android_makefile.inc

# return back to the root of the repository
cd ../../../../..

Optionally we can modify tensorflow/lite/tools/make/Makefile to build shared library libtensorflow-lite.so

Get Makefile.diff and put it to /tmp folder (Alternative version of Makefile2.diff)

git apply /tmp/Makefile.diff

Download all the dependencies

# Run this script at the root of the repository to download all the dependencies
./tensorflow/lite/tools/make/download_dependencies.sh

Build Tensorflow Lite

# Run this script at the root of the repository to start the build
./tensorflow/lite/tools/make/build_i686-linux-android21_silvermont_lib.sh

# libtensorflow-lite.a (and optionally libtensorflow-lite.so) files should appear in the following folder
ls -la tensorflow/lite/tools/make/gen/i686-linux-android_silvermont/lib/libtensorflow-lite.a
ls -la tensorflow/lite/tools/make/gen/i686-linux-android_silvermont/lib/libtensorflow-lite.so

# size: 
# libtensorflow-lite.a  - 3,281,174
# libtensorflow-lite.so - 2,507,032

# To rerun the build remove tensorflow/lite/tools/make/gen folder first.

Run the inference

The wiki page run-ssd.cpp.md explains how to run SSD models on the device using tensorflow lite C++ API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment