Construct and execute TensorFlow graphs in Go.
WARNING: The API defined in this package is not stable and can change without notice. The same goes for the awkward package path (
github.com/tensorflow/tensorflow/tensorflow/go).
-
Go version 1.7+
-
Environment to build TensorFlow from source code (Linux or Mac OS X). If you'd like to skip reading those details and do not care about GPU support, try the following:
# On Linux sudo apt-get install python swig python-numpy # On Mac OS X with homebrew brew install swig
-
Download the TensorFlow source code:
go get -d github.com/tensorflow/tensorflow/tensorflow/go -
Build the TensorFlow library (
libtensorflow.so):cd ${GOPATH}/src/github.com/tensorflow/tensorflow ./configure bazel build -c opt //tensorflow:libtensorflow.soThis can take a while (tens of minutes, more if also building for GPU).
-
Make
libtensorflow.soavailable to the linker. This can be done by either:a. Copying it to a system location, e.g.,
cp ${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow/libtensorflow.so /usr/local/libOR
b. Setting the
LD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflowenvironment variable (DYLD_LIBRARY_PATHon Mac OS X). -
Generate wrapper functions for TensorFlow ops:
go generate github.com/tensorflow/tensorflow/tensorflow/go/op
After this, the go tool should be usable as normal. For example:
go test -v github.com/tensorflow/tensorflow/tensorflow/go
This API has been built on top of the C API, which is intended for building language bindings for TensorFlow functionality. However, this is far from complete. Contributions are welcome.