seq2seq icon indicating copy to clipboard operation
seq2seq copied to clipboard

Unable to save and load model

Open galaxyh opened this issue 8 years ago • 7 comments

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?

galaxyh avatar Mar 26 '16 08:03 galaxyh

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?

iamyuanchung avatar Apr 12 '16 10:04 iamyuanchung

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?

chm90 avatar Jul 06 '16 15:07 chm90

Have you tried this? https://github.com/farizrahman4u/seq2seq/issues/24

iamyuanchung avatar Jul 06 '16 15:07 iamyuanchung

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

nicoayroles avatar Oct 21 '16 11:10 nicoayroles

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)

smodlich avatar Mar 05 '17 18:03 smodlich

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')

naotokui avatar Jun 08 '17 09:06 naotokui

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?

CaseyKay avatar Aug 28 '17 10:08 CaseyKay