tree: 2cf218b44417e30eebd9bb6a97c3daeba24de144 [path history] [tgz]
  1. genop/
  2. op/
  3. BUILD
  4. doc.go
  5. example_inception_inference_test.go
  6. graph.go
  7. graph_test.go
  8. lib.go
  9. operation.go
  10. operation_test.go
  11. README.md
  12. session.go
  13. session_test.go
  14. status.go
  15. tensor.go
  16. tensor_test.go
  17. util_test.go
  18. version.go
tensorflow/go/README.md

TensorFlow Go API

Construct and execute TensorFlow graphs in Go.

GoDoc

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).

Requirements

  • Go version 1.7+

  • bazel

  • 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
    

Installation

  1. Download the TensorFlow source code:

    go get -d github.com/tensorflow/tensorflow/tensorflow/go
    
  2. Build the TensorFlow library (libtensorflow.so):

    cd ${GOPATH}/src/github.com/tensorflow/tensorflow
    ./configure
    bazel build -c opt //tensorflow:libtensorflow.so
    

    This can take a while (tens of minutes, more if also building for GPU).

  3. Make libtensorflow.so available 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/lib
    

    OR

    b. Setting the LD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow environment variable (DYLD_LIBRARY_PATH on Mac OS X).

  4. 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

Contributions

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.