Go language bindings to the TensorFlow C API
Graft contains nightly and release builds of the Go language bindings to the TensorFlow C API, including Go-compiled TensorFlow protocol buffers and generated Go wrappers for TensorFlow operations.
Use Graft exactly as you would use the Go bindings found in the main TensorFlow
repo, and with the following import statement: github.com/wamuir/graft/tensorflow
Note: the Go bindings depend on libtensorflow, which should be downloaded (or compiled) and installed first.
Installation is performed using go get
:
go get -u github.com/wamuir/graft/tensorflow/...
Hello TensorFlow
package main
import (
tf "github.com/wamuir/graft/tensorflow"
"github.com/wamuir/graft/tensorflow/op"
"fmt"
)
func main() {
// Construct a graph with an operation that produces a string constant.
s := op.NewScope()
c := op.Const(s, "Hello from TensorFlow version " + tf.Version())
graph, err := s.Finalize()
if err != nil {
panic(err)
}
// Execute the graph in a session.
sess, err := tf.NewSession(graph, nil)
if err != nil {
panic(err)
}
output, err := sess.Run(nil, []tf.Output{c}, nil)
if err != nil {
panic(err)
}
fmt.Println(output[0].Value())
}
Graft is a compilation of TensorFlow source code.