編譯TensorFlow Lite for Android展示與範例程式

前面兩篇文章” 安裝Android 8.1到百度人臉識別開發套件”與” TensorFlowLite for Android編譯環境安裝(macOS)”分別設定了硬體與軟體開發環境,接下來說明如何編譯TensorFlow Lite for Android的展示程式。在此特別說明的是,在這邊是使用晶片廠(Rockchip)修改後的TensorFlow版本,用以搭配” 百度人臉識別開發套件”。

步驟一:下載TensorFlow 1.9.0原始碼(Rockchip)

git clone https://github.com/rockchip-linux/tensorflow.git

步驟二:進入TensorFlow專案根目錄

cd tensorflow

步驟三:編輯WORKSPACE檔案,修改與Android SDK與NDK相關設定

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 = "28.0.3",
# Replace with path to Android SDK on your system
path = "/Users/tungyilin/Library/Android/sdk",
)
android_ndk_repository(
name="androidndk",
path="/Users/tungyilin/Library/Android/sdk/ndk-bundle",
# This needs to be 14 or higher to compile TensorFlow.
# Please specify API level to >= 21 to build for 64-bit
# archtectures or the Android NDK will automatically select biggest
# API level that it supports without notice.
# Note that the NDK version is not the API level.
api_level=23,
)

步驟四:編譯TfLiteCameraDemo專案(產出TfLiteCameraDemo.apk)

bazel build -c opt --cxxopt='--std=c++11' //tensorflow/contrib/lite/java/demo/app/src/main:TfLiteCameraDemo

步驟五:編譯tflite_demo專案(產出tflite_demo.apk)

bazel build -c opt --cxxopt='--std=c++11' --fat_apk_cpu=x86,x86_64,arm64-v8a,armeabi-v7a //tensorflow/contrib/lite/examples/android:tflite_demo

編譯完成後,使用系統內建Apk Installer進行TfLiteCameraDemo.apk與tflite_demo.apk安裝;TfLiteCameraDemo.apk安裝完後會出現TfLiteCameraDemo應用程式,tflite_demo.apk完後會出現TFL Classify、TFL Detect與TFL Speech三個應用程式。

TfLiteCameraDemo執行結果如下所示:

TFL Detect執行結果如下所示:

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *