参考  tf.Operation - 云+社区 - 腾讯云

Class Operation

Represents a graph node that performs computation on tensors.

Aliases:

  • Class tf.compat.v1.Oeration
  • Class tf.compat.v2.Operation

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.compat.v1.get_default_session().run(op).

__init__

View source

__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. NodeDef for the Operation. Used for attributes of node_def_pb2.NodeDef, typically name, op, and device. The input attribute is irrelevant here as it will be computed when generating the model.
  • g: Graph. The parent graph.
  • inputs: list of Tensor objects. The inputs to this Operation.
  • output_types: list of DType objects. List of the types of the Tensors computed by this operation. The length of this list indicates the number of output endpoints of the Operation.
  • control_inputs: list of operations or tensors from which to have a control dependency.
  • input_types: List of DType objects 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 Operation with an existing Operation (for example, a replica with the op that was replicated).
  • op_def: Optional. The op_def_pb2.OpDef proto that describes the op type that this Operation represents.

Raises:

  • TypeError: if control inputs are not Operations or Tensors, or if node_def is not a NodeDef, or if g is not a Graph, or if inputs are not tensors, or if inputs and input_types are incompatible.
  • ValueError: if the node_def name 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:

  • A NodeDef protocol buffer.

op_def

Returns the OpDef proto that represents the type of this op.

Returns:

  • An OpDef 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.

1traceback_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").

2、Methods

1、colocation_groups

View source

colocation_groups()

Returns the list of colocation groups of the op.

2、get_attr

View source

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.

3、run

View source

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.

Args:

  • feed_dict: A dictionary that maps Tensor objects to feed values. See tf.Session.run for a description of the valid feed values.
  • session: (Optional.) The Session to be used to run to this operation. If none, the default session will be used.

4、values

View source

values()

DEPRECATED: Use outputs.

tf.Operation相关推荐

  1. python tensorflow tf.Session().run()函数(运行操作并评估“fetches”中的张量)

    参考文章:TensorFlow-sess.run() 当我们构建完图(可能是我们pre_process后生成的图片?NoNoNo,它只是指tensorflow框架的一种设计理念--计算流图)后,需要在 ...

  2. TensorFlow 学习(七) — 常用函数 api、tf.nn、tf.keras

    0. 四则运算 平方:tf.square(),开方:tf.sqrt() tf.add().tf.sub().tf.mul().tf.div().tf.mod().tf.abs().tf.neg() 1 ...

  3. 批标准化 tf.keras.layers.BatchNormalization 中的trainable参数与training参数比较

    巨坑提醒:tf.keras与tensorflow混用,trainable=False根本不起作用.正文不用看了. 摘要: 在tensorflow中,training参数和trainable参数是两个不 ...

  4. 批标准化 tf.keras.layers.BatchNormalization 参数解析与应用分析

    Table of Contents 函数调用 设置training=None时可能存在的问题 :tf.keras.backend.learning_phase()的特点 批标准化函数产生的变量是可训练 ...

  5. tf.reset_default_graph()

    tf.reset_default_graph函数用于清除默认图形堆栈并重置全局默认图形. 注意:默认图形是当前线程的一个属性.该tf.reset_default_graph函数只适用于当前线程.当一个 ...

  6. Dive into TensorFlow - 解析 TF 核心抽象 op 算子

    TF 计算图从逻辑层来讲,由 op 与 tensor 构成.op 是项点代表计算单元,tensor 是边代表 op 之间流动的数据内容,两者配合以数据流图的形式来表达计算图.那么 op 对应的物理层实 ...

  7. 对于operation操作的理解

    #如果存在函数复用的情况 比如add用了好几次 那么后面的operation名字是什么样子的呢 import tensorflow as tf def calu(a,b):out = tf.add(a ...

  8. TensorFlow算子融合

    TensorFlow算子融合 • TensorFlow的特点: o 真正的可移植性 o 引入各种计算设备的支持,包括CPU,GPU,以及能够很好的运行在各种系统的移动端 o 多语言支持 o 支持C++ ...

  9. TensorFlow之会话

    TensorFlow之会话 1.1 会话 一个运行TensorFlow operation的类.会话包含以下两种开启方式 tf.Session:用于完整的程序当中     [如在pycharm中写代码 ...

最新文章

  1. Spring之HelloWorld再起
  2. R语言画Cox回归森林图
  3. 06上半年网络工程师试题分类精讲.第一部分:计算机与网络知识(上午考试科目).第一章:计算机系统知识...
  4. Ant Design Pro 改变默认启动端口号
  5. CAP-微服务间通信实践
  6. python列表浅复制_Python列表深浅复制详解
  7. Hadoop生态圈-Hbase的API常见操作
  8. 腾讯牵手数十家合作伙伴发起“光合计划” 推动“百千万”三大目标落地
  9. WIN10 64位 JDK的安装
  10. mysql中date与datetime类型的区别
  11. java聊天室源工程文件_socket实现java聊天室,公告等功能,前后端分离(附源码)...
  12. 在计算机网络中vc是,计算机网络——第一章 体系
  13. Eclipse ADT 进行android应用签名打包详解
  14. 微PE制作U盘启动盘教程
  15. shiro的anon失效问题
  16. codeforces 849B Tell Your World(计算几何)
  17. spring boot 作业管理系统
  18. TiggerRamDisk的超详细使用教程(亲测成功)
  19. python 第五章 字典
  20. TKO 6-2 DP入门之2084(基本dp之数塔问题)

热门文章

  1. 都市白领们值得收藏-大病之前的先兆,请有心人收藏分享一下!
  2. 第二幅“码绘”——创意自画像
  3. FileYee一键备份电脑所有文件内容
  4. win 10 配置 Github ssh key
  5. 同步调制和异步调制区别
  6. Linux/centos更改网卡名字
  7. 推箱子(Java版)
  8. 线卡(line card)
  9. Linux中使用echo修改用户密码
  10. 是后门,还是大意?Furucombo遭黑客攻击事件分析 |零时科技