【问题标题】:Google COLAB free version saving Keras trained model谷歌 COLAB 免费版保存 Keras 训练模型
【发布时间】:2020-06-03 03:26:07
【问题描述】:

我在 google colab 免费版中保存了经过 keras 训练的模型

 model.save("my_model.h5")

我尝试使用以下方法检索模型

from keras.models import load_model
model = load_model('my_model.h5')

但它会抛出错误

OSError: Unable to open file (unable to open file: name = 'my_model.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

我能从免费的 google colab 版本中检索保存的模型吗,你能帮忙吗? 我在stackoverflow中检查了类似的问题,我认为这些答案属于colab pro版本

否则,我是否必须在训练时将模型保存到本地驱动器的特定路径中?

【问题讨论】:

  • 是的,我遵循如下,>from google.colab import drive >drive.mount('/content/drive') '**
  • 保存和加载模型的时间差是多少。这是因为您正在保存模型 colab 环境,而 colab 环境在运行时终止时会删除文件。
  • @PSKP 昨天早上 6:30 开始营业,累到早上 7:30 营业。我怀疑这可能是原因。你能告诉我在这种情况下如何将深度学习模型保存到本地驱动器
  • 我添加了可以解决您问题的答案。看看吧。

标签: keras google-colaboratory


【解决方案1】:

什么问题

您将模型存储在运行时而不是您的谷歌驱动器中。运行 12 小时后自动删除数据。所以我们必须将模型保存在谷歌驱动器中。

如何存储到 Google 云端硬盘

首先连接到谷歌驱动器

from google.colab import drive
drive.mount('/content/drive')

现在您将在左侧找到具有drive 目录的文件资源管理器。当你进入该目录时,它会带你到谷歌驱动器。

假设我想把我的数据放在驱动器My Drive 然后

from keras.models import load_model

MODEL_PATH = './drive/My Drive/model.h5'

# Now save model in drive
model.save(MODEL_PATH)

# Load Model
model = load_model(MODEL_PATH)

当您打开驱动器时,您会在驱动器中找到文件model.h5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 2018-01-05
    相关资源
    最近更新 更多