Tensorflow中Graph的概念
来源:互联网 发布:临海停水通知软件 编辑:程序博客网 时间:2024/06/06 00:38
一、英文文档深入解读
class tf.Graph
A TensorFlow computation, represented as a dataflow graph.
Graph实际上是一个由数据流图表示的计算过程
A Graph
contains a set of Operation
objects, which represent units of computation; and Tensor
objects, which represent the units of data that flow between operations.
Graph表示了数据流图中的操作流水,而Tensor表示的是其中流动的数据
底下这几段讲述了系统默认的Graph获取方式,以及他的“线程不安全”特性。
A default Graph
is always registered, and accessible by calling tf.get_default_graph()
. To add an operation to the default graph, simply call one of the functions that defines a new Operation
:
c = tf.constant(4.0)assert c.graph is tf.get_default_graph()
Another typical usage involves the Graph.as_default()
context manager, which overrides the current default graph for the lifetime of the context:
g = tf.Graph()with g.as_default(): # Define operations and tensors in `g`. c = tf.constant(30.0) assert c.graph is g
Important note: This class is not thread-safe for graph construction. All operations should be created from a single thread, or external synchronization must be provided. Unless otherwise specified, all methods are not thread-safe.
二、关于Tensorflow的图计算过程
我们通过下面的代码来看一下Tensorflow的图计算过程:
import tensorflow as tfa = tf.constant(1)b = tf.constant(2)c = tf.constant(3)d = tf.constant(4)add1 = tf.add(a, b)mul1 = tf.mul(b, c)add2 = tf.add(c, d)output = tf.add(add1, mul1)with tf.Session() as sess: print sess.run(output)# result: 9
上面的代码构成的Graph如下图所示,
当Session加载Graph的时候,Graph里面的计算节点都不会被触发执行。当运行sess.run(output)的时候,会沿着指定的Tensor output来进图路径往回触发相对应的节点进行计算(图中红色线表示的那部分)。当我们需要output的值时,触发Operation tf.add(add1, mul1)被执行,而该节点则需要Tensor add1和Tensor mul1的值,则往回触发Operation tf.add(a, b)和Operation tf.mul(b, c)。以此类推。
所以在计算Graph时,并不一定是Graph中的所有节点都被计算了,而是指定的计算节点或者该节点的输出结果被需要时。
- Tensorflow中Graph的概念
- Tensorflow中 Graph和Session的关系
- 简单记录Tensorflow中Graph和Session的关系
- Tensorflow: Graph
- Tensorflow-Graph
- tensorflow graph 中获取variable operation
- Tensorflow Session graph Op 的理解
- Tensorflow框架中常见的概念和函数一
- GRAPH --- 图的相关概念整理
- tensorflow 中导出/恢复模型Graph数据Saver
- [TensorFlow]理解Tensorboard Graph
- Tensorflow(2) Graph
- 【Tensorflow】tf.Graph()函数
- tensorflow graph 数据结构
- 三十六、深入理解tensorflow的session和graph
- tensorflow 分布式 数据并行 in-graph 自己写的实例
- 【TensorFlow】计算图graph的使用学习笔记(二)
- tensorflow之Graph save and restore in python and c++(C++ 中使用tensorflow)
- 美团API使用之外卖订单
- 【Swift学习】Enum、Struct、Class的学习及异同
- 第四题
- ListView添加自定义适配器最优方案
- java项目通过设置JVM属性参数依赖本地配置
- Tensorflow中Graph的概念
- MooseFS3.0分布式文件系统安装升级手记【迁移02】
- iOS开发 使用NSURLConnection实现图片上传
- shiro注解@RequiresPermissions多权限任选一参数用法
- PAT (Advanced Level) Practise 1049 Counting Ones (30)
- 如何在页面上调用同一个方法
- PoEdu_python_Lesson005_回顾以及作业讲解
- spring RestTemplate用法详解
- cvCreateFileCapture读取AVI格式视频返回NULL