Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AI and Deep Learning by (55.6k points)
Is there any way to close the TensorFlow session automatically?

1 Answer

0 votes
by (119k points)

You can use ‘with’ statement to close a TensorFlow session automatically in your code. Here is an example of how you can implement this:

with tf.session() as sess1:

             output = sess1.run(result)

            print(output)

If you run the above code, the TensorFlow session will automatically be closed after printing the output.

If you want to learn Tensorflow, you can enroll in this Artificial Intelligence course by Intellipaat.

You can watch this video on Tensorflow in 10 minutes to know tricks with TensorFlow:

Browse Categories

...