TensorFlow編譯androiddemo

來源:互聯網
上載者:User

標籤:資料線   led   sdn   local   複製   install   連結   tools   user   

首先是把tensorflow複製到本地一份。

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

既然是Google官方要求的,最好把--recurse-submodules加上,文檔說可以避免一些資料結構序列化時的編譯問題。

這是android demo的github首頁。

準備編譯1.安裝bazel

bazel是Google自己的構建工具。tensorflow只能部分支援cmake或者gradle,而bazeltensorflow工程的主要構建工具。

點這裡下載Bazel。

Mac和Linux使用者根據文檔進行安裝。Windows使用者,按照官方建議到下面的連結下載demo的二apk檔案,目前bazel在windows平台還處於實驗階段。

Windows使用者點這裡直接下載apk

bazel安裝成功與否,用bazel version檢查版本即可。

2.下載NDK

點這裡下載最新版本NDK。

最好下載r12b版本的,最新的r13b可能與bazel有相容問題。

下載完成後解壓到自訂目錄,然後在~/.bash_profilelinux~/.bashrc)下添加環境變數。環境變數的添加過程大家百度一下吧,不是這裡的重點。

3.下載 >=23 Android SDK

Tensorflow Android Demo必須在大於等於23API環境中編譯。可以開啟Android Studio中的SDK Manager來安裝最新的SDK

4. 編輯Tensorflow根目錄下的WORKSPACE檔案

回到tensorflow根目錄,(當前在android目錄就往上兩級)。開啟WORKSPACE檔案。

在檔案開頭部分找到

# Uncomment and update the paths in these entries to build the Android demo.#android_sdk_repository(#    name = "androidsdk",#    api_level = 23,#    # Ensure that you have the build_tools_version below installed in the#    # SDK manager as it updates periodically.#    build_tools_version = "25.0.2",#    # Replace with path to Android SDK on your system#    path = "/path/to/your/sdk",#)# Android NDK r12b is recommended (higher may cause issues with Bazel)#android_ndk_repository(#    name="androidndk",#    path="/path/to/your/ndk",#    # This needs to be 14 or higher to compile TensorFlow.#    # Note that the NDK version is not the API level.#    api_level=14)

 

這兩部分定義了SDKNDK的路徑,把/path/to/your的部分改成系統相應的路徑。然後將每一行前的注釋去掉。如下:

# Uncomment and update the paths in these entries to build the Android demo.android_sdk_repository(    name = "androidsdk",    api_level = 23,    # Ensure that you have the build_tools_version below installed in the    # SDK manager as it updates periodically.    build_tools_version = "25.0.2",    # Replace with path to Android SDK on your system    path = "/Users/XXX/Library/Android/sdk",)## Android NDK r12b is recommended (higher may cause issues with Bazel)android_ndk_repository(    name="androidndk",    path="/usr/local/lib/android-ndk-r12b",    # This needs to be 14 or higher to compile TensorFlow.    # Note that the NDK version is not the API level.    api_level=14)
開始編譯

tansorflow根目錄執行,

bazel build -c opt //tensorflow/examples/android:tensorflow_demo

進行編譯,變異過程如下:

一切順利的話,編譯成功,如:

安裝APK DEMO

變異成功之後bazel會在bazel-bin目錄下面產生apk檔案。用資料線連上手機,執行

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

即可安裝到手機。

TensorFlow編譯androiddemo

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.