model.save is giving AttributeError: 'NoneType' object has no attribute 'get_config'

2,004 views
Skip to first unread message

Srinivasa Rao

unread,
May 11, 2018, 12:15:51 PM5/11/18
to Keras-users
Hi,

I am running language translation model using encoder/decoder architecture. I am using keras bundled with tensorflow 1.8, using tensorflow.python.keras functions. When I try to save encoder and decoder models, I am getting the following error.

encoder_model.save('seq2seq_encoder_eng_hin.hd5')
decoder_model
.save('seq2seq_decoder_eng_hin.hd5')

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-42-3d9647a65ce6> in <module>()
----> 1 encoder_model.save('Chatbot_E2H/seq2seq_encoder_eng_hin.hd5')
      2 decoder_model.save('Chatbot_E2H/seq2seq_decoder_eng_hin.hd5')

~\Anaconda3\envs\tf18\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\network.py in save(self, filepath, overwrite, include_optimizer)
   1124
   1125     from tensorflow.python.keras._impl.keras.models import save_model  # pylint: disable=g-import-not-at-top
-> 1126     save_model(self, filepath, overwrite, include_optimizer)
   1127
   1128   def save_weights(self, filepath, overwrite=True):

~\Anaconda3\envs\tf18\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\saving.py in save_model(model, filepath, overwrite, include_optimizer)
    148                 'optimizer_config': {
    149                     'class_name': model.optimizer.__class__.__name__,
--> 150                     'config': model.optimizer.get_config()
    151                 },
    152                 'loss': model.loss,

AttributeError: 'NoneType' object has no attribute 'get_config'



These models are used for inference. Strangely when I save the model used for training(translation_model), it is not giving this error, but gives another warning as shown below!

translation_model.save('Chatbot_E2H/eng2hindi1000.hd5')

-----------------
WARNING
:tensorflow:Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm/while/Exit_2:0' shape=(?, 256) dtype=float32>, <tf.Tensor 'lstm/while/Exit_3:0' shape=(?, 256) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time).

------------------------------




Appreciate any help on this.

In fact, I ran this model earlier on colab portal with keras 2.1.4, tensorflow 1.6. It also gave the warning message as above, but encoder/decoder model save did not give AttributeError! Looks like it is introduced i


nivedit...@gmail.com

unread,
Jan 23, 2019, 9:26:08 PM1/23/19
to Keras-users
Hi Srinivasa,

Did you get this resolved? Nivedit here - hope you remember me. I was in same UPx batch with you.

Regards,
Nivedit.
Reply all
Reply to author
Forward
0 new messages