简体   繁体   English

在TensorFlow图中初始化变量

[英]initialize variables in TensorFlow graph

I'm starting an interactive session in TensorFlow, and after defining all the variables I'm starting to train end evaluate the network. 我正在TensorFlow中开始一个交互式会话,并在定义了所有变量之后开始训练最终评估网络。

What is the difference between those two commands: 这两个命令有什么区别:

  1. tf.global_variables_initializer().run()
  2. sess.run(tf.initialize_all_variables())

till today I used the second command, but recently I noticed the first command. 直到今天,我仍然使用第二个命令,但是最近我注意到了第一个命令。

Thanks :) 谢谢 :)

The two statements are equivalent: both tf.global_variables_initializer() and tf.initialize_all_variables() return a tf.Operation that, when run, will initialize the global variables in a model. 这两个语句是等效的: tf.global_variables_initializer()tf.initialize_all_variables()返回一个tf.Operation在运行时将初始化模型中的全局变量。 Passing an operation to sess.run() or calling operation.run() are equivalent when you have created a tf.InteractiveSession , or are in a with tf.Session(): block. 创建tf.InteractiveSessionwith tf.Session(): tf.InteractiveSession ,将操作传递给sess.run()或调用operation.run()是等效的。

The tf.initialize_all_variables() function has been deprecated (and will be removed from TensorFlow 1.0) because its name is confusing: it does not initialize all variables (ie local variables must be initialized separately, using tf.local_variables_initializer() ), and it doesn't immediately initialize the variables (instead it returns an operation that you have to run yourself). tf.initialize_all_variables()函数已被弃用(将从TensorFlow 1.0中删除),因为其名称令人困惑:它不会初始化所有变量(即,必须使用tf.local_variables_initializer()单独初始化局部变量),并且它不会立即初始化变量(而是会返回您必须自己运行的操作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM