user2069136
user2069136

Reputation: 289

Saving Keras model - UserWarning: Layer XX was passed non-serializable keyword arguments

I've just trained and finished my first sequence to sequence model with Keras and now wants to save it so I later can load the model and use it (without having to train it every time). When saving it I do:

model.save_weights('models/model_weights.h5')
with open('models/model_architecture.json', 'w') as f:
    f.write(model.to_json())

But, doing this produces a bunch of user warnings (more or less one for every layer) of the type:

path/to/site-packages/keras/engine/topology.py:2379: UserWarning: Layer lstm_15 was 
passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 's0_7:0' 
shape=(?, 64) dtype=float32>, <tf.Tensor 'c0_7:0' shape=(?, 64) dtype=float32>]}. 
They will not be included in the serialized model (and thus will be missing at 
deserialization time).
str(node.arguments) + '. They will not be included '

Even though just warnings this really puts off the model and accuracy after loading the model.

Everything works perfectly fine right after training (making good predictions, etc.), it's only the saving part that fails. What can I do about this? Anyone else experienced the same thing and solved it somehow? Is there a workaround? May it be any issues with the names I have given the different layers?

Upvotes: 2

Views: 1355

Answers (1)

Daniel M&#246;ller
Daniel M&#246;ller

Reputation: 86600

You can save the model "code", maybe a .py file just to create the model exactly as it were.

Then you load weights: model.load_weights('models/model_weights.h5').

Upvotes: 2

Related Questions