Graph collections

tf.add_to_collection(name, value)

Wrapper for Graph.add_to_collection() using the default graph.

See Graph.add_to_collection() for more details.

Args:
  • name: The key for the collection. For example, the GraphKeys class contains many standard names for collections.
  • value: The value to add to the collection.

tf.get_collection(key, scope=None)

Wrapper for Graph.get_collection() using the default graph.

See Graph.get_collection() for more details.

Args:
  • key: The key for the collection. For example, the GraphKeys class contains many standard names for collections.
  • scope: (Optional.) If supplied, the resulting list is filtered to include only items whose name attribute matches using re.match. Items without a name attribute are never returned if a scope is supplied and the choice or re.match means that a scope without special tokens filters by prefix.
Returns:

The list of values in the collection with the given name, or an empty list if no value has been added to that collection. The list contains the values in the order under which they were collected.


tf.get_collection_ref(key)

Wrapper for Graph.get_collection_ref() using the default graph.

See Graph.get_collection_ref() for more details.

Args:
  • key: The key for the collection. For example, the GraphKeys class contains many standard names for collections.
Returns:

The list of values in the collection with the given name, or an empty list if no value has been added to that collection. Note that this returns the collection list itself, which can be modified in place to change the collection.


class tf.GraphKeys

Standard names to use for graph collections.

The standard library uses various well-known names to collect and retrieve values associated with a graph. For example, the tf.Optimizer subclasses default to optimizing the variables collected under tf.GraphKeys.TRAINABLE_VARIABLES if none is specified, but it is also possible to pass an explicit list of variables.

The following standard keys are defined:

  • VARIABLES: the Variable objects that comprise a model, and must be saved and restored together. See tf.all_variables() for more details.
  • TRAINABLE_VARIABLES: the subset of Variable objects that will be trained by an optimizer. See tf.trainable_variables() for more details.
  • SUMMARIES: the summary Tensor objects that have been created in the graph. See tf.merge_all_summaries() for more details.
  • QUEUE_RUNNERS: the QueueRunner objects that are used to produce input for a computation. See tf.start_queue_runners() for more details.
  • MOVING_AVERAGE_VARIABLES: the subset of Variable objects that will also keep moving averages. See tf.moving_average_variables() for more details.
  • REGULARIZATION_LOSSES: regularization losses collected during graph construction.
  • WEIGHTS: weights inside neural network layers
  • BIASES: biases inside neural network layers
  • ACTIVATIONS: activations of neural network layers