I am training some model via keras
with tensorflow
backend.
When I call predict right after training on the same object it works fine and gives different values for different inputs. But when I save the model to a file, then load it from another python
session, predict
always returns the same value for different inputs.
I use ModelCheckpoint
for saving the model, then load_model
for loading. I have also tried to save and load architecture separately to a json file with to_json
and model_from_json
functions. Sample code:
Saving part
with open("model.json", "w") as textFile:
print(model.to_json(), file = textFile)
model.fit(X_train, y_train, epochs=iterationCount, batch_size=64, validation_split=0.2, callbacks = [ModelCheckpoint(filepath='model.h5', verbose=0, save_best_only=True)])
Loading part
with open('model.json') as json_file:
model = model_from_json(json_file.read())
model.load_weights('model.h5')
Any ideas to solve this? Is there anything that I am missing?