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

查看:31
本文介绍了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 中,我们需要将数据输入 placeholder,数据可以来自 CPU 内存或文件.

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

我的问题是:是否可以在 GPU 内存上为 tensorflow 存储输入数据?或者它已经以某种神奇的方式做到了?

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天全站免登陆