【问题标题】:How to properly save a keras model in R?如何在 R 中正确保存 keras 模型?
【发布时间】:2020-06-20 21:29:05
【问题描述】:

我一直无法保存一个keras模型,我一直在使用这个代码:

save_model_hdf5(model, "F:/Models/1")

我收到此错误消息:

#Error in py_call_impl(callable, dots$args, dots$keywords):
#OSError: Unable to create file(unable to open file: name = 'F:\Modelos\1', error = 13,error message = 'Permission denied', flags = 13,o_flags = 302) 

【问题讨论】:

    标签: r keras


    【解决方案1】:

    Python:

    我使用model.save(filename.hdf5) 来保存我的模型。请注意,model 是一个对象,例如由model.compile(...) 创建。查找full example here

    # Set up model
    model = models.Sequential()
    ...
    # Compile model
    model.compile(...)
    ...
    # Save model
    model.save('C:/savepath/savename.hdf5')
    

    可以再次加载模型,例如to make predictions as outlined here.

    # Load model
    model = load_model('C:/savepath/savename.hdf5')
    

    R:

    在 R 中,保存模型的工作方式略有不同:

    # Set up a model
    model <- create_model()
    ...
    # Fit the model
    model %>% fit()
    ...
    # Save the model
    model %>% save_model_hdf5("C:/savepath/savename.hdf5")
    

    或者(没有中缀运算符%&gt;%,它不是基础 R 的一部分):

    save_model_hdf5(model, "C:/savepath/savename.hdf5")
    

    【讨论】:

    • save_model_hdf5(model, "F:/Models/1/model.hdf5")
    猜你喜欢
    • 2019-03-14
    • 2020-05-28
    • 2018-05-02
    • 2022-07-25
    • 2012-01-22
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 2021-05-05
    相关资源
    最近更新 更多