简体   繁体   中英

TensorFlow 'module' object has no attribute 'global_variables_initializer'

I'm new to Tensorflow I'm running a Deep learning Assignment from Udacity on iPython notebook. link

And it has an error.

AttributeError                            Traceback (most recent call last)
`<ipython-input-18-3446420b5935>` in `<module>`()
  2 
  3 with tf.Session(graph=graph) as session:
----> 4   tf.global_variables_initializer().run()

AttributeError: 'module' object has no attribute 'global_variables_initializer'

Please help! How can I fix this? Thank you.

在旧版本中,它被称为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 ie (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()

In Tensorflow 1.11 You can use both initialize_all_variables().run() or tf.global_variables_initializer()

  #tf.global_variables_initializer().run()
  tf.initialize_all_variables().run()

both of then works fine on

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM