Collections 在tensorflow中,您可以定义自己的集合名称吗?

Collections 在tensorflow中,您可以定义自己的集合名称吗?,collections,tensorflow,Collections,Tensorflow,我在tensorflow的API文档中搜索了所有资源,没有找到任何迹象。 似乎在使用get_variable()时,我可以为集合设置一个特定的名称,如: x=tf.get_variable('x',[2,2],collections='my_scope') 但执行以下操作时,仅获取空列表: tf.get_collection('my_scope') 集合S需要集合名称的列表 >>x = tf.get_variable('x',[2,2], collections=['my_sco

我在tensorflow的API文档中搜索了所有资源,没有找到任何迹象。 似乎在使用get_variable()时,我可以为集合设置一个特定的名称,如:

x=tf.get_variable('x',[2,2],collections='my_scope')
但执行以下操作时,仅获取空列表:

tf.get_collection('my_scope')

集合S需要集合名称的
列表

>>x = tf.get_variable('x',[2,2], collections=['my_scope'])
>>tf.get_collection('my_scope')

[<tensorflow.python.ops.variables.Variable at 0x10d8e1590>]

但事情开始变得单调乏味。

实际上,您可以使用
tf.get\u collection
创建新的集合:

tf.get_collection('my_collection')
var = tf.get_variable('var', [2, 2], initializer=tf.constant_initializer())
tf.add_to_collection('my_collection', var)
tf.get_collection('my_collection')
var = tf.get_variable('var', [2, 2], initializer=tf.constant_initializer())
tf.add_to_collection('my_collection', var)