简体   繁体   中英

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.

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. 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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