User9362
User9362

Reputation: 45

What the difference between tf.Graph.add_to_collections and tf.add_to_collections?

In my model I used to add the variable to collections as tf.add_to_collections(['xxx', 'yyy'], val) but now with updated version of tensorflow I see another method tf.Graph.add_to_collections, Whats the difference b/w them ?

Upvotes: 2

Views: 360

Answers (1)

javidcf
javidcf

Reputation: 59701

If you look at the implementation of tf.add_to_collections, you will see that it just does:

get_default_graph().add_to_collections(names, value)

So it is exactly the same as calling tf.get_default_graph().add_to_collections. The collections are really associated with a graph, in most cases you are just interested in one graph, which is the default one, but sometimes you may want to manage different tf.Graph objects manually, and in that case you may prefer to use the methods of the graph class instead of relying on which one is the default one. If you are only working with one graph, though, tf.add_to_collections is usually more convenient and readable.

Upvotes: 3

Related Questions