Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build all architectures of libtensorflow_inference.so required for use on Android, using selective registration https://medium.com/@daj/how-to-shrink-the-tensorflow-android-inference-library-cb698facf758
# This script assumes your /tensorflow/core/framework/ops_to_register.h file is already in place
mkdir /tf_files/armeabi-v7a
bazel build --local_resources 4096,4.0,1.0 -j 1 -c opt --copt="-DSELECTIVE_REGISTRATION" --copt="-DSUPPORT_SELECTIVE_REGISTRATION" //tensorflow/contrib/android:libtensorflow_inference.so --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --crosstool_top=//external:android/crosstool --verbose_failures --cpu=armeabi-v7a
cp bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so /tf_files/armeabi-v7a
mkdir /tf_files/arm64-v8a
bazel build --local_resources 4096,4.0,1.0 -j 1 -c opt --copt="-DSELECTIVE_REGISTRATION" --copt="-DSUPPORT_SELECTIVE_REGISTRATION" //tensorflow/contrib/android:libtensorflow_inference.so --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --crosstool_top=//external:android/crosstool --verbose_failures --cpu=arm64-v8a
cp bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so /tf_files/arm64-v8a
mkdir /tf_files/x86
bazel build --local_resources 4096,4.0,1.0 -j 1 -c opt --copt="-DSELECTIVE_REGISTRATION" --copt="-DSUPPORT_SELECTIVE_REGISTRATION" //tensorflow/contrib/android:libtensorflow_inference.so --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --crosstool_top=//external:android/crosstool --verbose_failures --cpu=x86
cp bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so /tf_files/x86
mkdir /tf_files/x86_64
bazel build --local_resources 4096,4.0,1.0 -j 1 -c opt --copt="-DSELECTIVE_REGISTRATION" --copt="-DSUPPORT_SELECTIVE_REGISTRATION" //tensorflow/contrib/android:libtensorflow_inference.so --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --crosstool_top=//external:android/crosstool --verbose_failures --cpu=x86_64
cp bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so /tf_files/x86_64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment