我试图让所有的变量在变量范围,如解释在这里.但是,tf.get_collection(tf.GraphKeys.VARIABLES, scope='my_scope')即使该范围中存在变量,该行也会返回一个空列表.
这是一些示例代码:
import tensorflow as tf
with tf.variable_scope('my_scope'):
a = tf.Variable(0)
print tf.get_collection(tf.GraphKeys.VARIABLES, scope='my_scope')
Run Code Online (Sandbox Code Playgroud)
打印[].
如何获取声明的变量'my_scope'?
mrr*_*rry 11
tf.GraphKeys.VARIABLES自TensorFlow 0.12起,该集合名称已被弃用.使用tf.GraphKeys.GLOBAL_VARIABLES将给出预期的结果:
with tf.variable_scope('my_scope'):
a = tf.Variable(0)
print tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='my_scope')
# ==> '[<tensorflow.python.ops.variables.Variable object at 0x7f33f67ebbd0>]'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3376 次 |
| 最近记录: |