I implement a callback , override on_epoch_end, when save the model and decode_model ,there is a warning mag:
UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [
str(node.arguments) + '. They will not be included '
it means some weight can't save to disk, when inference
How can I save the model , encoder_model, decoder_model for offline test & application
save the model:
print('save s2s h5')
model.save('s2s.h5.'+str(epoch))
model_json = model.to_json()
with open("model.json."+str(epoch), "w") as json_file:
print('save s2s json')
json_file.write(model_json)
encoder_model = Model(encoder_inputs, encoder_states)
decoder_state_input_h = Input(shape=(latent_dim,))
decoder_state_input_c = Input(shape=(latent_dim,))
decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]
decoder_outputs, state_h, state_c = decoder_lstm(decoder_inputs, initial_state=decoder_states_inputs)
decoder_states = [state_h, state_c]
decoder_outputs = decoder_dense(decoder_outputs)
decoder_model = Model([decoder_inputs] + decoder_states_inputs,[decoder_outputs] + decoder_states)
#save encoder model
print('save encoder h5')
encoder_model.save('encoder_model.h5.'+str(epoch))
encoder_model_json = encoder_model.to_json()
with open("encoder_model.json."+str(epoch), "w") as json_file:
print('save encoder json')
json_file.write(encoder_model_json)
#save decoder model
print('save decoder h5')
decoder_model.save('decoder_model.h5.'+str(epoch))
decoder_model_json = decoder_model.to_json()
with open("decoder_model.json."+str(epoch), "w") as json_file:
print('save decoder json')
json_file.write(decoder_model_json)
I get the exact same warning using the code online for seq2seq.
Without touching any line of code I train on the given dataset and it gives reasonable results. The warning appears when I try to save the model.
If I load the saved model everything runs but I get completely wrong predictions.
you can refer to the example code
I got the same problem. Anyone has an idea?
the example code will show you how to load