tree: bb8fbdb6df52032a1e0a48711caf60f4f559ebe3 [path history] [tgz]
  1. genop/
  2. op/
  3. android.go
  4. attrs.go
  5. attrs_test.go
  6. BUILD
  7. context.go
  8. context_test.go
  9. doc.go
  10. example_inception_inference_test.go
  11. graph.go
  12. graph_test.go
  13. lib.go
  14. operation.go
  15. operation_test.go
  17. saved_model.go
  18. saved_model_test.go
  19. session.go
  20. session_test.go
  21. shape.go
  22. shape_test.go
  23. status.go
  24. tensor.go
  25. tensor_handle.go
  26. tensor_handle_test.go
  27. tensor_test.go
  29. util_test.go
  30. version.go

TensorFlow in Go

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 package path: (


Refer to Installing TensorFlow for Go

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.


  • bazel

  • Environment to build TensorFlow from source code (Linux or macOS). If you don't need GPU support, then try the following:

    sudo apt-get install python swig python-numpy # Linux
    brew install swig                             # OS X with homebrew


  1. Download the source code

    go get -d
  2. Build the TensorFlow C library:

    cd ${GOPATH}/src/
    bazel build -c opt //

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

  3. Make and available to the linker. This can be done by either:

    a. Copying it to a system location, e.g.,

    sudo cp ${GOPATH}/src/ /usr/local/lib
    sudo cp ${GOPATH}/src/ /usr/local/lib


    b. Setting environment variables:

    export LIBRARY_PATH=${GOPATH}/src/
    # Linux
    export LD_LIBRARY_PATH=${GOPATH}/src/
    # OS X
    export DYLD_LIBRARY_PATH=${GOPATH}/src/
  4. Build and test:

    go test

Generate wrapper functions for ops

Go functions corresponding to TensorFlow operations are generated in op/wrappers.go. To regenerate them:


go generate


Use stackoverflow and/or Github issues.


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.