tensorflow 防止将变量添加到可训练变量 [英] tensorflow prevent variables to be added to trainable variables

查看:36
本文介绍了tensorflow 防止将变量添加到可训练变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 ...(如果 bc 是 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 防止将变量添加到可训练变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆