Search code examples
sessiontensorflowdefault

What is default session in TensorFlow?


I am trying to understand notion of default session in TensorFlow. Here is an example:

import tensorflow as tf

sess = tf.Session()
print(tf.get_default_session == sess)

returns

False

This one

with sess.as_default() as default_session:
    print(tf.get_default_session == default_session)

also returns

False

And this one

with sess.as_default() as default_session:
    print(tf.get_default_session == sess)

returns

False

What is default session then?


Solution

  • Try this one : it returns true

    sess = tf.InteractiveSession()  
    print(tf.get_default_session() == sess)
    

    True