Latest commit 93a975e Feb 17, 2017 @vrv vrv committed with tensorflower-gardener Merge changes from github.
Change: 147897309
Permalink
..
Failed to load latest commit information.
genop Merge changes from github. Feb 18, 2017
op Merge changes from github. Feb 18, 2017
BUILD Go: Run tests during continuous integration Feb 17, 2017
README.md Go/Java: Update links following the 1.0 release. Feb 15, 2017
doc.go Website: Add a reference to the Go API in the "API DOCS" section. Nov 14, 2016
example_inception_inference_test.go Merge changes from github. Feb 18, 2017
graph.go Go: Support setting shape valued attributes. Jan 17, 2017
graph_test.go go: Ability to import a pre-defined Graph. Sep 23, 2016
lib.go Go: Add PartialRun support. Feb 17, 2017
operation.go Go: Add Output.DataType() Feb 9, 2017
operation_test.go Go: Add Output.DataType() Feb 9, 2017
saved_model.go Go: Add blank line to avoid Copyright notice from appearing as packag… Feb 15, 2017
saved_model_test.go Go: Add blank line to avoid Copyright notice from appearing as packag… Feb 15, 2017
session.cpp Go: Add PartialRun support. Feb 17, 2017
session.go Go: Add PartialRun support. Feb 17, 2017
session_test.go Go: Add PartialRun support. Feb 17, 2017
shape.go Go: Support setting shape valued attributes. Jan 17, 2017
shape_test.go Go: Support setting shape valued attributes. Jan 17, 2017
status.go Initial version of the Go API. The API is subject to change. Aug 23, 2016
tensor.go Go: Support DT_BOOL tensors. Jan 20, 2017
tensor_test.go Go: Support DT_BOOL tensors. Jan 20, 2017
test.sh Go: Run tests during continuous integration Feb 17, 2017
util_test.go Go: Add PartialRun support. Feb 17, 2017
version.go C API: Add TF_Version(), akin to __version__ in python. Nov 15, 2016

README.md

TensorFlow in Go

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

Quickstart

  1. Download and extract the TensorFlow C library, preferably into /usr/local. GPU-enabled versions require CUDA 8.0 and cuDNN 5.1. For other versions, the TensorFlow C library will have to be built from source (see below).

    The following shell snippet downloads and extracts into /usr/local:

    TF_TYPE="cpu" # Set to "gpu" for GPU support
    curl -L \
      "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-$(go env GOOS)-x86_64-1.0.0.tar.gz" |
    sudo tar -C /usr/local -xz
  2. go get this package (and run tests):

    go get github.com/tensorflow/tensorflow/tensorflow/go
    go test github.com/tensorflow/tensorflow/tensorflow/go
  3. Done!

Installing into locations other than /usr/local

The TensorFlow C library (libtensorflow.so) needs to be available at build time (e.g., go build) and run time (go test or executing binaries). If the library has not been extracted into /usr/local, then it needs to be made available through the LIBRARY_PATH environment variable at build time and the LD_LIBRARY_PATH environment variable (DYLD_LIBRARY_PATH on OS X) at run time.

For example, if the TensorFlow C library was extracted into /dir, then:

export LIBRARY_PATH=/dir/lib
export LD_LIBRARY_PATH=/dir/lib   # For Linux
export DYLD_LIBRARY_PATH=/dir/lib # For OS X

Building the TensorFlow C library from source

If the "Quickstart" instructions above do not work (perhaps the release archives are not available for your operating system or architecture, or you're using a different version of CUDA/cuDNN), then the TensorFlow C library must be built from source.

Prerequisites

  • bazel
  • Environment to build TensorFlow from source code (Linux or OS X). If you don't need GPU support, then try the following: sh # Linux sudo apt-get install python swig python-numpy # OS X with homebrew brew install swig

Build

  1. Download the source code

    go get -d github.com/tensorflow/tensorflow/tensorflow/go
  2. Build the TensorFlow C library:

    cd ${GOPATH}/src/github.com/tensorflow/tensorflow
    ./configure
    bazel build --config 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.,

    sudo cp ${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow/libtensorflow.so /usr/local/lib

    OR

    b. Setting environment variables:

    export LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow
    # Linux
    export LD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow
    # OS X
    export DYLD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow
  4. Build and test:

    go test github.com/tensorflow/tensorflow/tensorflow/go

Support

Use stackoverflow and/or Github issues.

Contributions

Contributions are welcome. If making any signification changes, probably best to discuss on a Github issue before investing too much time. Github pull requests are used for contributions.