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>
Read More:
- Tensorflow reported an error when using session module: attributeerror: module ‘tensorflow’ has no attribute ‘session’, which has been solved
- php open(/var/lib/php/session/sess_4ofxxx, O_RDWR) failed: Permission denied (13)
- Tensorflow in function tf.Print Method of outputting intermediate value
- In tensorflow tf.reduce_ Mean function
- tf.contrib.layers .xavier_ Initializer function usage
- tensorflow.python.framework.errors_impl.InternalError: Failed to create session.
- After the new video card rtx3060 arrives, configure tensorflow and run “TF. Test. Is”_ gpu_ The solution of “available ()” output false
- Tensorflow tf.train.exponential_ Decay function (exponential decay method)
- The routine of benewake tfmini-s / tfmimi plus / tfluna / tf02 Pro / tf03 radar on Python
- Solve the problem of using in tensoft 2. X tf.contrib.slim No module named appears in the package: tensorflow.contrib problem
- tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.
- session_ start(): open(SESSION_ FILE, O_ Rdwr)) failed: processing of permission denied (13)
- Tensorflow error: module ‘tensorflow’ has no attribute ‘xxx’
- Record a problem of no module named ‘tensorflow. Examples’ and’ tensorflow. Examples. Tutorials’ in tensorflow 2.0
- failed to lazily initialize a collection of role: ……, no session or session was closed
- Using pip to install tensorflow: tensorflow — is not a supported wheel on this platform
- Tensorflow operation report error modulenotfounderror: no module named ‘tensorflow. Python. Types’ solution
- To solve the problem of importerror when installing tensorflow: libcublas.so . 10.0, failed to load the native tensorflow runtime error
- Tensorflow error: attributeerror: module ‘tensorflow’ has no attribute ‘unpack’ (‘pack ‘)
- Resolve – keyerror encountered while installing tensorflow GPU: ‘tensorflow’ error