Can a TensorFlow queue be reopened after it is closed?

↘锁芯ラ 提交于 2019-12-04 11:35:35

问题


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::

  1. Create your queue in a with tf.container(name): block that wraps only the queues, and where name is not used for any other tf.container() blocks.

  2. Before you want to reopen the queue, call tf.Session.reset(..., [name]), where name is 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!