seq2seq
seq2seq copied to clipboard
Unable to save and load model
I am trying to save and load AttentionSeq2Seq model by calling Model.to_json(), Model.save_weights(), Model.model_from_json() and Model.load_weights() without success. How can I fix this problem?
I have similar problem. When I tried to load the trained Seq2seq model with model.load_weights(...), it raised a "Unrecognized model" error. @galaxyh do you have the same error?
I'm using a SimpleSeq2seq and can successfully save models but doesn't seem to be able to load them. Loading the saved Simple model throws the exception "Invalid layer: SimpleSeq2seq". Anybody got any clues how this could be resolved?
Have you tried this? https://github.com/farizrahman4u/seq2seq/issues/24
As mentioned in #24 , I tried to pickle my model:
model = Seq2Seq()
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
with open(path, 'w') as f:
pkl.dump(model, f)
but I get the following error:
pickle.PicklingError: Can't pickle <function step at 0x7f56d52a10c8>: it's not found as recurrentshop.cells.step
How do you solve this? Thanks
For me saving the model works when I use dill instead of cpickle.
import dill as pickle
model=...
pickle.dump(model,open("model.p","wb"),protocol=2)
with open("model.p","rb")as m:
model =pickle.load(m)
pickle
or dill
doesn't work in my case.
but this works:
# saving
model = Seq2Seq(input_shape... ....)
model.fit(...)
model.save_weights('model.h5')
# loading
#### model = model_from_json() # <---- doesn't work!!
model = Seq2Seq(input_shape... ....) # Instantiate a model object with the same configuration as above before loading weights
model.load_weights('model.h5')
For me, it raise 'ValueError: Unknown layer: _OptionalInputPlaceHolder' when I use model.save() and load_model(), and model_from_json() too, cPickle doen't work either, @naotokui 's way works, but is there a better solution now?