TensorFlow 'module' object has no attribute 'global_variables_initializer' TensorFlow 'module' object has no attribute 'global_variables_initializer' python python

TensorFlow 'module' object has no attribute 'global_variables_initializer'


In older versions, it was called tf.initialize_all_variables.


Seems like you're using tensorflow 0.11 or older versions. If you see this git-commit, they replaced initialize_all_variables with global_variables_initializer.

So, either you can use initialize_all_variables or update to a newer version i.e. (0.12) or later.


In Tensorflow 2.0 , it does away from session and switches to eager execution. You can still run your code using session if you refer to tf.compat library and disable eager execution. This command should do the work:

tf.compat.v1.global_variables_initializer()