Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all collections in Tensorflow?

I'm trying to get a list of all existing collections in a Tensorflow model. Regarding collections automatically created by Tensorflow I can iterate over all keys in GraphKeys and can query each key e.g.

 tf.get_collection(tf.GraphKeys.TRAIN_OP)

Is there a way to get a complete list of all collections, including user created collections.

like image 904
bluenote10 Avatar asked Apr 18 '17 12:04

bluenote10


People also ask

How do I get all the variables in Tensorflow?

If you want to get all the trainable variables, you can get all of them inside of a list using tf. trainable_variables method.

What is collection in Tensorflow?

Remember that under the hood, Tensorflow is a system for specifying and then executing computational data flow graphs. The graph collections are used as part of keeping track of the constructed graphs and how they must be executed. For example, when you create certain kinds of ops, such as tf. train.


1 Answers

Tensorflow stores the collections as a private dictionary _collections in class Graph. This class also exposes a function to retrieve all collection keys/names:

tf.get_default_graph().get_all_collection_keys()
like image 85
bluenote10 Avatar answered Oct 22 '22 09:10

bluenote10