level 8
1. 图(Graph)
TensorFlow 计算被抽象为包括若干节点的有向图。如下图所示例子:对应的 TensorFlow Python 代码如下:import tensorflow as tf b = tf.Variable(tf.zeros([100])) # 100-d vector, init to zeroes W = tf.Variable(tf.random_uniform([784,100],-1,1)) # 784x100 matrix w/rnd vals x = tf.placeholder(name="x") relu = tf.nn.relu(tf.matmul(W, x) + b) C = [...] s = tf.Session for step in xrange(0, 10): input = ...construct 100-D input array ... result = s.run(C, feed_dict={x: input}) print step, result
在 TensorFlow 有向图中,每个节点表示运算符,可以有零个或多个输入,零个或多个输出。
在有向图的普通棱边(从一个节点输出到另一个节点输入)流动的数值称为张量(Tensor),本质为任意维度数组。张量的元素数据类型可以显式指定或在构建有向图时推断得到。
有关图及张量的实现源码均位于 tensorflow/tensorflow/python/framework/ops.py,我们后面会细讲。
2018年03月18日 05点03分
