TensorFlow Tutorial : Graph and Session

Graph

A computational graph is a series of TensorFlow operations arranged into a graph. The graph is composed of two types of objects.

tf.Operation (or “ops”): The nodes of the graph. Operations describe calculations that consume and produce tensors.
tf.Tensor: The edges in the graph. These represent the values that will flow through the graph. Most TensorFlow functions return tf.Tensors.

Quoting from TensorFlow – Guide – Low Level APIs – Introduction

从上面的介绍可以看出, Graph主要包含两种构成,OperationTensor.
Operation构成了图中的节点, 用来表示消费和生产Tensor的计算过程.
Tensor构成了图中的边, 表示的是在图中进行流动的值. TensorFlow中大部分的方法都会返回Tensor.

What is a tf.Graph?
A tf.Graph contains two relevant kinds of information:

Graph structure. The nodes and edges of the graph, indicating how individual operations are composed together, but not prescribing how they should be used. The graph structure is like assembly code: inspecting it can convey some useful information, but it does not contain all of the useful context that source code conveys.

Graph collections. TensorFlow provides a general mechanism for storing collections of metadata in a tf.Graph. The tf.add_to_collection function enables you to associate a list of objects with a key (where tf.GraphKeys defines some of the standard keys), and tf.get_collection enables you to look up all objects associated with a key. Many parts of the TensorFlow library use this facility: for example, when you create a tf.Variable, it is added by default to collections representing “global variables” and “trainable variables”. When you later come to create a tf.train.Saver or tf.train.Optimizer, the variables in these collections are used as the default arguments.

Quoting from TensorFlow – Guide – Low Level APIs – Graph and Sessions

Session

Graph && Session

Graph是用来定义操作和变量的. 定义好了之后, 交给Session进行加载和计算. Session同时管理资源.

References

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据