mattn / go-tflite

Go binding for TensorFlow Lite
MIT License
304 stars 44 forks source link

How does one install Tensorflow Lite C API #34

Closed wlwatkins closed 4 years ago

wlwatkins commented 4 years ago

Hi, I must be pretty ignorant, but I cannot figure out how to install Tensorflow Lite C API. I just got my coral TPU, and the sales from Google told me that they worked with you @mattn to allow tensorflow lite to work in go. But everywhere on the tensorflow website, it shows installation with pip in python. I got bazel working, but I don't know where /source/directory/tensorflow is supposed to be. I git clone https://github.com/tensorflow/tensorflow and checked out v2.2.0-rc3 but no dice.

Could you enlighten me for the initial setup?

My goal is to develop in go on a ubuntu intel 64 machine and then, once everything is running, install everything on a raspberry pi and compile it over there. I'm saying this because the only instructions to make Tensorflow for C is for arm based systems on their website https://www.tensorflow.org/lite/guide/build_arm64

wlwatkins commented 4 years ago

fyi

/src$ bazel build --config opt --config monolithic tensorflow:libtensorflow_c.so
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=176
INFO: Reading rc options for 'build' from /home/dev/Documents/tensorflow/src/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /home/dev/Documents/tensorflow/src/.bazelrc:
  'build' options: --apple_platform_type=macos --define framework_shared_object=true --define open_source_build=true --java_toolchain=//third_party/toolchains/java:tf_java_toolchain --host_java_toolchain=//third_party/toolchains/java:tf_java_toolchain --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --noincompatible_prohibit_aapt1 --enable_platform_specific_config --config=v2
INFO: Found applicable config definition build:v2 in file /home/dev/Documents/tensorflow/src/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
ERROR: Config value opt is not defined in any .rc file
wlwatkins commented 4 years ago

changing --config opt to -c opt I manage to compile the different commands. However, I still run into issues, mainly, when I go and build an example, I get

# github.com/mattn/go-tflite
/usr/bin/ld: cannot find -ltensorflowlite_c
collect2: error: ld returned 1 exit status

which I don't really know how to fix, since the bazel command builds libtensorflow_c

leondgarse commented 4 years ago

Steps work for me on Ubuntu 20.04 compiling x86_64 version:

wlwatkins commented 4 years ago

Thank you so much, I had to copy some stuff to usr/local/lib as described in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/README.md