|TensorFlow 1 version||View source on GitHub|
Represents a graph node that performs computation on tensors.
Compat aliases for migration
See Migration guide for more details.
Operation is a node in a
tf.Graph that takes zero or more
objects as input, and produces zero or more
Tensor objects as output.
Objects of type
Operation are created by calling a Python op constructor
tf.matmul) within a
tf.function or under a
For example, within a
c = tf.matmul(a, b) creates an
Operation of type "MatMul" that takes tensors
b as input, and
c as output.
__init__( node_def, g, inputs=None, output_types=None, control_inputs=None, input_types=None, original_op=None, op_def=None )
NOTE: This constructor validates the name of the
Operation names match the following
Operation. Used for attributes of
inputattribute is irrelevant here as it will be computed when generating the model.
Graph. The parent graph.
inputs: list of
Tensorobjects. The inputs to this
output_types: list of
DTypeobjects. List of the types of the
Tensorscomputed by this operation. The length of this list indicates the number of output endpoints of the
control_inputs: list of operations or tensors from which to have a control dependency.
input_types: List of
DTypeobjects representing the types of the tensors accepted by the
Operation. By default uses
[x.dtype.base_dtype for x in inputs]. Operations that expect reference-typed inputs must specify these explicitly.
original_op: Optional. Used to associate the new
Operationwith an existing
Operation(for example, a replica with the op that was replicated).
op_def: Optional. The
op_def_pb2.OpDefproto that describes the op type that this
TypeError: if control inputs are not Operations or Tensors, or if
node_defis not a
NodeDef, or if
gis not a
Graph, or if
inputsare not tensors, or if
ValueError: if the
node_defname is not valid.
Operation objects on which this op has a control dependency.
Before this op is executed, TensorFlow will ensure that the
self.control_inputs have finished executing. This
mechanism can be used to run ops sequentially for performance
reasons, or to ensure that the side effects of an op are observed
in the correct order.
A list of
The name of the device to which this op has been assigned, if any.
The string name of the device to which this op has been assigned, or an empty string if it has not been assigned to a device.
Graph that contains this operation.
The sequence of
Tensor objects representing the data inputs of this op.
The full name of this operation.
NodeDef representation of this operation.
OpDef proto that represents the type of this op.
The list of
Tensor objects representing the outputs of this op.
Returns the call stack from when this operation was constructed.
The type of the op (e.g.
Returns the list of colocation groups of the op.
Returns the value of the attr of this op with the given
name: The name of the attr to fetch.
The value of the attr, as a Python object.
ValueError: If this op does not have an attr with the given
run( feed_dict=None, session=None )
Runs this operation in a
Calling this method will execute all preceding operations that produce the inputs needed for this operation.
N.B. Before invoking
Operation.run(), its graph must have been
launched in a session, and either a default session must be
session must be specified explicitly.
feed_dict: A dictionary that maps
Tensorobjects to feed values. See
tf.Session.runfor a description of the valid feed values.
session: (Optional.) The
Sessionto be used to run to this operation. If none, the default session will be used.
DEPRECATED: Use outputs.