多次进给Tensorflow FIFOQueue

时间:2017-06-05 05:12:06

标签: tensorflow queue deep-learning tensorflow-gpu

我正在尝试在训练过程中重置并重新喂养FIFIQueue。有可能吗?

我添加了一个代码来执行此操作。此实现能够向训练过程添加新值,但它无法删除旧元素,因此我需要找到一种方法来停止旧的队列运行程序。我尝试了sess.run(qr.close_op)sess.run(qr.cancel_op),但没有成功。

另外,我不想重新创建图表并重用变量。 tf.train.string_input_producer在原始实现中无法满足我的需求。

with tf.Session() as sess:

biases = tf.Variable(tf.zeros([1]), name="biases")
sess.run(tf.global_variables_initializer())
coord = tf.train.Coordinator()
queue = tf.FIFOQueue(capacity=50, dtypes=[tf.float32], shapes=[[]])
numbers = queue.dequeue()
batch_numbers = tf.train.batch([numbers], batch_size=20)
batch_numbers = tf.multiply(batch_numbers, 10.0) + biases # simulate a network operation
#Need to change the content of the queue 10 times
for k in range(10):

    input_numbers = [k*1.0 for i in range(100)]

    queue_op = queue.enqueue_many([input_numbers])

    qr = tf.train.queue_runner.QueueRunner(queue, [queue_op]*5)
    tf.train.queue_runner.add_queue_runner(qr)

    threads = tf.train.start_queue_runners(coord=coord)

    for step in xrange(100):
        if coord.should_stop():
            break
        batch = sess.run([batch_numbers])
        print(batch)
    print("finished that batch")

0 个答案:

没有答案