且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Google Cloud Bucket 中保存 Keras ModelCheckpoint

更新时间:2023-12-01 22:41:10

可以用下面一段代码解决这个问题:

The issue can be solved with the following piece of code:

# Save Keras ModelCheckpoints locally
model.save('model.h5')

# Copy model.h5 over to Google Cloud Storage
with file_io.FileIO('model.h5', mode='r') as input_f:
    with file_io.FileIO('model.h5', mode='w+') as output_f:
        output_f.write(input_f.read())
        print("Saved model.h5 to GCS")

model.h5 保存在本地文件系统中并复制到 GCS.正如 Jochen 指出的那样,目前没有简单的支持将 HDF5 模型检查点写入 GCS.有了这个 hack,就可以写入数据,直到提供更简单的解决方案.

The model.h5 is saved on local filesystem and the copied over to GCS. As Jochen pointed out, there currently is no easy support to write HDF5 model checkpoints to GCS. With this hack it is possible to write the data until an easier solution is provided.