问题
I would like to enqueue items, close the queue to ensure that other sessions will dequeue all remaining items, then reopen it later for the next epoch. Is this possible?
q = tf.FIFOQueue(...)
close_q = q.close()
reopen_q = #???
with tf.Session([...]) as sess:
[...]
sess.run(close_q)
[...]
sess.run(reopen_q)
回答1:
There's no way to re-open a closed queue, but (only if you are using multiple sessions) there is a workaround::
Create your queue in a with tf.container(name): block that wraps only the queues, and where
nameis not used for any othertf.container()blocks.Before you want to reopen the queue, call tf.Session.reset(..., [name]), where
nameis the name of the container you created in step 1. This will cause the queue to be recreated on its next use, and it will be in the opened state.
来源:https://stackoverflow.com/questions/39204335/can-a-tensorflow-queue-be-reopened-after-it-is-closed