Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between tf.initialize_all_variables() and tf.initialize_local_variables()?

Tags:

tensorflow

I am reviewing the code in this example: fully_connected_reader.py

I am confused with Line 147 and 148:

init_op = tf.group(tf.initialize_all_variables(),
                   tf.initialize_local_variables())

I don't know which variables are all variables and which are local variables. Any ideas?

like image 421
C. Wang Avatar asked Oct 24 '16 13:10

C. Wang


People also ask

What is tf global_variables_initializer ()?

global_variables_initializer() in a session will your variables hold the values you told them to hold when you declare them ( tf. Variable(tf. zeros(...)) , tf.

Is tf variable trainable?

New!

How do you initialize a parameter in TensorFlow?

To initialize a new variable from the value of another variable use the other variable's initialized_value() property. You can use the initialized value directly as the initial value for the new variable, or you can use it as any other tensor to compute a value for the new variable.

How do you initialize a TensorFlow variable in a matrix?

First, remember that you can use the TensorFlow eye functionality to easily create a square identity matrix. We create a 5x5 identity matrix with a data type of float32 and assign it to the Python variable identity matrix. So we used tf. eye, give it a size of 5, and the data type is float32.


1 Answers

tf.initialize_all_variables() is a shortcut to tf.initialize_variables(tf.all_variables()), tf.initialize_local_variables() is a shortcut to tf.initialize_variables(tf.local_variables()), which initializes variables in GraphKeys.VARIABLES and GraphKeys.LOCAL_VARIABLE collections, respectively.

Variables in GraphKeys.LOCAL_VARIABLES collection are variables that are added to the graph, but not saved or restored (source).

tf.Variable() by default adds a new variable to GraphKeys.VARIABLE collection, which can be controlled by collections= argument.

like image 51
M U Avatar answered Sep 22 '22 11:09

M U