The final session does not have a graphic design reset. If you want to reset the graph, you can either call tf.reset_default_graph() , like this
for _ in range(3): tf.reset_default_graph() var = tf.Variable(0) with tf.Session() as session: session.run(tf.global_variables_initializer()) print(len(session.graph._nodes_by_name.keys()))
or you can do something like this
for _ in range(3): with tf.Graph().as_default() as graph: var = tf.Variable(0) with tf.Session() as session: session.run(tf.global_variables_initializer()) print(len(graph._nodes_by_name.keys()))
source share