How to create calculation Chart in the Foundation of TensorFlow
This article shows you how to create a calculation chart on the basis of TensorFlow. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
The following describes TensorFlow and several functions for creating a calculation graph:
G = tf.Graph () # create a new calculation graph g
G.as_default () # sets the calculation chart g to the currently used calculation chart
G0 = tf.get_default_graph () # get the default calculation chart
Tf.reset_default_graph () # clear the default calculation chart
Demonstration 1:
Import tensorflow as tf
# initialize a computed graph object g
G = tf.Graph ()
# add node definition calculation diagram to g
With g.as_default ():
A = tf.constant (10ther name ='a')
B = tf.constant (5 ~ name ='b')
C = tf.add (aPerm b)
Print (c.graph)
The output after execution is:
Demonstration 2:
Import tensorflow as tf
# get the default computed graph object handle G0
G0 = tf.get_default_graph ()
# add node definition calculation chart to G0
With g0.as_default ():
A = tf.constant (10ther name ='a')
B = tf.constant (5 ~ name ='b')
C = tf.add (aPerm b)
Print (c.graph)
The output after execution is:
Demonstration 3:
Import tensorflow as tf
# clear the default calculation chart
Tf.reset_default_graph ()
# nodes defined directly in Operator will be added to the default calculation diagram
A = tf.constant (10ther name ='a')
B = tf.constant (5 ~ name ='b')
C = tf.add (aPerm b)
Print (c.graph)
# View the Operators in the default calculation chart
Tf.get_default_graph () .get_operations ()
The output after execution is:
It is recommended to use demonstration 1 to define the calculation chart without having to tf.reset_default_graph () every time.
The above is how to create computing diagrams in the foundation of TensorFlow. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.