如何在tensorflow中设置默认变量集合?
我想要这样的东西:如何在tensorflow中设置默认变量集合?,tensorflow,Tensorflow,我想要这样的东西: with tf.variable_scope("yes", default_collection=["A", "B"]): ... 我能做些什么吗 使用TF Slim与arg_scope aware相结合使用TF Slim与arg_scope aware相结合这不是很方便,但您可以使用TF定义一个自定义获取程序 def make_local_getter(getter, *args, **kwargs): if kwargs['collections'] is
with tf.variable_scope("yes", default_collection=["A", "B"]):
...
我能做些什么吗 使用TF Slim与arg_scope aware相结合使用TF Slim与arg_scope aware相结合这不是很方便,但您可以使用
TF定义一个自定义获取程序
def make_local_getter(getter, *args, **kwargs):
if kwargs['collections'] is None:
kwargs['collections'] = []
kwargs['collections'] += [tf.GraphKeys.LOCAL_VARIABLES]
return getter(*args, **kwargs)
with tf.variable_scope(scope, custom_getter=make_local_getter):
tf.get_variable(...)
这不是很方便,但是您可以使用tf.variable\u scope
定义一个自定义\u getter
:
def make_local_getter(getter, *args, **kwargs):
if kwargs['collections'] is None:
kwargs['collections'] = []
kwargs['collections'] += [tf.GraphKeys.LOCAL_VARIABLES]
return getter(*args, **kwargs)
with tf.variable_scope(scope, custom_getter=make_local_getter):
tf.get_variable(...)