This is the application for recognize number sequence.
This project is based on tensorflow android demo. Unused files are removed to keep it simple.
This project should be built under the tensorflow source code, so download
tensorflow source project before you go ahead. Currently it's built at commit
c2fc604b52dfee03794a95f88b0187d278aad078
of tensorflow source code.
After you clone tensorflow source code, place this project at //tensorflow/examples/numseq-android
.
As a prerequisite, Bazel, the Android NDK, and the Android SDK must all be installed on your system.
- Get the recommended Bazel version listed at: https://www.tensorflow.org/versions/master/get_started/os_setup.html#source
- The Android NDK may be obtained from: http://developer.android.com/tools/sdk/ndk/index.html
- The Android SDK and build tools may be obtained from: https://developer.android.com/tools/revisions/build-tools.html
The Android entries in <workspace_root>/WORKSPACE
must be uncommented with the paths filled in appropriately depending on where
you installed the NDK and SDK. Otherwise an error such as:
"The external label '//external:android/sdk' is not bound to anything" will
be reported.
The tensorflow model is not packaged in the repo because of its size. It can be trained and exported by project num-seq-recognizer.
After editing your WORKSPACE file to update the SDK/NDK configuration, you may build the APK.
To build the apk, first you need to build the inference.so and inference.jar
Run this from folder //
bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=armeabi-v7a
bazel build //tensorflow/contrib/android:android_tensorflow_inference_java
Two files will be generated at bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so
and bazel-bin/tensorflow/contrib/android/libandroid_tensorflow_inference_java.jar
.
Copy the jar file into libs
folder and so file into libs/armeabi-v7a
folder.
If you get build errors about protocol buffers, run
git submodule update --init
from tensorflow root directory and build again.
Run this from folder //tensorflow/examples/numseq-android
:
$ ./gradlew build
If adb debugging is enabled on your Android 5.0 or later device, you may then use the following command from your workspace root to install the APK once built:
$ adb install -r -g gradleBuild/outputs/apk/numseq-android-debug.apk
Some older versions of adb might complain about the -g option (returning: "Error: Unknown option: -g"). In this case, if your device runs Android 6.0 or later, then make sure you update to the latest adb version before trying the install command again. If your device runs earlier versions of Android, however, you can issue the install command without the -g option.
If camera permission errors are encountered (possible on Android Marshmallow or
above), then the adb install
command above should be used instead, as it
automatically grants the required camera permissions with -g
. The permission
errors may not be obvious if the app halts immediately, so if you installed
with bazel and the app doesn't come up, then the easiest thing to do is try
installing with adb.
Once the app is installed it can be started via the "NumTeller", which have the orange TensorFlow logo as their icon.