B W*_* Wu 2 collections tensorflow
我搜索了tensorflow的API文档中的所有资源,但找不到任何指示.看来在使用get_variable()时,我可以为集合术语设置一个特定的名称:
x=tf.get_variable('x',[2,2],collections='my_scope')
Run Code Online (Sandbox Code Playgroud)
这样做时只获得空列表:
tf.get_collection('my_scope')
Run Code Online (Sandbox Code Playgroud)
集合S需要一个list
集合名称.
>>x = tf.get_variable('x',[2,2], collections=['my_scope'])
>>tf.get_collection('my_scope')
[<tensorflow.python.ops.variables.Variable at 0x10d8e1590>]
Run Code Online (Sandbox Code Playgroud)
注意,如果你使用它,其他一些操作可能会产生副作用.喜欢tf.all_variables()
不会工作,因此tf.initialize_all_variables()
也不会看到你的变量.修复它的一种方法是指定默认集合.
>>x = tf.get_variable('x',[2,2], collections=['my_scope', tf.GraphKeys.VARIABLES])
Run Code Online (Sandbox Code Playgroud)
但事情开始变得单调乏味.
归档时间: |
|
查看次数: |
1935 次 |
最近记录: |