AttributeError: module 'tensorflow' has no attribute 'Session'

In the latest version of tensorflow, e.g 2.2.0-rc3, session is not supported. Luckily it is now provided with backward compatibility .

#sess = tf.Session(graph = graph1)
 sess = tf.compat.v1.Session(target='', graph=graph1, config=None)

Other attributes were also not supported e.g assign, global_variables_initializer

#update = tf.assign(v, v+1)
 update = tf.compat.v1.assign(v, v+1)
#init_op = tf.compat.v1.global_variables_initializer()
 init_op = tf.compat.v1.global_variables_initializer()

To run v1.x code on tensorflow 2.0:

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.