我在colab中通过keras=2.3.1和tensorflow=2.1.0训练了一个深度模型,我用JSON和Keras保存了我的模型:
saveWeightPath = "/content/drive/My Drive/model_info/model_weights.h5"
saveModelPath = "/content/drive/My Drive/model_info"
model.save_weights(saveWeightPath)
tf.keras.models.save_model(model, saveModelPath)
和我保存的 json 代码
model_json = model.to_json()
with open("model.json", "w") as json_file:
json_file.write(model_json)
model.save_weights("model.h5")
print("Saved model to disk")
当我想在 colab 中加载模型时,我没有问题,但是当我想在电脑本地加载模型时,我不能,并且收到此错误:
”
- fid = h5f.open(name, flags, fapl=fapl) 文件“h5py_objects.pyx”,第 54 行,在 h5py._objects.with_phil.wrapper 文件“h5py_objects.pyx”中,
第 55 行,在 h5py._objects.with_phil.wrapper 文件“h5py\h5f.pyx”中,行
88、在h5py.h5f.open中OSError: Unable to open file(无法打开
文件: name = 'C:/Users/Kosar 37638090/Desktop/end pro/model_info',
errno = 13,错误消息 = '权限被拒绝',flags = 0,o_flags =
0)
"
-
我的 Keras 和张量版本与我的 colab Keras 和张量版本相同
-
我尝试在电脑中使用 JSON 和 Keras 加载我的模型
-
我收到回溯错误,我将错误消息的最后 5 行和最上面几行复制到此处3
您好,首先您需要存储模型或模型权重吗?
要知道它们之间的区别,model.save()
为您节省重量和结构模型......但是model.save_weights()
只要保存你的体重模型,我建议你看看这个了解更多信息。
如果你想保存模型,我建议使用model.save("test.hd5")
or model.save(test.hdf5")
并使用tensorflow.kears.models.load_model("test.hd5")
加载模型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)