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 ¶
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 (*Scope) AddOperation ¶
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 ¶
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 ¶
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 ¶
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