且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Android上运行Tensorflow模型

更新时间:2023-10-20 16:14:28

在WORKSPACE文件中设置Android NDK之后,Bazel可以交叉编译.so for Android,如下所示:

After setting up an Android NDK in your WORKSPACE file, Bazel can cross-compile a .so for Android, like this:

cc_binary(
    name = "libfoo.so",
    srcs = ["foo.cc"],
    deps = [":bar"],
    linkstatic = 1,
    linkshared = 1,
)

$ bazel build foo:libfoo.so \
    --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a \
    --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
$ file bazel-bin/foo/libfoo.so
bazel-bin/foo/libfoo.so: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), not stripped

Bazel希望所有Java应用程序代码都在"WORKSPACE"内部 顶层目录(在Tensorflow仓库中)

Bazel wants all of the java app code to be inside the 'WORKSPACE' top-level directory (in the Tensorflow repo)

当0.1.4发布(现在将其推送)并且我们已经对TensorFlow和Protobuf进行了一些修复时,您可以开始使用TensorFlow回购作为远程存储库.在WORKSPACE文件中对其进行设置后,即可使用@tensorflow//foo/bar标签引用TensorFlow规则.

When 0.1.4 is released (pushing it right now) and we have pushed some fixes to TensorFlow and Protobuf, you can start using the TensorFlow repo as a remote repository. After setting it up in your WORKSPACE file, you can then refer to TensorFlow rules using @tensorflow//foo/bar labels.