Supervisor循环和队列运行器

时间:2016-10-16 19:57:03

标签: tensorflow

我尝试使用外部线程循环填充队列。以下是我尝试做的事情的片段:

class Provider:

    def __init__(self):
        self.count = 0

    def __call__(self, *args, **kwargs):
        self.count += 1
        print("call provider", self.count)

d = tf.placeholder(tf.int32, shape=[2, 1])
queue = tf.FIFOQueue(3*2*10, dtypes=[tf.int32], shapes=[[1]])
enqueue_op = queue.enqueue_many(d)
#tf.train.queue_runner.add_queue_runner(tf.train.QueueRunner(queue, [enqueue_op]))

provider = Provider()


sv = tf.train.Supervisor(logdir='/tmp/test_provider')

with sv.managed_session() as sess:
    sv.loop(1, provider)
    sv.start_queue_runners(sess)

    for i in range(100):
        print("run", i)
        time.sleep(20)

此代码不完整,但我期望的是以下输出

call provider 1
run 0
call provider 2
call provider 3
call provider 4
call provider 5
call provider 6
call provider 7
call provider 8
call provider 9
call provider 10
call provider 11
call provider 12
call provider 13
call provider 14
call provider 15
call provider 16
call provider 17
call provider 18
call provider 19
call provider 20
call provider 21
run 1
call provider 22
call provider 23
call provider 24
call provider 25

只要行

即可
#tf.train.queue_runner.add_queue_runner(tf.train.QueueRunner(queue, [enqueue_op]))

被评论。一旦我解除它,它就不再起作用了。我的下一步是将队列放在我的可调用对象中以填充它。关于它为什么会破裂的任何想法?

0 个答案:

没有答案