每次从HDF5文件加载模型时,都会出现此错误。下面是我的错误跟踪。
Traceback (most recent call last):
File "D:\Anaconda3New\Datasets\train.py", line 63, in <module>
model = load_model(args["model"])
File "D:\Anaconda3New\lib\site-packages\keras\engine\saving.py", line 419, in
load_model
model = _deserialize_model(f, custom_objects, compile)
File "D:\Anaconda3New\lib\site-packages\keras\engine\saving.py", line 249, in
_deserialize_model
layer_weights = model_weights_group[name]
File "D:\Anaconda3New\lib\site-packages\keras\utils\io_utils.py", line 303, in
__getitem__
val = H5Dict(self.data.create_group(attr))
File "C:\Users\dell\AppData\Roaming\Python\Python37\site-packages\h5py\_hl\gro
up.py", line 68, in create_group
gid = h5g.create(self.id, name, lcpl=lcpl, gcpl=gcpl)
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5g.pyx", line 161, in h5py.h5g.create
ValueError: Unable to create group (no write intent on file)
我已经阅读了以下问题,但是似乎这与我目前遇到的问题不同。
I can't read data back in using h5py. "unable to create group"
因为我只是从保存的HDF5文件(在cmd中按ctrl + c后创建)加载架构和权重,如何为该HDF5文件分配模式?
有人可以帮助我解决此问题吗?
请参阅保存模型的两种方法。答:-
model.save("Model_name.model")
和B:-
model_json = model.to_json()
with open(file_name + ".json", "w") as json_file:
json_file.write(model_json)
model.save_weights(file_name + '.h5')
我相信您是使用第一种方法保存模型的,由于存在许多内部冲突,因此无法使用。我建议您使用第二种方法保存模型,然后尝试重新加载模型。它将起作用。
另一个可能的错误是,由于您说的是在按ctrl + c之后保存了模型,该命令通常用于终止程序,因此可能导致文件的不正确保存。尝试使用其他组合键。