了解 tensorflow 队列和 cpu <-> gpu 传输

Understanding tensorflow queues and cpu <-> gpu transfer

读完这个 github 问题后,我觉得我对队列的理解遗漏了一些东西:

https://github.com/tensorflow/tensorflow/issues/3009

我认为当将数据加载到队列中时,它会在计算最后一批时预先传输到 GPU,因此几乎没有带宽瓶颈,假设计算时间比加载时间长下一批。

但是上面的 link 表明从队列到图形中有一个昂贵的副本 (numpy <-> TF) 并且将文件加载到图形中并在那里进行预处理会更快.但这对我来说没有意义。为什么我从文件加载 256x256 图像与原始 numpy 数组有关系?如果有的话,我会认为 numpy 版本更快。我错过了什么?

没有 GPU 队列的实现,所以它只是将内容加载到主内存中,没有异步预取到 GPU 中。您可以使用固定到 gpu:0

的变量来制作类似于基于 GPU 的队列的东西

documentation 表明可以将队列固定到设备:

N.B. Queue methods (such as q.enqueue(...)) must run on the same device as the queue. Incompatible device placement directives will be ignored when creating these operations.

但以上内容对我来说意味着任何试图入队的变量都应该已经在 GPU 上了。

This 评论表明可以使用 tf.identity 执行预取。