Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to understand tf.get_collection() in TensorFlow

I am confused by tf.get_collection() form the docs, it says that

Returns a list of values in the collection with the given name.

And an example from the Internet is here

from_vars = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, from_scope)

Is it means that it collects variables from tf.GraphKeys.TRAINABLE_VARIABLES to from_scope?

However, how can I use this function if I want to get variables from another scope? Thank you!

like image 641
GoingMyWay Avatar asked Jun 22 '17 06:06

GoingMyWay


People also ask

What is graph mode in TensorFlow?

TensorFlow uses graphs as the format for saved models when it exports them from Python. Graphs are also easily optimized, allowing the compiler to do transformations like: Statically infer the value of tensors by folding constant nodes in your computation ("constant folding").

What is default graph in TensorFlow?

The TensorFlow Python library has a default graph to which ops constructors add nodes. The default graph is sufficient for many applications. See the Graph class documentation for how to explicitly manage multiple graphs.

How does TF function work?

You can use tf. function to make graphs out of your programs. It is a transformation tool that creates Python-independent dataflow graphs out of your Python code. This will help you create performant and portable models, and it is required to use SavedModel .

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

A collection is nothing but a named set of values.

Every value is a node of the computational graph.

Every node has its name and the name is composed by the concatenation of scopes, / and values, like: preceding/scopes/in/that/way/value

get_collection, without scope allow fetching every value in the collection without applying any filter operation.

When the scope parameter is present, every element of the collection is filtered and its returned only if the name of the node starts with the specified scope.

like image 103
nessuno Avatar answered Oct 14 '22 04:10

nessuno