The
Session provides the environment for Operation execution and Tensor evaluation. As shown below,
import tensorflow as tf
# Build a graph.
a = tf.constant([1.0, 2.0])
b = tf.constant([3.0, 4.0])
c = a * b
# Launch the graph in a session.
sess = tf.Session()
# Evaluate the tensor 'c'.
print sess.run(c)
sess.close()
# result: [3., 8.]
p>
a Session might have some resources, such as Variable or Queue. When the session is no longer needed, these resources need to be released. There are two ways to do it,
-
calls session.close() method;
-
USES with tf.session () to create the Context (Context) for execution, which is automatically released when the Context exits.
import tensorflow as tf
# Build a graph.
a = tf.constant([1.0, 2.0])
b = tf.constant([3.0, 4.0])
c = a * b
with tf.Session() as sess:
print sess.run(c)
p>
https://www.cnblogs.com/lienhua34/p/5998853.html
p>
https://blog.csdn.net/qq_36666115/article/details/80017050
p>
div>