【问题标题】:Keras ConvLSTM2D: ValueError when saving modelKeras ConvLSTM2D:保存模型时出现ValueError
【发布时间】:2020-08-05 08:17:48
【问题描述】:

我正在尝试为时间序列预测创建几个 LSTM 模型(例如 Vanilla、Stacked、Bidirectional)。创建模型后,我想使用tf.keras.models.save_model保存它

这适用于我上面描述的 LSTM 架构,但是在尝试保存 ConvLSTM model 时出现以下错误:ValueError: Object dictionary contains a non-trackable object: (None, None) (for关键州)

我在 Colab 笔记本上使用 Keras 和后端 TensorFlow (2.X)。我创建了一个notebook 可以重现问题。

任何帮助将不胜感激!

编辑:模型应保存为 Tensorflow SavedModel 格式 (save_format='tf')

【问题讨论】:

    标签: tensorflow keras conv-neural-network lstm google-colaboratory


    【解决方案1】:

    更新:我可以确认此问题已在 Tensorflow 2.3.0 https://github.com/tensorflow/tensorflow/issues/40081 中得到修复

    【讨论】:

      【解决方案2】:

      有两种方法可以保存模型。

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

      2. 您的方法,但您缺少模型名称和扩展名。

      使用 cd 进入 gdrive 目录。

      % cd /content/gdrive
      

      使用文件名和扩展名保存。

      # save model to drive
      tf.keras.models.save_model(
          model = model,
          filepath = 'model2.h5',
          overwrite=True,
          include_optimizer=True,
          save_format=None,
          signatures=None
      )
      

      【讨论】:

      • 感谢您的回复。在我的情况下,我需要将模型保存为 Tensorflow SavedModel 格式(save_format='tf')。当我尝试使用您的建议执行此操作时,我仍然收到相同的错误 ValueError: Object dictionary contains a non-trackable object: (None, None) (for key states)
      • 您的模型无法使用 Tensorflow SavedModel 序列化,您必须使用 .h5 或者可能必须在 tensorflow 中使用适合 SavedModel 的新实现。
      猜你喜欢
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      • 2020-04-11
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多