aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/go/example_inception_inference_test.go
diff options
context:
space:
mode:
authorGravatar Asim Shankar <ashankar@google.com>2016-10-27 11:03:48 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-10-27 12:21:17 -0700
commit7351a21714f467eb9d440703001876616d02e0fd (patch)
tree045ef82b2337c660c0440a552923105ff38016f6 /tensorflow/go/example_inception_inference_test.go
parent414eeebc639eb75009ea5bbbac32a1f8a275dd30 (diff)
go: Change generated op function API.
Errors during graph construction are held in the Scope. This makes the op construction code mode compact and nestable as errors do not _need_ to be handled on every op addition. To help ensure that the client does not miss the error completely, the Scope is treated as a "builder" of Graphs, and once the Graph is extracted from the Scope (using Scope.Finalize), the Scope is rendered useless. To help tracing failures to the op, the error stores the stacktrace pointing to when the error occurred, which will help in identifying the precise operation that failed. To use scopes to enhance existing Graphs, the idea is to add a: NewScopeWithGraph(*tf.Graph) *Scope function, but that is not included in this change. Change: 137423318
Diffstat (limited to 'tensorflow/go/example_inception_inference_test.go')
-rw-r--r--tensorflow/go/example_inception_inference_test.go44
1 files changed, 13 insertions, 31 deletions
diff --git a/tensorflow/go/example_inception_inference_test.go b/tensorflow/go/example_inception_inference_test.go
index 88dc9a53fc..09c7004468 100644
--- a/tensorflow/go/example_inception_inference_test.go
+++ b/tensorflow/go/example_inception_inference_test.go
@@ -219,17 +219,6 @@ func constructGraphToNormalizeImage() (graph *tf.Graph, input, output tf.Output,
Mean = float32(117)
Scale = float32(1)
)
- scope := op.NewScope()
- // Shorthand: op.Const can return an error, typically if an invalid
- // type is provided as an argument. Knowing that only valid types will be provided,
- // make a shorthand.
- Const := func(name string, value interface{}) tf.Output {
- out, err := op.Const(scope.SubScope(name), value)
- if err != nil {
- panic(err)
- }
- return out
- }
// - input is a 3D tensor of shape [Height, Width, Colors=3], where
// each pixel is represented as a triplet of 1-byte colors
// - ResizeBilinear (and the inception model) takes a 4D tensor of shape
@@ -237,26 +226,19 @@ func constructGraphToNormalizeImage() (graph *tf.Graph, input, output tf.Output,
// represented as a triplet of floats
// - Apply normalization on each pixel and use ExpandDims to make
// this single image be a "batch" of size 1 for ResizeBilinear.
- if input, err = op.Placeholder(scope, tf.Uint8); err != nil {
- return
- }
- if output, err = op.Cast(scope, input, tf.Float); err != nil {
- return
- }
- if output, err = op.ExpandDims(scope, output, Const("make_batch", int32(0))); err != nil {
- return
- }
- if output, err = op.ResizeBilinear(scope, output, Const("size", []int32{H, W})); err != nil {
- return
- }
- // Subtract the Mean and divide by Scale
- if output, err = op.Sub(scope, output, Const("mean", Mean)); err != nil {
- return
- }
- if output, err = op.Div(scope, output, Const("scale", Scale)); err != nil {
- return
- }
- return scope.Graph(), input, output, nil
+ s := op.NewScope()
+ input = op.Placeholder(s, tf.Uint8)
+ output = op.Div(s,
+ op.Sub(s,
+ op.ResizeBilinear(s,
+ op.ExpandDims(s,
+ op.Cast(s, input, tf.Float),
+ op.Const(s.SubScope("make_batch"), int32(0))),
+ op.Const(s.SubScope("size"), []int32{H, W})),
+ op.Const(s.SubScope("mean"), Mean)),
+ op.Const(s.SubScope("scale"), Scale))
+ graph, err = s.Finalize()
+ return graph, input, output, err
}
func modelFiles(dir string) (modelfile, labelsfile string, err error) {