Class Operation
Represents a graph node that performs computation on tensors.
Aliases:
- Class
tf.compat.v1.Operation - Class
tf.compat.v2.Operationtf.matmulAn 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 ) or tf.Graph.create_op.
For example = tf.m`a`tmul(`a`, `b`)reates an Operation of type "MatMul" that takes tensors a and b as input, and produes 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.compat.v1.get_default_session().run(op).
init
__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_.\\-/]*
Args:
node_def:node_def_pb2.NodeDef.NodeDeffor theOperation. Used for attributes ofnode_def_pb2.NodeDef, typicallyname,op, anddevice. Theinputattribute is irrelevant here as it will be computed when generating the model.g:Graph. The parentgraph.inputs: list ofTensorobjects. Theinputs to thisOperation.output_types: list ofDTypeobjects. List of the types of theTensors computed by thisoperation. The length of this list indicates the number of output endpoints of theOperation.control_inputs: list ofoperations or tensors from which to have a control dependency.input_types: List ofDTypeobjects representingthe types of the tensors accepted by theOperation. By default uses[x.dtype.base_dtype for x in inputs].Operations that expect reference-typedinputs must specify these explicitly.original_op: Optional. Used to associate the newOperationwith an existingOperation(for example, a replica with theopthat was replicated).op_def: Optional. Theop_def_pb2.OpDef proto that describes theoptype that thisOperationrepresents.
Raises:
TypeError: if controlinputsare not Operations or Tensors, or ifnode_defis not aNodeDef, or ifgis not aGraph, or ifinputsare not tensors, or ifinputsandinput_typesare incompatible.ValueError: if thenode_defname is not valid.
Properties
control_inputs
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.
Returns:
A list of Operation objects.
device
The name of the device to which this op has been assigned, if any.
Returns:
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
The Graph that contains this operation.
inputs
The list of Tensor objects representing the data inputs of this op.
name
The full name of this operation.
node_def
Returns the NodeDef representation of this operation.
Returns:
NodeDefA protocol buffer.
op_def
Returns the OpDef proto that represents the type of this op.
Returns:
OpDefAn protocol buffer.
outputs
The list of Tensor objects representing the outputs of this op.
traceback
Returns the call stack from when this operation was constructed.
traceback_with_start_lines
Same as traceback but includes start line of function definition.
Returns:
A list of 5-tuples (filename, lineno, name, code, func_start_lineno).
type
The type of the op (e.g. "MatMul").
Methods
colocation_groups
colocation_groups()
Returns the list of colocation groups of the op.
get_attr
get_attr(name)
Returns the value of the attr of this op with the given name.
Args:
name: Thenameof the attr to fetch.
Returns:
The value of the attr, as a Python object.
Raises:
ValueError: If this op does not have an attr with the givenname.
run
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.
Operation.run()N.B. Before invoking , its graph must have been launched in a session, and either a default session must be available, or session must be specified explicitly.
Args:
feed_dict: A dictionary that mapsTensorobjects to feed values. Seetf.Session.runfor a description of the valid feed values.session: (Optional.) TheSessionto be used to run to this operation. If none, the defaultsessionwill be used.
values
values()
DEPRECATED: Use outputs.