如何导入训练有素的 keras 模型

数据挖掘 喀拉斯 机器学习模型
2022-02-20 22:03:43

我有一些训练有素的模型可以导入和比较,但是同样的代码给出了:

"WARNING tensorflow:From 'where its saved' colocate with (from tensorflow.python.framework.ops)
  is deprecated and will be removed in a future version.
Instructions for updating:
  Colocations handled automatically by placer."

以及其他 2 个弃用警告。

我用来导入模型的代码是:

"model_1 = load_model("filepath\\filename.h5")"

重新启动我的计算机解决了这个问题,但我很好奇为什么会发生这种情况,如果有人能解释的话。

1个回答

恐怕如果您将模型保存在驱动器而不是 google collab 目录中,因为它会在运行时会话中断后丢失。

model_new = load_model('BestModelWeights.hdf5') # 将加载模型,如果 BestModelWeights 文件存在于 collab 目录中——我觉得在你的情况下迷失了,这可能是你得到“保存位置”错误的原因。

我建议使用谷歌驱动器保存权重并在需要时直接加载权重文件。为此,您需要执行两个步骤

  1. 挂载谷歌驱动器并验证协作。

    从 google.colab 导入驱动器 drive.mount('/content/drive')

  2. 加载模型

    model_new = load_model('/content/drive/My Drive/BestModelWeights.hdf5')

您可以使用新加载的模型。

希望能帮助到你。JSH