【问题标题】:How to handle different queue batch size and feed value batch size in tensorflow?如何在 tensorflow 中处理不同的队列批量大小和提要值批量大小?
【发布时间】:2016-03-19 18:52:49
【问题描述】:

我的代码曾经在 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)'

【问题讨论】:

    标签: python tensorflow training-data prefetch


    【解决方案1】:

    我们最近添加了此检查以防止错误(并添加了一些优化机会)。您可以通过将x 的声明更改为使用新的tf.placeholder_with_default() 操作来使您的程序再次运行:

    x = tf.placeholder_with_default(q.dequeue(), shape=[None, 100])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-21
      • 2021-10-25
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      相关资源
      最近更新 更多