【问题标题】:What is queue.dequeue_up_to() method in tensorflow.data_flow_ops used for?tensorflow.data_flow_ops 中的 queue.dequeue_up_to() 方法是做什么用的?
【发布时间】:2018-06-14 18:08:11
【问题描述】:

我真的很困惑这种方法,尤其是当我发现这个令人费解的陈述时:

output.set_shape(tensor_shape.TensorShape([None]).concatenate(shape))

这里有一些cmets作为方法的描述:

This operation concatenates queue-element component tensors along
the 0th dimension to make a single component tensor. If the queue
has not been closed, all of the components in the dequeued tuple
will have size `n` in the 0th dimension.

在形状的第 0 维指定 None 太奇怪了(我想它可能是 n?),这似乎与描述中的 size 'n' 相矛盾。这导致我的程序出现形状错误,我无法理解原因,尽管我已经找到了它的位置。

你能告诉我为什么在这里使用TensorShape([None])吗?

【问题讨论】:

标签: python tensorflow machine-learning deep-learning computer-vision


【解决方案1】:

QueueBase.dequeue_up_to(n) 方法从队列中返回一批最多(“最多”)n 元素。相比之下,QueueBase.dequeue_many(n) 方法从队列中返回一批完全 n 元素。

在队列为closed 之前,这两个操作的行为相同。此后,不能再向队列中添加元素,因此这些操作将耗尽剩余元素。如果剩余元素的数量 (num_remaining) 不是 n 的精确倍数,QueueBase.dequeue_up_to(n) 将返回最后一批更小的 num_remaining % n 元素。相比之下,QueueBase.dequeue_many(n) 将不会返回最后几个元素,因为它无法生成一批正好是 n 元素。

由于QueueBase.dequeue_up_to(n) 可以返回静态未知的不同大小的批次(即nnum_remaining % n)(因为num_remaining 取决于运行时发生的入队操作的数量),第一个其返回值的维度是Dimension(None)Dimension(None) 通常用于指示可以在执行之间变化的形状。

【讨论】:

    猜你喜欢
    • 2011-01-18
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 2023-04-10
    • 1970-01-01
    相关资源
    最近更新 更多