Skip to content

Commit

Permalink
Shrink libtensorflow_inference.so library using selective registration
Browse files Browse the repository at this point in the history
This reduces libtensorflow_inference.so from 9.7MB to 2.5MB.

SUMMARY

 - tensorflow-android.jar - created by extracting classes.jar from the "org.tensorflow:tensorflow-android:1.2.0" AAR dependency.
 - libtensorflow_inference.so - built for armeabi-v7a using print_selective_registration_header and then building //tensorflow/contrib/android:libtensorflow_inference.so with selective registration. Detailed build steps are listed below.

BUILD STEPS

Here are the commands I ran (in my Docker container):

bazel build --local_resources 4096,4.0,1.0 -j 1 tensorflow/python/tools:print_selective_registration_header

bazel-bin/tensorflow/python/tools/print_selective_registration_header --graphs=/TF/mnist_model_graph.pb > /tensorflow/core/framework/ops_to_register.h

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 --cpu=armeabi-v7a --verbose_failures

LIMITATIONS

The previous "org.tensorflow:tensorflow-android:1.2.0" dependency used supported the four main architectures: arm64-v8a, armeabi-v7a, x86, x86_64

This change only includes a native library for the armeabi-v7a architecture.  The app will crash on all other architectures, and Android Studio fails to install the app with a INSTALL_FAILED_NO_MATCHING_ABIS error.
  • Loading branch information
daj committed Oct 7, 2017
1 parent 4d0b1ea commit 6e1b15f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.2.0'
testCompile 'junit:junit:4.12'
compile 'org.tensorflow:tensorflow-android:1.2.0'
compile files('libs/tensorflow-android.jar')
}
Binary file added app/libs/tensorflow-android.jar
Binary file not shown.
Binary file not shown.

0 comments on commit 6e1b15f

Please sign in to comment.