【问题标题】:Google colaboratory, Keras : Save model in HDF5 file format and download it to LaptopGoogle colaboratory, Keras:以 HDF5 文件格式保存模型并将其下载到笔记本电脑
【发布时间】:2018-10-31 00:20:40
【问题描述】:

我正在使用 GPU 在 Google Collab 中训练小型 RNN 模型。我通常将模型和权重保存为 HDF5 文件格式。

在本地机器(笔记本电脑)中,我按照以下步骤进行操作

sudo pip install h5py
model.fit(....)
model.save('model1.h5')

我加载回训练好的模型进行预测,

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

我现在想

  1. 在 Google Collab 中保存模型,格式与上述类似
  2. 下载.h5文件到本地机器(PC)
  3. 在 PC 中进行预测并在 PC 中进行训练
  4. 保存经过训练的模型,将 .h5 文件加载回 google collab
  5. 在 Google Collab 中恢复培训

【问题讨论】:

    标签: keras hdf5 h5py google-colaboratory


    【解决方案1】:

    有点晚了,但为了未来的开发者,我会尝试解决这个问题。

    该过程与您的本地计算机中的过程相同,只有两个不同:

    从 Google Collab 下载模型:

    from google.colab import files
    files.download("model1.h5")
    

    要将模型上传到 Google Collab:

    from google.colab import files
    files.upload()
    

    您可以查看此笔记本了解更多 i/o 选项:https://colab.research.google.com/notebooks/io.ipynb

    所有其他步骤的执行方式与您在本地计算机中执行的方式相同。 希望对您有所帮助。

    【讨论】:

    • 更正from google.colab import files 另外,files.upload() 不接受任何参数,所以这不起作用。
    猜你喜欢
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    相关资源
    最近更新 更多