【问题标题】:Loading Keras model from google cloud ml bucket从谷歌云 ml 存储桶加载 Keras 模型
【发布时间】:2018-04-20 13:56:46
【问题描述】:

在 Google 云机器学习上使用 Keras:

从训练中保存模型:

model.save('model.h5')

if cfg.cloud:
    # Copy model.h5 over to Google Cloud Storage
    with file_io.FileIO('model.h5', mode='rb') as input_f:
        with file_io.FileIO(data_folder + 'model.h5', mode='wb+') as output_f:
            output_f.write(input_f.read())

注意:不保存到 job_folder,我需要稍后再阅读,不想跟踪最新的作业(即使这是将模型分开的好方法)。

现在我想从下一次运行中读取:

f = file_io.FileIO(model_file, mode='rb')
model = load_model(f)
model.load_weights(f)

“model_file”在我的提交中作为输入给出,指向

--model-file gs://$BUCKET_NAME/resources/model.h5

来自 google cloud ml jobs 的投诉:

TypeError: expected str, bytes or os.PathLike object, not FileIO

我尝试了很多方法,但我的基本问题是:尤其是从 gcp 存储桶中读取模型的最佳实践是什么?

【问题讨论】:

  • 请说明此异常发生在代码中的哪个位置,是在您的 load_model(f) 代码中还是在 sdk 代码中?
  • 感谢 Oliver,我进行了一些调试以更详细地回答您的问题,并在此过程中找到了以下解决方案。

标签: model keras google-cloud-platform load google-cloud-ml


【解决方案1】:

最后我得到了它,使用这里的解决方案:

loading saved keras model from gs to pydatalab

感谢 Tíarnán McGrath(我没有足够的积分来加 1)

【讨论】:

  • 什么是将模型文件从gs复制到本地文件系统,对吧?
  • @user2427317 你可以接受你的答案(考虑编辑添加重要信息)
猜你喜欢
  • 2021-03-12
  • 1970-01-01
  • 2020-06-01
  • 2018-08-29
  • 1970-01-01
  • 1970-01-01
  • 2021-04-07
  • 2018-10-27
  • 2019-04-13
相关资源
最近更新 更多