Closed wlwatkins closed 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
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
Steps work for me on Ubuntu 20.04
compiling x86_64
version:
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
sudo apt update && sudo apt install bazel
sudo apt install openjdk-11-jdk
Build tensorflowlite c lib from source
cd ~/workspace
git clone https://github.com/tensorflow/tensorflow.git && cd tensorflow
./configure
bazel build --config opt --config monolithic --define tflite_with_xnnpack=false //tensorflow/lite:libtensorflowlite.so
bazel build --config opt --config monolithic --define tflite_with_xnnpack=false //tensorflow/lite/c:libtensorflowlite_c.so
# Check status
file bazel-bin/tensorflow/lite/c/libtensorflowlite_c.so
# ELF 64-bit LSB shared object, x86-64
export CGO_LDFLAGS=-L$HOME/workspace/tensorflow/bazel-bin/tensorflow/lite/c
export CGO_CFLAGS=-I$HOME/workspace/tensorflow/
go get github.com/mattn/go-tflite
go build github.com/mattn/go-tflite
go install github.com/mattn/go-tflite
package main
import (
"fmt"
"github.com/mattn/go-tflite"
)
func main() {
model := tflite.NewModelFromFile("model.tflite")
options := tflite.NewInterpreterOptions()
interp := tflite.NewInterpreter(model, options)
status := interp.AllocateTensors()
input := interp.GetInputTensor(0)
in := input.Float32s()
fmt.Println(status, len(in))
status = interp.Invoke()
output := interp.GetOutputTensor(0).Float32s()
fmt.Println(output)
}
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
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. Igit clone https://github.com/tensorflow/tensorflow
and checked outv2.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