三种计算图
有三种计算图的构建方式:静态计算图,动态计算图,以及Autograph.
1.计算图简介
计算图由节点(nodes)和线(edges)组成。
- 节点表示操作符Operator,或者称之为算子,线表示计算间的依赖。
- 实线表示有数据传递依赖,传递的数据即张量。
- 虚线通常可以表示控制依赖,即执行先后顺序。
2.静态计算图
在TensorFlow1.0中,使用静态计算图分两步,第一步定义计算图,第二步在会话中执行计算图。
2.1.TensorFlow 1.0静态计算图范例
import tensorflow as tf
#定义计算图
g = tf.Graph()
with g.as_default():
#placeholder为占位符,执行会话时候指定填充对象
x = tf.placeholder(name='x', shape=[], dtype=tf.string)
y = tf.placeholder(name='y', shape=[], dtype=tf.string)
z = tf.st