如何在张量流中处理不同的队列批量大小和馈送值批量大小?
How to handle different queue batch size and feed value batch size in tensorflow?
我的代码曾经在 tensorflow 0.6 上工作,但它不再在最新的 tensorflow 上工作。
我想每隔几次训练迭代就执行一次推理。我的训练数据来自队列,我的推理数据来自 feed_dict。训练批次大小为 128,而推理批次大小为 1。我应该怎么做才能使网络接受两种不同的批次大小?
batch_size = 128
x_batch = tf.placeholder("float", [None, 100])
q = tf.FIFOQueue(10, [tf.float32], shapes=[[batch_size, 100]])
enqueue_op = q.enqueue([x_batch])
# during training
x = q.dequeue() # dequeue operation
# network definition, takes x as input, and output y
......
# during inference
x_array_of_batch_size_1 = .. # a 1x100 numpy array
sess.run([y], feed_dict={x: x_array_of_batch_size_1))
我收到以下错误:
ValueError: Cannot feed value of shape (1, 100) for Tensor u'fifo_queue_Dequeue:0', which has shape '(128, 100)'
我们最近添加了此检查以防止错误(并添加了一些优化机会)。您可以通过更改 x
的声明以使用新的 tf.placeholder_with_default()
op:
让您的程序再次运行
x = tf.placeholder_with_default(q.dequeue(), shape=[None, 100])
我的代码曾经在 tensorflow 0.6 上工作,但它不再在最新的 tensorflow 上工作。
我想每隔几次训练迭代就执行一次推理。我的训练数据来自队列,我的推理数据来自 feed_dict。训练批次大小为 128,而推理批次大小为 1。我应该怎么做才能使网络接受两种不同的批次大小?
batch_size = 128
x_batch = tf.placeholder("float", [None, 100])
q = tf.FIFOQueue(10, [tf.float32], shapes=[[batch_size, 100]])
enqueue_op = q.enqueue([x_batch])
# during training
x = q.dequeue() # dequeue operation
# network definition, takes x as input, and output y
......
# during inference
x_array_of_batch_size_1 = .. # a 1x100 numpy array
sess.run([y], feed_dict={x: x_array_of_batch_size_1))
我收到以下错误:
ValueError: Cannot feed value of shape (1, 100) for Tensor u'fifo_queue_Dequeue:0', which has shape '(128, 100)'
我们最近添加了此检查以防止错误(并添加了一些优化机会)。您可以通过更改 x
的声明以使用新的 tf.placeholder_with_default()
op:
x = tf.placeholder_with_default(q.dequeue(), shape=[None, 100])