From 2f6e25df47c24b9c84907b605bdbac4a3b208288 Mon Sep 17 00:00:00 2001 From: Asim Shankar Date: Thu, 29 Sep 2016 13:34:47 -0800 Subject: [PATCH] go: Make example easier to try out. godoc.org translates full-file examples into a "main" package. This change makes the example so that the generated "main" code can be copy-pasted and thus used to try out a standalone binary. Another step towards #10 Change: 134709944 --- .../go/example_inception_inference_test.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tensorflow/go/example_inception_inference_test.go b/tensorflow/go/example_inception_inference_test.go index abed215d02b..45a38996208 100644 --- a/tensorflow/go/example_inception_inference_test.go +++ b/tensorflow/go/example_inception_inference_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package tensorflow +package tensorflow_test import ( "bufio" @@ -22,6 +22,8 @@ import ( "io/ioutil" "log" "os" + + tf "github.com/tensorflow/tensorflow/tensorflow/go" ) func Example() { @@ -69,13 +71,13 @@ func Example() { } // Construct an in-memory graph from the serialized form. - graph := NewGraph() + graph := tf.NewGraph() if err := graph.Import(model, ""); err != nil { log.Fatal(err) } // Create a session for inference over graph. - session, err := NewSession(graph, nil) + session, err := tf.NewSession(graph, nil) if err != nil { log.Fatal(err) } @@ -90,10 +92,10 @@ func Example() { log.Fatal(err) } output, err := session.Run( - map[Output]*Tensor{ + map[tf.Output]*tf.Tensor{ graph.Operation("input").Output(0): tensor, }, - []Output{ + []tf.Output{ graph.Operation("output").Output(0), }, nil) @@ -134,7 +136,7 @@ func printBestLabel(probabilities []float32, labelsFile string) { // Given an image stored in filename, returns a Tensor which is suitable for // providing the image data to the pre-defined model. -func makeTensorFromImageForInception(filename string) (*Tensor, error) { +func makeTensorFromImageForInception(filename string) (*tf.Tensor, error) { const ( // Some constants specific to the pre-trained model at: // https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip @@ -179,5 +181,5 @@ func makeTensorFromImageForInception(filename string) (*Tensor, error) { ret[0][y][x][2] = float32((int(r>>8) - Mean)) / Std } } - return NewTensor(ret) + return tf.NewTensor(ret) }