4

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

nbro
  • 15,395
  • 32
  • 113
  • 196
cerebrou
  • 5,353
  • 15
  • 48
  • 80

2 Answers2

7

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]).

Eric Platon
  • 9,819
  • 6
  • 41
  • 48
6

You can create non-trainable variables in two different ways:

There is no easy way to change the variable from trainable to non-trainable and otherwise. Also there is no easy way to check whether the variable is trainable (you need to check whether the name of your variable is in the list of tf.trainable_variables()

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
  • I am loading a pre-trained graph from "object detection zoo" but when I run tf.trainable_variables() I get an empty list - what does this mean? what do i do wrong? – Jenny Apr 15 '18 at 11:54
  • @Jenny Did you figure out why there are no trainable variables in the object detection zoo models ? – lamo_738 Jun 11 '19 at 15:27