【发布时间】:2019-07-03 17:47:26
【问题描述】:
当我尝试像这样获取模型时,我正在编写一个专门训练机器学习模型的应用程序:
model = tf.keras.models.load_model('./models/model.h5')
我收到一个错误:
Unable to open file (unable to open file: name = 'models/model.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
但在某些特殊情况下,模型可能不存在于磁盘上,此时应创建、训练并保存模型以供以后使用。检查模型是否存在的正确方法是什么?我可以使用 python 中的内置功能来检查文件是否存在,但对我来说很明显 load_model 上应该有一个参数,如果文件不存在则返回 None 而不是抛出错误。
【问题讨论】:
标签: python-3.x tensorflow keras