TensorFlow compiling Androiddemo

Source: Internet
Author: User

The first is tensorflow to clone to a local copy.

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

Since it is Google's official request, it is best to --recurse-submodules Add, the document said can avoid some data structure serialization when the problem of compilation.

This is the GitHub homepage for Android demo.

Preparing for compilation 1. Install Bazel

bazelIs Google's own build tool. tensorflowcan only be partially supported cmake or gradle , but bazel is the tensorflow Main building tool of the project.

Click here to download Bazel.

Mac and Linux users are installed according to the documentation. Windows users, according to the official recommendations to the following link to download the demo two apk file, currently Bazel on the Windows platform is still in the experimental phase.

Windows users click here to download apk directly

bazelIf the installation is successful or not, use the bazel version check version.

2. Download the NDK

Click here to download the latest version of the NDK.

The best download r12b version, the latest r13b possible with bazel compatibility issues.

Unzip to the custom directory when the download is complete, and then ~/.bash_profile linux Add the ~/.bashrc environment variable under (under). The process of adding environment variables everybody Baidu a bit, not here the key.

3. Download >=23 Android SDK

Tensorflow Android DemoMust be compiled in an environment that is greater than equals 23 API . You can open Android Studio the in SDK Manager to install the latest SDK .

4. Edit the workspace file in the TensorFlow root directory

Go back to the tensorflow root directory (currently on android level two in the directory). Open the WORKSPACE file.

Found at the beginning of the file

# Uncomment and update the pathsinchthese entries to build the Android demo. #android_sdk_repository (# Name="ANDROIDSDK", # Api_level= at, # # Ensure that's the build_tools_version below installedinchthe# # SDK Manager asIt updates periodically.# build_tools_version="25.0.2", # # Replace with the path to the Android SDK on your system# path="/PATH/TO/YOUR/SDK", #) # Android NDK r12b isrecommended (higher may cause issues with Bazel) #android_ndk_repository (# name="ANDROIDNDK", # Path="/PATH/TO/YOUR/NDK", # # This needs- be -or higher to compile tensorflow.# # Note that the NDK version isNot the API level.# api_level= -)

These two parts define the SDK path of the and NDK , and /path/to/your change the part to the corresponding path of the system. Then remove the comments before each line. As follows:

# Uncomment and update the pathsinchthese entries to build the Android demo.android_sdk_repository (name="ANDROIDSDK", Api_level= at, # Ensure that the build_tools_version below installedinchThe # SDK manager asit updates periodically. Build_tools_version="25.0.2", # Replace with path to the Android SDK on your system path="/USERS/XXX/LIBRARY/ANDROID/SDK",) # # Android NDK r12b isrecommended (higher may cause issues with Bazel) android_ndk_repository (name="ANDROIDNDK", Path="/usr/local/lib/android-ndk-r12b", # This needs- be -or higher to compile tensorflow. # Note that the NDK version isThe API level is not . Api_level= -)
Start compiling

tansorflowexecute in root directory,

// Tensorflow/examples/android:tensorflow_demo

To compile, the mutation process is as follows:

If all goes well, compile successfully, such as:

Install APK DEMO

After the mutation succeeds, bazel the file is generated under the bazel-bin directory apk . Connect your phone with a data cable to perform

ADB install-r bazel-bin/tensorflow/examples/android/tensorflow_demo.apk

Can be installed to your phone.

TensorFlow compiling Androiddemo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.