「VMware Playerを快適にしたい」で, Google発の深層学習フレームワーク「TensorFlow」のAndroidデモをUbuntu 14.04 on VMware Playerでビルドしようとして, うまくいかなかったことを書いた.
ところが, 最近VMWare Player6をVMWare Workstation 12 Playerにupdateしたところ, ホストPCのRAMが8GBでも仮想マシンのRAMを最大6GB強まで設定できるようになった. (以前は4GB程度まで)
そこで, 再度Androidデモのビルドにチャレンジ.
0. ビルド環境
ホストマシン:
CPU:Intel Core i7-2600K
RAM:8.00GB
OS:Windows 10 Pro
VMware Workstation 12 Player
仮想マシン:
プロセッサ数:4
メモリ:6GB
HDD:100GB
OS:Ubuntu 14.04
1. ビルド手順[1][2]
基本的にはここに記載の手順でOK.
よくわからないという方は, こちらも参考に.
1.1 TensorFlowのダウンロード
TensorFlowのソースをGitから取得する.
$ git clone -- recurse-submodules https://github.com/tensorflow/tensorflow
1.2 ビルド
a) WEORKSPACEにAndorid SDK/NDKの場所を指定する.
$ cd tensorflow
$ emacs WORKSPACE & // エディタで開く
[修正内容]
# Uncomment and update the paths in these entries to build the Android demo.
android_sdk_repository(
name = "androidsdk",
api_level = 23,
build_tools_version = "23.0.2",
# Replace with path to Android SDK on your system
path = "/home/xxxx/Android/Sdk",
)
android_ndk_repository(
name="androidndk",
path="/home/xxxx/Android/android-ndk-r10e",
api_level=21)
b) ビルドする.
$ bazel build //tensorflow/examples/android:tensorflow_demo
:
:
Target //tensorflow/examples/android:tensorflow_demo up-to-date:
bazel-bin/tensorflow/examples/android/tensorflow_demo_deploy.jar
bazel-bin/tensorflow/examples/android/tensorflow_demo_unsigned.apk
bazel-bin/tensorflow/examples/android/tensorflow_demo.apk
INFO: Elapsed time: 409.768s, Critical Path: 125.45s
(注) メモリが不足した場合, 以下のようなエラーが発生する.
:
INFO: From Compiling tensorflow/core/kernels/cwise_op_mul.cc:
virtual memory exhausted: Cannot allocate memory
ERROR: /home/xxxx/work/tensorflow/tensorflow/core/BUILD:796:1: C++ compilation of rule '//tensorflow/core:android_tensorflow_lib' failed: arm-linux-androideabi-gcc failed: error executing command external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -fstack-protector-strong -fpic -ffunction-sections -funwind-tables ... (remaining 44 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
Target //tensorflow/examples/android:tensorflow_demo failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 292.118s, Critical Path: 145.50s
1.3 インストール
Android端末(Android 5.0以降)にインストールする.
$ adb install -r -g bazel-bin/tensorflow/examples/android/tensorflow_demo.apk
2. 動作例
- Nexus 7 (2013) / Android 6.0
2.1 成功例
2.2 失敗例
ちょっと試しただけだが, 認識しやすものと認識しにくいものの差が大きいな, といった感じを受けた.
----
参照URL:
[1] Tensorflow Android Camera Demo
[2] TensorFlowをアプリで使ってみる | GuildWorks Blog