gpt4 book ai didi

tensorflow - tf.global_variables_initializer 的目的是什么?

转载 作者:行者123 更新时间:2023-12-01 22:05:46 26 4
gpt4 key购买 nike

我想更详细地了解 tf.global_variables_initializer 的作用。一个sparse description is given here :

Returns an Op that initializes global variables.

但这并没有真正帮助我。我知道该操作对于初始化图形是必要的,但这实际上意味着什么?这是编译图表的步骤吗?

最佳答案

给出了更完整的描述here

只有在 session 中运行 tf.global_variables_initializer() 后,您的变量才会保存您在声明它们时告诉它们保存的值 (tf.Variable(tf.zeros(.. .)), tf.Variable(tf.random_normal(...)),...).

来自 TF 文档:

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.

还有:

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.

关于tensorflow - tf.global_variables_initializer 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44433438/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com