I'm trying to use theano with cpu-multiprocessing with a neural network library, Keras.
I use device=gpu
flag and load the keras model. Then for extracting features for over a million images, im using multiprocessing pool.
The function looks something like this:
from keras import backend as K
f = K.function([model.layers[0].input, K.learning_phase()], [model.layers[-3].output,])
def feature_gen(flz):
im = imread(flz)
cPickle.dump(f([im, 0])[0][0], open(flz, 'wb'), -1)
pool = mp.Pool(processes=10)
results = [pool.apply_async(feature_gen, args=(f, )) for f in filelist]]
This however starts creating pools in the GPU memory and my code fails with memory error. Is it possible to force multiprocessing to create threads in CPU memory and then use specific parts for feature extraction such as f([im, 0])[0][0]
with GPU?
If not, is there an alternative to do the same thing in parallel in python?