如何在 Tensorflow 中将变量重用设置回 False? [英] How to set variable reuse back to False in Tensorflow?
问题描述
在 Tensorlfow 中,我们可以使用 tf.get_variable_scope().reuse_variables()
将变量重用设置为 True
,是否有任何方法可以将其设置回 False 而无需离开范围?
In Tensorlfow, we can set variable reuse to True
with tf.get_variable_scope().reuse_variables()
, is there any way it to set it back to False without leaving the scope?
推荐答案
这是不可能的.在关于共享变量的教程中,他们明确指出:
This is not possible. In the tutorial on Sharing Variables, they explicitly state:
请注意,您不能将重用标志设置为 False.这背后的原因是允许组合创建模型的函数.想象一下,您像以前一样编写了一个函数 my_image_filter(inputs).有人在变量范围内调用函数并使用重用 = True 会期望所有内部变量也被重用.允许在函数内部强制使用重用=False 会破坏这个约定并使得以这种方式共享参数变得困难
Note that you cannot set the reuse flag to False. The reason behind this is to allow to compose functions that create models. Imagine you write a function my_image_filter(inputs) as before. Someone calling the function in a variable scope with reuse=True would expect all inner variables to be reused as well. Allowing to force reuse=False inside the function would break this contract and make it hard to share parameters in this way
你必须离开你的范围并打开另一个同名且reuse=False
You have to get out of your scope and open another with the same name and reuse=False
这篇关于如何在 Tensorflow 中将变量重用设置回 False?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!