问题描述
我正在使用 tensorflow while_loop.问题是我在 while_loop 主体中创建的变量将被添加到可训练变量中.例如:
i'm using tensorflow while_loop. The problem is variables that i created in the body of the while_loop will be added to trainable variable. For example:
def body(b, c):
a = b + c
...
(others calculations that create variables like a)
...
return b, c
a 被添加到 trainable_variables
a was add to trainable_variables
推荐答案
如果您正在使用 tf.Variable
获取变量,然后您可以将 trainable=False
提供给 tf.Variable
的构造函数.但是,在您的示例中, a
可能不是 TensorFlow Variable ...(如果 b
和 c
是 Variable 对象,则 a
是一个张量).没有更多的上下文或代码,我无话可说.
If you're using tf.Variable
to obtain variables, then you could supply trainable=False
to tf.Variable
's constructor. In your example, however, a
is likely not a TensorFlow Variable ... (if b
and c
are Variable objects, then a
is a Tensor). Without more context or code, there's not much else I can say.
这篇关于tensorflow 防止将变量添加到可训练变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!