What are the `'UnreadVariable'` in Tensorflow 2.0?

Viewed 1913

In Tensorflow 2.0, some variables can be described as 'UnreadVariable'

For ex:

b = tf.Variable([4,5], name="test")
print(b.assign([7, 9]))
# Will print
# <tf.Variable 'UnreadVariable' shape=(2,) dtype=int32, numpy=array([7, 9], dtype=int32)>

What does it mean?

1 Answers

UnreadVariable basically Represents a future for a read of a variable. Pretends to be the tensor if anyone looks.

This is because of the eager execution enabled during assign operation.

TensorFlow's eager execution is an imperative programming environment that evaluates operations immediately, without building graphs: operations return concrete values instead of constructing a computational graph to run later.

In Tensorflow 2.0 eager execution is enabled by default. So the operation which you are performing does it without constructing a graph.

Anyways if you want you can change the type to AssignVariableOp by disabling eager execution as follows.

import tensorflow as tf
tf.compat.v1.disable_eager_execution()

b = tf.Variable([4,5], name="test")
print(b.assign([7, 9]))

Returns:  

<tf.Variable 'AssignVariableOp' shape=(2,) dtype=int32>
Related