To be able to run a TensorFlow
lite model that supports native TensorFlow
operations, the libtensorflow-lite
static library has to be re-compiled. The instructions for doing this in C++
can be found HERE.
It states that
When building TensorFlow Lite libraries using the bazel pipeline, the additional TensorFlow ops library can be included and enabled as follows:
Enable monolithic builds if necessary by adding the --config=monolithic build flag.
Add the TensorFlow ops delegate library dependency to the build dependencies: tensorflow/lite/delegates/flex:delegate.
Note that the necessary TfLiteDelegate will be installed automatically when creating the interpreter at runtime as long as the delegate is linked into the client library. It is not necessary to explicitly install the delegate instance as is typically required with other delegate types.
The thing is that the standard way of building the static lib is via a shell script/make (see the docs HERE; this is for arm64
, but there are scripts that can be used for x86_64
as well). There's no obvious way for me to build tensorflow-lite
via bazel
and modify the build commands there.
Has anybody successfully built this when trying to build models for arm64/x86_64
architectures and can share this? I'm new to bazel
and cannot find a detailed walkthrough.
EDIT
After troubleshooting steps proposed by @jdehesa, I was able to build libtensorflowlite.so
, but ran into another problem. My app built successfully, but upon execution of the app, the .so
file cannot be found:
./myapp: error while loading shared libraries: libtensorflowlite.so: cannot open shared object file: No such file or directory
The paths are correct due to other .so
files being located in the same directory which can be found. Also, the app works if using the static library.
To reproduce the issue, I used the tensorflow/tensorflow:devel-gpu-py3
docker build image (instructions found here).
I executed the configure script with default settings, and used the command
bazel build --config=monolithic --define=with_select_tf_ops=true -c opt //tensorflow/lite:libtensorflowlite.so
to create the library. I have uploaded by built library on my personal repo (https://github.com/DocDriven/debug-lite).