tensorflow将训练数据存储在GPU内存中 [英] tensorflow store training data on GPU memory

查看:729
本文介绍了tensorflow将训练数据存储在GPU内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对tensorflow很陌生.我曾经使用theano进行深度学习开发.我注意到这两者之间的区别,那就是可以存储输入数据.

I am pretty new to tensorflow. I used to use theano for deep learning development. I notice a difference between these two, that is where input data can be stored.

在Theano中,它支持共享变量以将输入数据存储在GPU内存中,以减少CPU和GPU之间的数据传输.

In Theano, it supports shared variable to store input data on GPU memory to reduce the data transfer between CPU and GPU.

在tensorflow中,我们需要将数据馈入占位符,并且数据可以来自CPU内存或文件.

In tensorflow, we need to feed data into placeholder, and the data can come from CPU memory or files.

我的问题是:是否可以将输入数据存储在GPU内存中以进行张量流?还是已经以某种神奇的方式做到了?

My question is: is it possible to store input data on GPU memory for tensorflow? or does it already do it in some magic way?

谢谢.

推荐答案

如果您的数据适合GPU,则可以通过以下方式将其加载到GPU上的常量中: numpy数组:

If your data fits on the GPU, you can load it into a constant on GPU from e.g. a numpy array:

with tf.device('/gpu:0'):
  tensorflow_dataset = tf.constant(numpy_dataset)

提取小批处理的一种方法是在每个步骤中切片该数组,而不是使用 tf.slice :

One way to extract minibatches would be to slice that array at each step instead of feeding it using tf.slice:

  batch = tf.slice(tensorflow_dataset, [index, 0], [batch_size, -1])

围绕该主题有很多可能的变体,包括使用队列将数据动态预取到GPU.

There are many possible variations around that theme, including using queues to prefetch the data to GPU dynamically.

这篇关于tensorflow将训练数据存储在GPU内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆