TensorFlow tutorials on tensorflow.org show the way to use tf.GradientTape
as:
x = tf.convert_to_tensor([1,2,3]);
with tf.GradientTape() as t:
t.watch(x);
I wonder why I can't move the t.watch(x)
outside of with
block like this:
x = tf.convert_to_tensor([1,2,3]);
t = tf.GradientTape();
t.watch(x); #ERROR
The error is:
tape.py (59):
pywrap_tensorflow.TFE_Py_TapeWatch(tape._tape, tensor)
AttributeError: 'NoneType' object has no attribute '_tape'