Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在tensorflow中设置默认变量集合?_Tensorflow - Fatal编程技术网

如何在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(...)