tensorflow-發生警告錯誤 Use `tf.global_variables_initializer` instead. 解決

通常執行 tensorflow 時,偶而會發生一些錯誤
例如
當發生下列錯誤時
WARNING:tensorflow:From <stdin>:1 in <module>.: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use `tf.global_variables_initializer` instead.
表示 tensorflow 的版本比較新,語法已經修正過,我們可以透過語法進行查詢例如

import tensorflow as tf

tf.__version__




例如我的版本為1.4.0
則當我輸入

tf.Session().run(tf.initialize_all_variables())

會發生錯誤警告

WARNING:tensorflow:From <stdin>:1 in <module>.: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use `tf.global_variables_initializer` instead.



其實我們只要改成相對應的語法即可解決

tf.Session().run(tf.global_variables_initializer())


但是如果版本為0.11 可能會發生下列錯誤
tf.Session().run(tf.global_variables_initializer())

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

因為0.11版以前尚未修正這個語法,該修正語法在0.12後才能使用!!

留言

這個網誌中的熱門文章

c語言-關於#define用法

CMD常用網管指令

PHP 與 JavaScript 之間傳值利用 json