教程地址:TensorFlow官方文档中文版
TensorFlow可以拆成两个词:Tensor(张量)和Flow(流),Tensor代表最底层的数据结构,每一个Tensor可以简易的理解为一个多维数组,类似于Caffe中的Blob,不过与Blob不同的是,对于一张图片,Tensor的四个维度分别是[batch, height, width, channel](Blob的为[batch, channel, height, width])。Tensor存在于节点op(operation)中,op执行计算功能,值得注意的是,Tensor并不真正具有op的输出值(it does not hold the values of that operation's output),它只是代表了这个op操作的返回值,它也可以作为另外一个op的输入。一个Tensor可以在多个op中流动(Flow),这样就组成了一个图(Graph),当图构建好之后,上下文(context)就会启动一个会话(session)来执行图中的op,这时Tensor的值才被计算出来。
创建一个默认图(default graph):
g = tf.Gragh()
with = g.as_default():
它与以下代码是等效的:
with tf.Graph().as_default() as g:这样context就创建了一个默认图。
创建好一个默认图后,就可以通过插入op来构建图:
g = tf.Gragh()
with = g.as_default():
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2)这里插入了两种类型的op:constant和matmul(常量和矩阵相乘),matrix1、matrix2和product代表op返回值的Tensor。
插入op的方式有很多种,如:
tf.Operat

——起步&spm=1001.2101.3001.5002&articleId=54089132&d=1&t=3&u=d2af208ea9654c2ba44c27525f3e5ee4)
8493

被折叠的 条评论
为什么被折叠?



