如何将所有批处理数据加载到Keras(Theano后端)的GPU内存中? [英] How can you load all batch data into GPU memory in Keras (Theano backend)?

查看:328
本文介绍了如何将所有批处理数据加载到Keras(Theano后端)的GPU内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Keras逐批将数据加载到GPU上(作者此处).

Keras loads data onto the GPU batch-by-batch (noted by the author here).

对于小型数据集,这是非常低效的.有没有办法修改Keras或直接调用Theano函数(在Keras中定义了模型之后),以允许将所有批次提前移动到GPU,并使用GPU内存中已经存在的批次进行训练?

For small datasets, this is very inefficient. Is there a way to modify Keras or call Theano functions directly (after defining the model in Keras) to allow all batches to be moved to the GPU up front, and training done using the batches already in GPU memory?

(有人在Keras列表上提出了相同的问题几周前,但到目前为止没有任何回复.)

(Someone asked the same question on the Keras list a few weeks ago, but has no replies so far.)

推荐答案

只需将您的数据作为不可训练的嵌入矩阵(带有自定义初始化程序的嵌入层)硬连接到模型中即可.然后,将一堆索引传递给model.fit方法,而不是训练数据.

Just hard-wire your data into the model as a non-trainable embedding matrix (Embedding layer with your custom initializer). Then instead of the training data you pass a bunch of indices to the model.fit method.

这篇关于如何将所有批处理数据加载到Keras(Theano后端)的GPU内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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