tensorflow 77 tensorflow android版本demo win10 下 編譯
阿新 • • 發佈:2018-12-30
01 基本配置
安裝studio 最新版本。重點關注
android sdk/ndk
set NDK_ROOT=D:\install\Android\AndroidSDK\ndk-bundle
%NDK_ROOT%\bin
加入PATH環境變數。
關注一下自己下載的build_tools版本
D:\install\Android\AndroidSDK\build-tools\28.0.2
D:\install\Android\AndroidSDK\build-tools\28.0.3
tensorflow程式碼下載 ,android版本的demo在examples\android裡面,切換到當期相對穩定tag下。
git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
git checkout -b b1.11.0-rc2 v1.11.0-rc2
02 修改基本資訊
使用android studio 開啟 \tensorflow\tensorflow\examples\android
專案。
做些簡單修改。
專案sdk/ndk基本配置,修改檔案 tensorflow\WORKSPACE
把bazel修改為自己本地安裝的版本。本地安裝的是0.17.2
check_bazel_version_at_least("0.15.0")
==> check_bazel_version_at_least("0.17.2")
api_level、build_tools_version、sdk的path,ndk的path一定要根據自己的實際情況設定。如下。
# Uncomment and update the paths in these entries to build the Android demo. android_sdk_repository( name = "androidsdk", api_level = 28, # 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/baishixian/Library/Android/sdk", path = "D:/install/Android/AndroidSDK", ) # android_ndk_repository( name="androidndk", # path="/Users/baishixian/Library/Android/sdk/android-ndk-r14b", path= "D:/install/Android/AndroidSDK/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=28)
修改生成apk名稱,tensorflow_demo ==> zdx_demo。
android_binary(
#name = "tensorflow_demo", # 修改專案名稱
name = "zdx_demo",
更換圖示資源
tensorflow\tensorflow\examples\android\res\drawable-hdpi\ic_launcher.png
tensorflow\tensorflow\examples\android\res\drawable-mdpi\ic_launcher.png
tensorflow\tensorflow\examples\android\res\drawable-xhdpi\ic_launcher.png
tensorflow\tensorflow\examples\android\res\drawable-xxhdpi\ic_launcher.png
修改字串資源
tensorflow\tensorflow\examples\android\res\values\base-strings.xml
TensorFlow Demo ==> Zdx Demo
TF Classify ⇒ Zdx Classify
TF Stylize ⇒ Zdx Stylize
TF Speech ⇒ Zdx Speech
03 編譯
在tensorflow目錄下執行如下命令:
bazel build -c opt //tensorflow/examples/android:zdx_demo
如果前面沒有修改apk,這裡就還使用tensorflow_demo
bazel build -c opt //tensorflow/examples/android:tensorflow_demo
編譯完成後,根據提示找到自己的目標檔案。
本例中生成目標檔案如下:
C:/users/soft/_bazel_soft/qe65roea/execroot/org_tensorflow/bazel-out/x64_windows-opt/bin/tensorflow/examples/android/zdx_demo.apk
傳送到android手機後模擬器即可。