-
Notifications
You must be signed in to change notification settings - Fork 74k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build TensorFlow Lite for Android and reduce binary size to use with C API #50946
Comments
Bazel can do the selective build mechanism for C API. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/BUILD#L115 |
The tflite_custom_c_library build rule can generate the selectively built TensorFlow Lite C library. |
Cool, I replaced
Then, built
and
Tested the generated Binaries reduction:
Is there any reason why binary for Thanks for pointing me to the right direction @abattery. |
I haven't looked at the details. Looks like the pruned op kernels consume more spaces at |
Hey, I still couldn't make it work. When I build TensorFlow Lite using selective build to generate the library and use the library with JNI, my app in Android Studio builds. However, when I flash it to the mobile it cannot load the library. For selective build I use:
In order to verify whether the issue was related to the selective build or not, I also tried building without selective build. Again, I could build my app in Android Studio using the generated library, however it did not work when I flashed it to the mobile. For default build, I use:
Before, I used to build the library using
The issue is that, as stated in Reduce Binary Size, selective build is not supported for C API and I need to reduce my binary size. I have the following questions: what is the difference between using Thanks! |
Could you share how the compiled shared object is not working on the mobile app? If possible, could you share the error message you've got? |
Hey @abattery, thanks for your reply.
Unfortunately, I don't have access to the java source code of my mobile app. I am just replacing the compiled shared object of the app and the error it gives me is not very descriptive. It is something like On the other hand, I think I figured out what was my issue. As I said, I don't have access to the java source code, so I need to use a specific name for the compiled shared object which was already being used by the java part. My issue was that I was compiling the shared object with Then, I tried to do the same for the selective build in order to reduce the library size. Initially, it did not work because I was trying to use
with
I did it and it worked. The shared object reduced from 2.5MB to 1.1MB. I used it with my mobile app and it worked! Here is the diff with the necessary changes: Again, thanks for your help @abattery. |
Great, thanks for sharing your success! |
Hello,
I would like to build TensorFlow Lite for Android reducing the binary size. I want to optimize its size based on the operations used by my model. Then, I want to use the generated
.so
forarm64-v8a
andarmeabi-v7a
in JNI with C API.I am able to build TensorFlow Lite for Android as described in Build Android and use it in my Android Studio project. However, the binary files are too big for my application. In order to reduce the binary size, I followed the instructions described in Reduce Binary Size, but as stated in Known Limitations it does not support C API. The generated
.aar
does not contain the C headers and when I try to use the.so
files in my Android Studio project, none of the C functions are available.Is there any other way to reduce TensorFlow Lite binary size to be used in JNI with C API?
Thanks.
The text was updated successfully, but these errors were encountered: