Use bazel to compile tensorflow Android source code under linux

Decided to learn tensorflow, listened to the suggestions of the lab classmates, installed a linux system, and then compiled the Android source code first.

Install Anaconda

Anaconda integrates python, tensorflow, spyder (pythonIDE)
tutorial click here

install bazel

git clone https://github.com/ibmsoe/bazel
cd bazel
git checkout master
./compile.sh
Modify the environment variables, linux can only be modified by the root user. After
sudo -i
entering the root user, open the configuration file with the vim editor , and add this sentence at the end, which is the installation path of bazel:vim /etc/profile

export PATH = /home/fancy/bazel/output:$PATH

Install AndroidStudio

Download the linux zip package on the official website, unzip it, and switch to the installation directory directly when
tar zxvf android-studio-ide-171.4443003-linux.zip
running , and enter the command in the terminal:
./studio.sh

Download tensorflow source code

git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git

Configure SDK and NDK

The SDK is to open Android Studio and it will prompt that the downloaded
NDK must download the r12 version, otherwise the bazel compilation will report an error, and the various .h files cannot be found. I installed the high version at first, and then asked all kinds of questions without any clue, and finally in the I got help in stackoverflow, and I changed the version successfully!

Open the WORKSPACE file in the tensorflow source directory, and configure the commented out piece of code, mainly the buildtools version and the path of the SDK and NDK.
write picture description here

Configure environment variables

JDK SDK NDK Python anaconda All variables are added
write picture description here

Note that after the configuration is complete, enter the following commands to take effect:
source /etc/profile

Compile Android source code into APK file

bazel build -c opt //tensorflow/examples/android:tensorflow_demo
After success, the apk file is in this directory:
tensorflow/bazel-bin/tensorflow/examples/android

If you don't succeed, then go to the Internet to search. If you can't find it, you can ask questions on stackoverflow. There are all kinds of enthusiastic and powerful gods~

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325349305&siteId=291194637