Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between tf.initialize_all_variables() and tf.global_variables_initializer()

Tags:

tensorflow

On Tensorflow official website, it gives explantions of the tf.initialize_all_variables() and tf.global_variables_initializer() functions as follow

tf.initialize_all_variables():

Returns an op that initializes all variables.

tf.global_variables_initializer():

Adds an op to initialize all variables in the model

It seems like both can be used to initialize all variables in graphs. Can we use these two functions exchangbly? If not, what would be the differences?

like image 238
GabrielChu Avatar asked Jan 03 '17 08:01

GabrielChu


2 Answers

Unfortunately, you forgot to read an important line in the documentation of tf.initialize_all_variables.

THIS FUNCTION IS DEPRECATED. It will be removed after 2017-03-02. Instructions for updating: Use tf.global_variables_initializer instead.

like image 68
martianwars Avatar answered Oct 14 '22 12:10

martianwars


The changelog for 0.12 version tells you that both both functions do the same thing because:

tf.initialize_all_variables renamed to tf.global_variables_initializer

and as Martianwars mentioned the documentation for initialize_all_variables tells that:

THIS FUNCTION IS DEPRECATED. It will be removed after 2017-03-02. Instructions for updating: Use tf.global_variables_initializer instead.

If you will call it, you will get a warning as well. So you should always use tf.global_variables_initializer()

like image 38
Salvador Dali Avatar answered Oct 14 '22 13:10

Salvador Dali