3

It seems Keras is slower with each load_model call when running multiple of those calls. See related question:

Extremely slow model load with keras

It can be reproduced with a simple code snippet:

from keras.models import Sequential
from keras.models import load_model
from keras.layers import Dense


model = Sequential()

model.add(Dense(units=64, activation='relu', input_dim=100))
model.add(Dense(units=10, activation='softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='sgd',
              metrics=['accuracy'])

model.save('asdf.h5')
del model

for i in range(100):
    t0 = time.time()
    load_model('asdf.h5')
    print('%.2f' % (time.time() - t0))

Why?

I am not interested in knowing how to avoid it, just why it happens.

Peque
  • 13,638
  • 11
  • 69
  • 105
  • Looks like there is a memory leak in how keras uses tensorflow and is a known bug -- https://github.com/keras-team/keras/issues/2102 Oh, looks like a fix was implemented `keras.backend.clear_session()` -- https://keras.io/backend/ – Dunes Oct 09 '18 at 16:55

0 Answers0