tensorflow: AttributeError: 'module' object has no attribute 'global_variables_initializer'
when I was trying a multi gpu training using python cifar10_multi_gpu_train.py --num_gpus=2, I got an error:
usr@linux:~/tensorflow_source/tensorflow/tensorflow/models/image/cifar10$ python cifar10_multi_gpu_train.py --num_gpus=2
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes.
Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes.
Traceback (most recent call last):
File "cifar10_multi_gpu_train.py", line 280, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 30, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "cifar10_multi_gpu_train.py", line 276, in main
train()
File "cifar10_multi_gpu_train.py", line 229, in train
init = tf.global_variables_initializer()
AttributeError: 'module' object has no attribute 'global_variables_initializer'
Seemingly there’s no global_variables_initializer of tf or in other module?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 13
- Comments: 17
Commits related to this issue
- weirdness between 0.11 and 0.12? see tensorflow/tensorflow#5514 — committed to 007/CarND by deleted user 7 years ago
This was introduced lately. Consider upgrading tf or use
tf.initialize_all_variables.(fixed typo)
@schmiflo you mean
tf.initialize_all_variablesthere is a typo.@liusida I changed
global_variables_initializerintoinitialize_all_variables, and it did work, I haven’t updated my tf to the latest version, maybe it has already hadglobal_variables_initializerI solved this by using tf.compat.v1.global_variables_initializer()
@zakizhou yes, i think you are right.
https://github.com/tensorflow/tensorflow/blob/20c3d37ecc9bef0e106002b9d01914efd548e66b/tensorflow/python/ops/variables.py#L1170
This change was made just 12 days ago
https://github.com/tensorflow/tensorflow/commit/4cbdead95f22de74bcbc72a68c9a38d465202db9#diff-ae1a8f7b66539f000615a4ab7e4b2151
@EricBuist if u are using tensorflow version 2.x u can try this: import tensorflow.compat.v1 as tf tf.disable_v2_behavior()
It would be nice if you update your tutorial here https://www.tensorflow.org/tutorials/mnist/beginners/ to use the new method.
@schmiflo Thankyou for your solution. However I got error by just blindly copy and paste the code. There is typo in
tf.intialize_all_variables. It should betf.initialize_all_variables. Could you fix it to prevent confusion?It works! Thank you! I changed global_variables_initializer into initialize_all_variables.
best answer:)))