Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you load all batch data into GPU memory in Keras (Theano backend)?

Tags:

keras

theano

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

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?

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

like image 730
capitalistcuttle Avatar asked Aug 14 '16 16:08

capitalistcuttle


1 Answers

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.

like image 175
Marek Avatar answered Sep 24 '22 23:09

Marek