1 # TensorFlow in Go 2 3 Construct and execute TensorFlow graphs in Go. 4 5 [![GoDoc](https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go?status.svg)](https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go) 6 7 > *WARNING*: The API defined in this package is not stable and can change 8 > without notice. The same goes for the awkward package path 9 > (`github.com/tensorflow/tensorflow/tensorflow/go`). 10 11 ## Quickstart 12 13 Refer to [Installing TensorFlow for Go](https://www.tensorflow.org/install/install_go) 14 15 ## Building the TensorFlow C library from source 16 17 If the "Quickstart" instructions above do not work (perhaps the release archives 18 are not available for your operating system or architecture, or you're using a 19 different version of CUDA/cuDNN), then the TensorFlow C library must be built 20 from source. 21 22 ### Prerequisites 23 24 - [bazel](https://www.bazel.build/versions/master/docs/install.html) 25 - Environment to build TensorFlow from source code 26 ([Linux](https://www.tensorflow.org/install/install_sources#PrepareLinux) 27 or [OS 28 X](https://www.tensorflow.org/install/install_sources#PrepareMac)). 29 If you don't need GPU support, then try the following: 30 31 ```sh 32 sudo apt-get install python swig python-numpy # Linux 33 brew install swig # OS X with homebrew 34 ``` 35 36 ### Build 37 38 1. Download the source code 39 40 ```sh 41 go get -d github.com/tensorflow/tensorflow/tensorflow/go 42 ``` 43 44 2. Build the TensorFlow C library: 45 46 ```sh 47 cd ${GOPATH}/src/github.com/tensorflow/tensorflow 48 ./configure 49 bazel build --config opt //tensorflow:libtensorflow.so 50 ``` 51 52 This can take a while (tens of minutes, more if also building for GPU). 53 54 3. Make `libtensorflow.so` available to the linker. This can be done by either: 55 56 a. Copying it to a system location, e.g., 57 58 ```sh 59 sudo cp ${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow/libtensorflow.so /usr/local/lib 60 ``` 61 62 OR 63 64 b. Setting environment variables: 65 66 ```sh 67 export LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow 68 # Linux 69 export LD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow 70 # OS X 71 export DYLD_LIBRARY_PATH=${GOPATH}/src/github.com/tensorflow/tensorflow/bazel-bin/tensorflow 72 ``` 73 74 4. Build and test: 75 76 ```sh 77 go test github.com/tensorflow/tensorflow/tensorflow/go 78 ``` 79 80 ### Generate wrapper functions for ops 81 82 Go functions corresponding to TensorFlow operations are generated in `op/wrappers.go`. To regenerate them: 83 84 Prerequisites: 85 - [Protocol buffer compiler (protoc) 3.x](https://github.com/google/protobuf/releases/) 86 - The TensorFlow repository under GOPATH 87 88 ```sh 89 go generate github.com/tensorflow/tensorflow/tensorflow/go/op 90 ``` 91 92 ## Support 93 94 Use [stackoverflow](http://stackoverflow.com/questions/tagged/tensorflow) and/or 95 [Github issues](https://github.com/tensorflow/tensorflow/issues). 96 97 ## Contributions 98 99 Contributions are welcome. If making any signification changes, probably best to 100 discuss on a [Github issue](https://github.com/tensorflow/tensorflow/issues) 101 before investing too much time. Github pull requests are used for contributions. 102