op

package
v1.0.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package op defines functions for adding TensorFlow operations to a Graph.

Functions for adding an operation to a graph take a Scope object as the first argument. The Scope object encapsulates a graph and a set of properties (such as a name prefix) for all operations being added to the graph.

WARNING: The API in this package has not been finalized and can change without notice.

Example
// This example creates a Graph that multiplies a constant matrix with
// a matrix to be provided during graph execution (via
// tensorflow.Session).
s := NewScope()
input := Placeholder(s, tf.Float) // Matrix to be provided to Session.Run
output := MatMul(s,
	Const(s, [][]float32{{10}, {20}}), // Constant 2x1 matrix
	input,
	MatMulTransposeB(true))
if s.Err() != nil {
	panic(s.Err())
}
// Shape of the product: The number of rows is fixed by m1, but the
// number of columns will depend on m2, which is unknown.
shape, _ := output.Shape()
fmt.Println(shape)
Output:

[2 -1]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Const

func Const(scope *Scope, value interface{}) (output tf.Output)

Const adds an operation to graph that produces value as output.

Types

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope encapsulates common operation properties when building a Graph.

A Scope object (and its derivates, e.g., obtained from Scope.SubScope) act as a builder for graphs. They allow common properties (such as a name prefix) to be specified for multiple operations being added to the graph.

A Scope object and all its derivates (e.g., obtained from Scope.SubScope) are not safe for concurrent use by multiple goroutines.

func NewScope

func NewScope() *Scope

NewScope creates a Scope initialized with an empty Graph.

func (*Scope) AddOperation

func (s *Scope) AddOperation(args tf.OpSpec) *tf.Operation

AddOperation adds the operation to the Graph managed by s.

If there is a name prefix associated with s (such as if s was created by a call to SubScope), then this prefix will be applied to the name of the operation being added. See also Graph.AddOperation.

func (*Scope) Err

func (s *Scope) Err() error

Err returns the error, if any, encountered during the construction of the Graph managed by s.

Once Err returns a non-nil error, all future calls will do the same, indicating that the scope should be discarded as the graph could not be constructed.

func (*Scope) Finalize

func (s *Scope) Finalize() (*tf.Graph, error)

Finalize returns the Graph on which this scope operates on and renders s unusable. If there was an error during graph construction, that error is returned instead.

func (*Scope) SubScope

func (s *Scope) SubScope(namespace string) *Scope

SubScope returns a new Scope which will cause all operations added to the graph to be namespaced with 'namespace'. If namespace collides with an existing namespace within the scope, then a suffix will be added.

Example
var (
	s  = NewScope()
	c1 = Const(s.SubScope("x"), int64(1))
	c2 = Const(s.SubScope("x"), int64(1))
)
if s.Err() != nil {
	panic(s.Err())
}
fmt.Println(c1.Op.Name(), c2.Op.Name())
Output:

x/Const x_1/Const

func (*Scope) UpdateErr

func (s *Scope) UpdateErr(op string, err error)

UpdateErr is used to notify Scope of any graph construction errors while creating the operation op.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL