Reducing size of the TFLite C++ static library

239 views
Skip to first unread message

momo114

unread,
May 26, 2021, 1:55:19 PM5/26/21
to TensorFlow Lite

Hello all,

Is there a way to reduce the size of the current TFLite C++ library ?

I have found in the below link that we can reduce the size of the library for Android by specifying the TFLite model.

Could we do it for the static C++ library ?

If not, is there any plan to add such feature ?
And is there any other way to reduce the library size ?

Thanks a lot,

Jaesung Chung

unread,
May 26, 2021, 6:39:03 PM5/26/21
to momo114, Thai Nguyen, TensorFlow Lite

In the bazel, you can create a selectively built TensorFlow Lite based on your models. As described in the above guide document, the selective building will remove unused operators from the library and it will give you a slimmed version.

For example,

load(
    "//tensorflow/lite:build_def.bzl",
    "tflite_custom_cc_library",
)

# A selective built tflite for your models.
tflite_custom_cc_library(
    name = "custom_tflite_lib",
    models = [
        "//path/.../model_a.tflite",
        "//path/.../model_b.tflite",
    ],
)

You can also refer to this.



--
You received this message because you are subscribed to the Google Groups "TensorFlow Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tflite+un...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tflite/126c4827-2c08-4ca5-94d5-5d1b300f47e0n%40tensorflow.org.

Thai Nguyen

unread,
May 26, 2021, 7:44:31 PM5/26/21
to Jaesung Chung, momo114, TensorFlow Lite
Hi,
Currently we only support dynamic libraries for Android. The guide to build the smaller size libraries is as Jaesung mentioned.
If you know the set of symbols you want to use, you can try further reducing the size by modifying the exported symbols list:


Best Regards,
Nguyen Khac Thai

Message has been deleted

momo114

unread,
May 27, 2021, 6:36:02 AM5/27/21
to TensorFlow Lite, Thai Nguyen, momo114, TensorFlow Lite, Jaesung Chung
Hi Thai, Jaesung,

I tried to use tflite_custom_cc_library with bazel and for a specific TFLite model.

Here what I'm getting in bazel-bin:
4.0K -r-xr-xr-x 965 May 27 11:15 custom_tflite_registration_registration.cc
4.0K drwxrwxr-x 4.0K May 27 11:16 external
4.0K -r-xr-xr-x 3.5K May 27 11:15 libcustom_tflite.a
4.0K -r-xr-xr-x 128 May 27 11:15 libcustom_tflite.a-2.params
4.0K -r-xr-xr-x 3.5K May 27 11:15 libcustom_tflite.pic.a
4.0K -r-xr-xr-x 136 May 27 11:15 libcustom_tflite.pic.a-2.params
8.0K -r-xr-xr-x 8.0K May 27 11:17 libcustom_tflite.so
4.0K -r-xr-xr-x 259 May 27 11:17 libcustom_tflite.so-2.params
4.0K drwxrwxr-x 4.0K May 27 11:15 _objs
4.0K drwxrwxr-x 4.0K May 27 11:17 tensorflow

When I try to link this library in my application, I'm getting linking issues as source code is missing for TFLite functions.
The library size is too small.

Am I missing something ?

Thanks,
Regards,

Thai Nguyen

unread,
May 30, 2021, 9:52:30 PM5/30/21
to momo114, TensorFlow Lite, Jaesung Chung
You should use tflite_custom_android_library and import the generated aar file to your Android project instead.

Best Regards,
Nguyen Khac Thai

momo114

unread,
May 31, 2021, 12:10:27 PM5/31/21
to TensorFlow Lite, Thai Nguyen, TensorFlow Lite, Jaesung Chung
Ah ok my bad, I thought we could do it for Linux.

Best regards,
Reply all
Reply to author
Forward
0 new messages