官术网_书友最值得收藏!

The TensorFlow graph

One of the more important and powerful features of TensorFlow is its graph. When you define one of the three types of TensorFlow data structures previously described, you automatically add a node and an edge to your graph. Nodes represent operations and edges represent tensors, so if we were to do basic multiplication such as the preceding example, const1 and const2 would represent edges in the graph, tf.multiply would represent a node, and product would represent an outgoing edge from that node. TensorFlow's graph is static, which means we cannot change it at runtime.

Remember, an ANN performs hundreds of computations; computing and interpreting at each step would be extremely compute-intensive. The TensorFlow graph helps solve this problem by creating a graph of all tensors and operations in your network and executing them in your runtime session that we previously described. Adjacent operations are compiled together in the graph for faster computation. On top of that, the graph structure allows us to easily distribute computational tasks across multiple CPUs or GPUs, and the TensorFlow session object automatically manages access to these multiple resources, whether local or in the cloud. This is where TensorFlow gets it flow; data and operations flow through the graph at runtime. 

You can either manually define graphs in TensorFlow, or use it's default graph. When we declared the variables precedingly, we declared them in the default graph that TensorFlow sets up for us when we import it. You can access that default graph with: 

default_graph = tf.get_default_graph()

If we're creating multiple models or processes in the same file however, it's necessary to create multiple graphs. For that, TensorFlow allows us to simply declare a new one:

my_graph = tf.Graph()

with new_graph.as_default():
x = tf.constant(2)
y = tf.constant(2)

If you are manually defining multiple graphs, you'll also want to remember to pass those graphs when running a TensorFlow session: 

sess = tf.Session(graph=my_graph)
主站蜘蛛池模板: 沽源县| 高平市| 司法| 赤水市| 元阳县| 齐齐哈尔市| 梁平县| 塘沽区| 阆中市| 泰来县| 陆河县| 基隆市| 西林县| 泾川县| 浪卡子县| 高平市| 通化县| 石狮市| 合江县| 壤塘县| 仁怀市| 平凉市| 格尔木市| 涞水县| 刚察县| 营山县| 剑阁县| 项城市| 社旗县| 安庆市| 岱山县| 邢台县| 正定县| 北票市| 凤山县| 海盐县| 沁源县| 安岳县| 乌兰浩特市| 游戏| 惠水县|