Created
October 19, 2016 11:09
-
-
Save sugyan/d8351d62f186162dca37e1b6354505e5 to your computer and use it in GitHub Desktop.
TensorFlow Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go run main.go | |
2016/10/19 20:07:55 value: 7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
tf "github.com/tensorflow/tensorflow/tensorflow/go" | |
"github.com/tensorflow/tensorflow/tensorflow/go/op" | |
) | |
func main() { | |
scope := op.NewScope() | |
c1, err := op.Const(scope.SubScope("c1"), int8(4)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
c2, err := op.Const(scope.SubScope("c2"), int8(3)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
o, err := op.Add(scope, c1, c2) | |
if err != nil { | |
log.Fatal(err) | |
} | |
sess, err := tf.NewSession(scope.Graph(), nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer sess.Close() | |
results, err := sess.Run(nil, []tf.Output{o}, nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, t := range results { | |
log.Printf("value: %v", t.Value()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment