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.