| View source on GitHub | 
Represents a graph node that performs computation on tensors.
tf.Operation(
    node_def,
    g,
    inputs=None,
    output_types=None,
    control_inputs=None,
    input_types=None,
    original_op=None,
    op_def=None
)
  An Operation is a node in a tf.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) within a tf.function or under a tf.Graph.as_default context manager.
For example, within a tf.function, c = tf.matmul(a, b) creates an Operation of type "MatMul" that takes tensors a and b as input, and produces c as output.
If a tf.compat.v1.Session is used, an Operation of a tf.Graph 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).
| 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 parent graph. | 
| inputs | list of Tensorobjects. The inputs to thisOperation. | 
| output_types | list of DTypeobjects. List of the types of theTensorscomputed 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 of DTypeobjects 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 new Operationwith an existingOperation(for example, a replica with the op that was replicated). | 
| op_def | Optional. The op_def_pb2.OpDefproto that describes the op type that thisOperationrepresents. | 
| Raises | |
|---|---|
| TypeError | if control inputs are not Operations or Tensors, or if node_defis not aNodeDef, or ifgis not aGraph, or ifinputsare not tensors, or ifinputsandinput_typesare incompatible. | 
| ValueError | if the node_defname is not valid. | 
| Attributes | |
|---|---|
| control_inputs | The Operationobjects on which this op has a control dependency.Before this op is executed, TensorFlow will ensure that the operations in  | 
| device | The name of the device to which this op has been assigned, if any. | 
| graph | The Graphthat contains this operation. | 
| inputs | The sequence of Tensorobjects representing the data inputs of this op. | 
| name | The full name of this operation. | 
| node_def | Returns the NodeDefrepresentation of this operation. | 
| op_def | Returns the OpDefproto that represents the type of this op. | 
| outputs | The list of Tensorobjects representing the outputs of this op. | 
| traceback | Returns the call stack from when this operation was constructed. | 
| type | The type of the op (e.g. "MatMul"). | 
colocation_groupscolocation_groups()
Returns the list of colocation groups of the op.
experimental_set_type
experimental_set_type(
    type_proto
)
 Sets the corresponding node's experimental_type field.
See the description of NodeDef.experimental_type for more info.
| Args | |
|---|---|
| type_proto | A FullTypeDef proto message. The root type_if of this object must be TFT_PRODUCT, even for ops which only have a singlre return value. | 
get_attr
get_attr(
    name
)
 Returns the value of the attr of this op with the given name.
| Args | |
|---|---|
| name | The name of 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 given name. | 
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.
Note: Before invokingOperation.run(), its graph must have been launched in a session, and either a default session must be available, orsessionmust be specified explicitly.
| Args | |
|---|---|
| feed_dict | A dictionary that maps Tensorobjects to feed values. Seetf.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. | 
valuesvalues()
    © 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
    https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/Operation