What is the purpose of tf.global_variables_initializer?

TensorflowDeep Learning

Tensorflow Problem Overview


I would like to understand what tf.global_variables_initializer does in a bit more detail. A sparse description is given here:

> Returns an Op that initializes global variables.

But that doesn't really help me. I know that the op is necessary to initialize the graph, but what does that actually mean? Is this the step where the graph is complied?

Tensorflow Solutions


Solution 1 - Tensorflow

A more complete description is given here.

Only after running tf.global_variables_initializer() in a session will your variables hold the values you told them to hold when you declare them (tf.Variable(tf.zeros(...)), tf.Variable(tf.random_normal(...)),...).

From the TF doc :

> Calling tf.Variable() adds several ops to the graph: > > * A variable op that holds the variable value. > * An initializer op that sets the variable to its initial value. This is actually a tf.assign op. > * The ops for the initial value, such as the zeros op for the biases variable in the example are also added to the graph.

And also:

> Variable initializers must be run explicitly before other ops in your > model can be run. The easiest way to do that is to add an op that runs > all the variable initializers, and run that op before using the model.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionToke FaurbyView Question on Stackoverflow
Solution 1 - TensorflowFlorentin HenneckerView Answer on Stackoverflow