What is the purpose of tf.global_variables_initializer?

后端 未结 1 1898
一个人的身影
一个人的身影 2020-12-23 13:54

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

Returns an

相关标签:
1条回答
  • 2020-12-23 14:34

    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.

    0 讨论(0)
提交回复
热议问题