【发布时间】: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