How to create a non-trainable variable in Tensorflow?

后端 未结 2 1855
悲哀的现实
悲哀的现实 2020-12-18 09:00

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

2条回答
  •  执念已碎
    2020-12-18 09:24

    You can mark variables as "non-trainable" on definition:

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

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

    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.

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

提交回复
热议问题