如何使用 select TensorFlow ops 为 x86_64 系统构建 TensorFlow lite?
How to build TensorFlow lite with select TensorFlow ops for x86_64 systems?
为了能够 运行 支持本机 TensorFlow
操作的 TensorFlow
精简模型,必须重新编译 libtensorflow-lite
静态库。在 C++
中执行此操作的说明可以在 HERE 中找到。
它指出
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.
问题是构建静态库的标准方法是通过 shell script/make(参见文档 HERE;这是针对 arm64
,但是有些脚本也可用于 x86_64
)。我没有明显的方法可以通过 bazel
构建 tensorflow-lite
并在那里修改构建命令。
有没有人在尝试为 arm64/x86_64
体系结构构建模型时成功构建它并可以分享它?我是 bazel
的新手,找不到详细的演练。
编辑
在@jdehesa 提出的故障排除步骤之后,我能够构建 libtensorflowlite.so
,但 运行 变成了另一个问题。我的应用程序构建成功,但在执行应用程序时,找不到 .so
文件:
./myapp: error while loading shared libraries: libtensorflowlite.so: cannot open shared object file: No such file or directory
路径是正确的,因为其他 .so
文件位于可以找到的同一目录中。此外,如果使用静态库,该应用程序也能正常工作。
为了重现该问题,我使用了 tensorflow/tensorflow:devel-gpu-py3
docker 构建映像(找到 here 中的说明)。
我使用默认设置执行了配置脚本,并使用了命令
bazel build --config=monolithic --define=with_select_tf_ops=true -c opt //tensorflow/lite:libtensorflowlite.so
创建库。我已经通过内置库上传到我的个人仓库 (https://github.com/DocDriven/debug-lite)。
编辑:实验性选项 with_select_tf_ops
似乎是 removed shortly after this was posted. As far as I can tell, there does not seem to be any builtin option to include the TF delegate library in the current build script for libtensorflowlite
. If you want to build the library with Bazel, it seems the only option at the moment is to include tensorflow/lite/delegates/flex:delegate
in the list of target dependencies, as suggested in the docs。
几天前,提交了 initial support for building TFLite with CMake. In that build script there is an option SELECT_TF_OPS
以在构建中包含委托库。我不知道该版本目前是否有效,但我想它最终会成为即将发布的正式版本的一部分。
libtensorflow-lite.a
似乎是用 Makefiles, out of Bazel, so I'm not sure if you can actually use that option for that library. There is however an experimental shared library target libtensorflowlite.so
that I think may be what you need. You can give the experimental option with_select_tf_ops
构建的,以便在其中包含 TensorFlow 内核。所以我认为构建命令应该是这样的:
bazel build --config=monolithic --define=with_select_tf_ops=true -c opt //tensorflow/lite:libtensorflowlite.so
为了能够 运行 支持本机 TensorFlow
操作的 TensorFlow
精简模型,必须重新编译 libtensorflow-lite
静态库。在 C++
中执行此操作的说明可以在 HERE 中找到。
它指出
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.
问题是构建静态库的标准方法是通过 shell script/make(参见文档 HERE;这是针对 arm64
,但是有些脚本也可用于 x86_64
)。我没有明显的方法可以通过 bazel
构建 tensorflow-lite
并在那里修改构建命令。
有没有人在尝试为 arm64/x86_64
体系结构构建模型时成功构建它并可以分享它?我是 bazel
的新手,找不到详细的演练。
编辑
在@jdehesa 提出的故障排除步骤之后,我能够构建 libtensorflowlite.so
,但 运行 变成了另一个问题。我的应用程序构建成功,但在执行应用程序时,找不到 .so
文件:
./myapp: error while loading shared libraries: libtensorflowlite.so: cannot open shared object file: No such file or directory
路径是正确的,因为其他 .so
文件位于可以找到的同一目录中。此外,如果使用静态库,该应用程序也能正常工作。
为了重现该问题,我使用了 tensorflow/tensorflow:devel-gpu-py3
docker 构建映像(找到 here 中的说明)。
我使用默认设置执行了配置脚本,并使用了命令
bazel build --config=monolithic --define=with_select_tf_ops=true -c opt //tensorflow/lite:libtensorflowlite.so
创建库。我已经通过内置库上传到我的个人仓库 (https://github.com/DocDriven/debug-lite)。
编辑:实验性选项 with_select_tf_ops
似乎是 removed shortly after this was posted. As far as I can tell, there does not seem to be any builtin option to include the TF delegate library in the current build script for libtensorflowlite
. If you want to build the library with Bazel, it seems the only option at the moment is to include tensorflow/lite/delegates/flex:delegate
in the list of target dependencies, as suggested in the docs。
几天前,提交了 initial support for building TFLite with CMake. In that build script there is an option SELECT_TF_OPS
以在构建中包含委托库。我不知道该版本目前是否有效,但我想它最终会成为即将发布的正式版本的一部分。
libtensorflow-lite.a
似乎是用 Makefiles, out of Bazel, so I'm not sure if you can actually use that option for that library. There is however an experimental shared library target libtensorflowlite.so
that I think may be what you need. You can give the experimental option with_select_tf_ops
构建的,以便在其中包含 TensorFlow 内核。所以我认为构建命令应该是这样的:
bazel build --config=monolithic --define=with_select_tf_ops=true -c opt //tensorflow/lite:libtensorflowlite.so