(tensorflow version: '0.12.head')
The documentation of TensorArray.close
says that it close the current TensorArray. What does it mean for the status of TensorArray
? I try the following code
import tensorflow as tf
sess = tf.InteractiveSession()
a1 = tf.TensorArray(tf.int32, 2)
a1.close().run()
a2 = a1.write(0, 0)
a2.close().run()
print(a2.read(0).eval())
And there are no errors. What is the usage of close
?
Learning-to-learn includes TensorArray.close
in the reset operations of the network. I can't figure out what the comment Empty array as part of the reset process means.
Update
For examples,
import tensorflow as tf
sess = tf.InteractiveSession()
N = 3
def cond(i, arr):
return i < N
def body(i, arr):
arr = arr.write(i, i)
i += 1
return i, arr
arr = tf.TensorArray(tf.int32, N)
_, result_arr = tf.while_loop(cond, body, [0, arr])
reset = arr.close() # corresponds to https://github.com/deepmind/learning-to-learn/blob/6ee52539e83d0452051fe08699b5d8436442f803/meta.py#L370
NUM_EPOCHS = 3
for _ in range(NUM_EPOCHS):
reset.run() # corresponds to https://github.com/deepmind/learning-to-learn/blob/6ee52539e83d0452051fe08699b5d8436442f803/util.py#L32
print(result_arr.stack().eval())
Why arr.close()
doesn't make the while loop fail? What are the advantages of calling arr.close() at the beginning of each epoch?
The
TensorArray
that is being closed in the Learning-to-learn example is not the originalTensorArray
that's being passed to the while-loop.Any subsequent calls to
fx_array.close()
from here close the new array returned by the while-loop and not the original array passed to the loop in the first iteration.If you want to see how
close
behaves as expected then run:This will fail with
TensorArray has already been closed.
since theloss
op tries to runpack()
on the closed array.