python – Tensorflow:有效地将数据移动/放入GPU

所以我正在阅读有关从CPU移动数据的更多信息 – > Tensorflow中的GPU,我看到feed_dict仍然很慢:
https://github.com/tensorflow/tensorflow/issues/2919

我看到的将Python变量“移动”到GPU的直接选项是:

#1. Tensorflow constant
a = tf.constant(data, name='a')

#2. Tensorflow Variable
b = tf.Variable(data, name='b')

#3. Tensorflow placeholder
c = tf.placeholder(dtype=dtype, shape=[x,y,z ...], name='c')

选项#1和#2对于非常大的数据集变量是不实用的(因为您实际上是将数据预加载到内存中),因为我们将快速超过2GB图形限制.目前这使得#3成为将大型Python变量带入Tensorflow的更好选择,但随后你被迫使用feed_dict.

除了#1,#2和#3之外,还有其他选择将Python变量移动到GPU吗?我指的是……

with tf.device('/gpu:0'):
    # create tensorflow object(s), whether it's tf.Variable, tf.constant, etc

如果我理解正确,我们可以使用输入管道功能来解决这个问题吗?我指的是这两个:

> https://datascience.stackexchange.com/questions/17559/input-pipeline-for-tensorflow-on-gpu
> https://stackoverflow.com/a/38956678/7093236

我有什么办法可以进一步提高Tensorflow方面的速度吗?

解决方法:

最好的方法是使用tensorflow Queue来加速数据传输.

即使您没有标签文件,也可以执行以下步骤

# data_files and labels_files are list, this may be some data files path, and labels values.
filename_queue = tf.train.slice_input_producer([data_files, label_files], shuffle=True)   
# filename_queue = tf.train.slice_input_producer(data_files, shuffle=True)       
# Some steps to decode the files and process
 ......
data, label = some_function(filename_queue)

# Define batch size and get batch for processing
image_batch, label_batch = tf.train.shuffle_batch([data, label], batch_size=batch_size, num_threads=num_threads)                                                                                                       

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐