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:
tf.global_variables_initializer().run()
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 (i.e. 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).