Python GraphKeys.trainiable_变量与tf.trainible_变量()

Python GraphKeys.trainiable_变量与tf.trainible_变量(),python,tensorflow,Python,Tensorflow,IsGraphKeys.TRAINABLE_VARIABLES与tf.TRAINABLE_VARIABLES()相同吗 是GraphKeys.TRAINABLE_变量实际上是tf.GraphKeys.TRAINABLE_变量 看起来networks成功地通过以下方式进行了培训: optimizer = tf.train.AdamOptimizer(config.LEARNING_RATE) with tf.control_dependencies(tf.get_collection(tf.Gra

Is
GraphKeys.TRAINABLE_VARIABLES
tf.TRAINABLE_VARIABLES()
相同吗

GraphKeys.TRAINABLE_变量
实际上是
tf.GraphKeys.TRAINABLE_变量

看起来networks成功地通过以下方式进行了培训:

optimizer = tf.train.AdamOptimizer(config.LEARNING_RATE)
with tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)):
    self.train_op = optimizer.minimize(self.loss, var_list=tf.trainable_variables())
但不是用

optimizer = tf.train.AdamOptimizer(config.LEARNING_RATE)
with tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)):
    self.train_op = optimizer.minimize(self.loss)
根据:

正如我在批量规范化示例中所看到的,代码
var\u list
被省略:

x\u norm=tf.layers.batch\u规范化(x,training=training)
# ...
update\u ops=tf.get\u集合(tf.GraphKeys.update\u ops)
使用tf.control\u依赖项(更新操作):
列车运行=优化器。最小化(损失)

如果未将
var\u list
传递给
minimize()
函数,变量将通过以下方式检索(取自
compute\u gradients()
):

如果变量列表为无:
变量列表=(
变量。可训练的_变量()+
ops.get_集合(ops.GraphKeys.Trainiable_RESOURCE_变量))
如果您没有定义任何不在
tf.trainable_variables()
中的
ResourceVariable
实例,则结果应该是相同的。我猜问题出在别的地方

在调用
minimize()
之前,您可以尝试执行一些测试,以确保没有
ResourceVariable
s不在
tf.trainable\u variables()
中:

将tensorflow导入为tf
使用tf.Graph()作为默认值():
x=tf.placeholder(tf.float32,shape=[None,2])
使用tf.name_作用域(“网络”):
对数=tf.layers.density(x,单位=2)
变量列表=(tf.可训练变量()
+tf.get_集合(tf.GraphKeys.TRAINABLE_RESOURCE_变量))
断言集(变量列表)=集(可训练变量()
是的,这是最重要的。可能是代码中其他地方的问题
var_list: Optional list or tuple of Variable objects to update to minimize loss. Defaults to the list of variables collected in the graph under the key GraphKeys.TRAINABLE_VARIABLES.