TensorFlow 队列关闭后可以重新打开吗? [英] Can a TensorFlow queue be reopened after it is closed?
问题描述
我想将项目入队,关闭队列以确保其他会话将所有剩余项目出队,然后在下一个时期重新打开它.这可能吗?
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)
推荐答案
没有办法重新打开关闭的队列,但是(仅当您使用多个会话时)有一个解决方法::
There's no way to re-open a closed queue, but (only if you are using multiple sessions) there is a workaround::
在
with tf.container(name):
只包装队列的块,其中name
不用于任何其他tf.container()代码>块.
Create your queue in a
with tf.container(name):
block that wraps only the queues, and wherename
is not used for any othertf.container()
blocks.
在你想重新打开队列之前,调用 tf.Session.reset(..., [name])
,其中 name
是您在步骤 1 中创建的容器的名称. 这将导致队列在下次使用时重新创建,并处于打开状态.
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.
这篇关于TensorFlow 队列关闭后可以重新打开吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!