Keras ConvLSTM2D: ValueError when saving model
Asked Answered
M

2

6

I am trying to create several LSTM models for time series prediction (e.g. Vanilla, Stacked, Bidirectional). After creating a model I want to save it using tf.keras.models.save_model

This works fine for the LSTM architectures I describe above, but when trying to save a ConvLSTM model I get the following error: ValueError: Object dictionary contained a non-trackable object: (None, None) (for key states)

I am using Keras with backend TensorFlow (2.X) on a Colab notebook. I've created a notebook where the problem can be reproduced.

Any help would be appreciated!

Edit: the model should be saved in the Tensorflow SavedModel format (save_format='tf')

Murdock answered 22/4, 2020 at 10:32 Comment(0)
M
1

There are two ways you can save your model.

  1. model.save('model.h5')

  2. Your method but you're missing model name and extension.

Go to gdrive directory using cd.

% cd /content/gdrive

Save with the file name and extension.

# save model to drive
tf.keras.models.save_model(
    model = model,
    filepath = 'model2.h5',
    overwrite=True,
    include_optimizer=True,
    save_format=None,
    signatures=None
)
Magnetite answered 22/4, 2020 at 10:51 Comment(2)
Thank you for your response. In my case I need to save the model in the Tensorflow SavedModel format (save_format='tf'). When I try to do this using your suggestion, I still get the same error ValueError: Object dictionary contained a non-trackable object: (None, None) (for key states)Murdock
your model can't be serialized with Tensorflow SavedModel, you have to use .h5 or probably have to use a new implmentation in tensorflow suitable for SavedModel.Magnetite
M
0

Update: I can confirm this issue has been fixed in Tensorflow 2.3.0 https://github.com/tensorflow/tensorflow/issues/40081

Midships answered 21/8, 2020 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.