tf.initialize_all_variables() 和 tf.initialize_local_variables() 有什么区别? [英] What is the difference between tf.initialize_all_variables() and tf.initialize_local_variables()?
问题描述
我正在查看此示例中的代码:fully_connected_reader.py
I am reviewing the code in this example: fully_connected_reader.py
我对第 147 和 148 行感到困惑:
I am confused with Line 147 and 148:
init_op = tf.group(tf.initialize_all_variables(),
tf.initialize_local_variables())
我不知道哪些变量是所有变量
,哪些是局部变量
.有什么想法吗?
I don't know which variables are all variables
and which are local variables
. Any ideas?
推荐答案
tf.initialize_all_variables()
是 tf.initialize_variables(tf.all_variables())
的快捷方式, tf.initialize_local_variables()
是 tf.initialize_variables(tf.local_variables())
的快捷方式,它在 GraphKeys.VARIABLES
和GraphKeys.LOCAL_VARIABLE
集合,分别.
tf.initialize_all_variables()
is a shortcut to tf.initialize_variables(tf.all_variables())
, tf.initialize_local_variables()
is a shortcut to tf.initialize_variables(tf.local_variables())
, which initializes variables in GraphKeys.VARIABLES
and GraphKeys.LOCAL_VARIABLE
collections, respectively.
GraphKeys.LOCAL_VARIABLES
集合中的变量是添加到图中但未保存或恢复的变量 (source).
Variables in GraphKeys.LOCAL_VARIABLES
collection are variables that are added to the graph, but not saved or restored (source).
tf.Variable()
默认为 GraphKeys.VARIABLE
集合添加一个新变量,可以通过 collections= 参数控制.
tf.Variable()
by default adds a new variable to GraphKeys.VARIABLE
collection, which can be controlled by collections= argument.
这篇关于tf.initialize_all_variables() 和 tf.initialize_local_variables() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!