Skip to content Skip to sidebar Skip to footer

Keras Predict Memory Swap Increase Indefinitely

I implemented a classification program using keras. I have a big set of images and I would like to predict each image using a for loop. However, every time a new image is computed

Solution 1:

If you are using TensorFlow backend you will be building a model for each img in the for loop. TensorFlow just keeps appending graph onto graph etc. which means memory just rises. This is a well known occurrence and must be dealt with during hyperparameter optimization when you will be building many models, but also here.

from keras import backend as K

and put this at the end of predict():

K.clear_session()

Or you can just build one model and feed that as input to the predict function so you are not building a new one each time.

Post a Comment for "Keras Predict Memory Swap Increase Indefinitely"