Wednesday, March 27, 2019

[TensorFlow Lite] Build Tensorflow Lite C++ shared library

Build Tensorflow Lite shared library:

Modify the code: tensorflow/contrib/lite/BUILD in TensorFlow source:
cc_binary(
    name = "libtflite.so",
    deps = [":framework",
        "//tensorflow/contrib/lite/kernels:builtin_ops",
        "//tensorflow/contrib/lite/kernels:eigen_support",
        "//tensorflow/contrib/lite/kernels:gemm_support",
    ],
    linkopts=["-shared -Wl,--whole-archive" ],
    linkshared=1

)

Build it:
bazel build --config opt //tensorflow/contrib/lite:libtflite.so  --cxxopt="-std=c++11" --copt="-O3"

P.S1: From TensorFlow 1.13, the "lite" directory is not under the "tensorflow/contrib" directory, instead directly in "tensorflow/".

P.S2:
you may need to download your TensorFlow version's flatbuffers in here:
https://github.com/tensorflow/tensorflow/blob/master/third_party/flatbuffers/workspace.bzl

"http://mirror.tensorflow.org/github.com/google/flatbuffers/archive/v1.11.0.tar.gz"
or
"https://github.com/google/flatbuffers/archive/v1.11.0.tar.gz",

And build it using CMake:
cmake -G "Unix Makefiles"
sudo make install

No comments: