page_type: reference
<style> table img { max-width: 100%; } </style>Defined in tensorflow/python/framework/ops.py
.
See the guide: Building Graphs > Core graph data structures
Represents a graph node that performs computation on tensors.
An Operation
is a node in a TensorFlow Graph
that takes zero or
more Tensor
objects as input, and produces zero or more Tensor
objects as output. Objects of type Operation
are created by
calling a Python op constructor (such as
tf.matmul
)
or tf.Graph.create_op
.
For example c = tf.matmul(a, b)
creates an Operation
of type
"MatMul" that takes tensors a
and b
as input, and produces c
as output.
After the graph has been launched in a session, an Operation
can
be executed by passing it to
tf.Session.run
.
op.run()
is a shortcut for calling tf.get_default_session().run(op)
.
The Operation
objects on which this op has a control dependency.
Before this op is executed, TensorFlow will ensure that the
operations in 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 Operation
objects.
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.
The Graph
that contains this operation.
The list of Tensor
objects representing the data inputs of this op.
The full name of this operation.
Returns the NodeDef
representation of this operation.
A
NodeDef
protocol buffer.
Returns the OpDef
proto that represents the type of this op.
An
OpDef
protocol buffer.
The list of Tensor
objects representing the outputs of this op.
Returns the call stack from when this operation was constructed.
Same as traceback but includes start line of function definition.
A list of 5-tuples (filename, lineno, name, code, func_start_lineno).
The type of the op (e.g. "MatMul"
).
__init__(
node_def,
g,
inputs=None,
output_types=None,
control_inputs=None,
input_types=None,
original_op=None,
op_def=None
)
Creates an Operation
.
NOTE: This constructor validates the name of the Operation
(passed
as node_def.name
). Valid Operation
names match the following
regular expression:
[A-Za-z0-9.][A-Za-z0-9_.\\-/]*
node_def
:node_def_pb2.NodeDef
.NodeDef
for theOperation
. Used for attributes ofnode_def_pb2.NodeDef
, typicallyname
,op
, anddevice
. Theinput
attribute is irrelevant here as it will be computed when generating the model.g
:Graph
. The parent graph.inputs
: list ofTensor
objects. The inputs to thisOperation
.output_types
: list ofDType
objects. List of the types of theTensors
computed by this operation. The length of this list indicates the number of output endpoints of theOperation
.control_inputs
: list of operations or tensors from which to have a control dependency.input_types
: List ofDType
objects representing the types of the tensors accepted by theOperation
. 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 newOperation
with an existingOperation
(for example, a replica with the op that was replicated).op_def
: Optional. Theop_def_pb2.OpDef
proto that describes the op type that thisOperation
represents.
TypeError
: if control inputs are not Operations or Tensors, or ifnode_def
is not aNodeDef
, or ifg
is not aGraph
, or ifinputs
are not tensors, or ifinputs
andinput_types
are incompatible.ValueError
: if thenode_def
name is not valid.
colocation_groups()
Returns the list of colocation groups of the op.
get_attr(name)
Returns the value of the attr of this op with the given name
.
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 givenname
.
run(
feed_dict=None,
session=None
)
Runs this operation in a Session
.
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
available, or session
must be specified explicitly.
feed_dict
: A dictionary that mapsTensor
objects to feed values. Seetf.Session.run
for a description of the valid feed values.session
: (Optional.) TheSession
to be used to run to this operation. If none, the default session will be used.
values()
DEPRECATED: Use outputs.