如何在 Tensorflow 中创建不可训练的变量? [英] How to create a non-trainable variable in Tensorflow?

查看:35
本文介绍了如何在 Tensorflow 中创建不可训练的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在将 tf.Variable 指定为不可训练的参数,以便该变量不包含在 tf.trainable_variables() 中?

Does it exist a parameter that specifies a tf.Variable as non-trainable, so that the variable is not included in tf.trainable_variables()?

推荐答案

您可以在 定义:

v = tf.Variable(tf.zeros([1]), trainable=False)

来自链接的文档(大约 TensorFlow v0.11):

From the linked documentation (circa TensorFlow v0.11):

trainable:如果为 True,默认情况下,还会将该变量添加到图形集合 GraphKeys.TRAINABLE_VARIABLES.此集合用作优化器类使用的默认变量列表.

trainable: If True, the default, also adds the variable to the graph collection GraphKeys.TRAINABLE_VARIABLES. This collection is used as the default list of variables to use by the Optimizer classes.

还有一些方法可以使用 API 来更改此条件,例如 tf.get_variable([v]).

There are also ways to change this condition with APIs such as tf.get_variable([v]).

这篇关于如何在 Tensorflow 中创建不可训练的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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