1

我正在尝试在训练过程中重置并重新输入 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")
4

0 回答 0