How to understand sess.as_default() and sess.graph.as_default()?

Viewed 14565

I read the docs of sess.as_default()

N.B. The default session is a property of the current thread. If you create a new thread, and wish to use the default session in that thread, you must explicitly add a with sess.as_default(): in that thread's function.

My understanding is that if there are two more sessions when a new thread is created, we must set a session to run TensorFlow code in it. So, to do this, a session is chosen and as_default() is called.

N.B. Entering a with sess.as_default(): block does not affect the current default graph. If you are using multiple graphs, and sess.graph is different from the value of tf.get_default_graph, you must explicitly enter a with sess.graph.as_default(): block to make sess.graph the default graph.

In sess.as_default() block, to call a specific graph, one must call sess.graph.as_default() to run the graph?

1 Answers
Related