How do I get the current value of a Variable?

The only way to get the value of the variable is by running it in a session. In the FAQ it is written that:

A Tensor object is a symbolic handle to the result of an operation,
but does not actually hold the values of the operation’s output.

So TF equivalent would be:

import tensorflow as tf

x = tf.Variable([1.0, 2.0])

init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)
    v = sess.run(x)
    print(v)  # will show you your variable.

The part with init = global_variables_initializer() is important and should be done in order to initialize variables.

Also, take a look at InteractiveSession if you work in IPython.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)