jeudi 23 mai 2019

Understanding Tensorflow initialize_all_variables

Why the following code prints 4 different numbers?

# Random seed for reproducibility
tf.set_random_seed(1234)
# Random variable
foo = tf.Variable(tf.random_uniform(shape=(1,1)),name = 'foo')
# Operation to initialize variables
init = tf.initialize_all_variables()
# Run Operations in session
with tf.Session() as sess:
    # Loop 
    for i in range(1,5):
        # Initialize variables
        sess.run(init)
        # Print foo value
        print(sess.run(foo))

I was expecting it to print the same random value 4 times since I am running the initializer at the start of each of the four iterations.




Aucun commentaire:

Enregistrer un commentaire