[英]Error loading model weights from .hdf5 in Keras
我正在嘗試從 hdf5 文件加載 model 權重以在我的測試集上進行評估。 當我嘗試加載權重時,出現以下錯誤:
"Unable to open object (file read failed: time = Sat Jan 9 18:02:20 2021\n, filename = '/content/drive/My Drive/Training Checkpoints/training_vgg16/Augmented/01-1.6986_preprocessed_unfrozen.hdf5', file descriptor = 203, errno = 5, error message = 'Input/output error', buf = 0x2d4ae840, total read size = 328, bytes this sub-read = 328, bytes actually read = 18446744073709551615, offset = 134448512)"
我正在使用的代碼如下:
weights_path = '/content/drive/My Drive/Training Checkpoints/training_vgg16/Augmented/'
for weight in os.listdir(weights_path):
print(weight)
weight_path = weights_path + weight
model.load_weights(weight_path)
evaluate_model()
昨天同樣的過程運行良好,但今天我收到了這個錯誤。 任何幫助將不勝感激!
編輯:重新啟動 Colab 運行時並重新運行后,這是我得到的錯誤堆棧跟蹤:
KeyError Traceback (most recent call last)
<ipython-input-51-0c9304b73f08> in <module>()
7 print(weight)
8 weight_path = weights_path + weight
----> 9 model.load_weights(weight_path)
10 evaluate_model()
2 frames
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
/usr/local/lib/python3.6/dist-packages/h5py/_hl/group.py in __getitem__(self, name)
262 raise ValueError("Invalid HDF5 object reference")
263 else:
--> 264 oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
265
266 otype = h5i.get_type(oid)
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/h5o.pyx in h5py.h5o.open()
KeyError: "Unable to open object (file read failed: time = Sat Jan 9 20:30:57 2021\n, filename = '/content/drive/My Drive/Training Checkpoints/training_vgg16/Unaugmented/03-1.5748_1_frozen.hdf5', file descriptor = 85, errno = 22, error message = 'Invalid argument', buf = 0x2b2af360, total read size = 160, bytes this sub-read = 160, bytes actually read = 18446744073709551615, offset = 49486272)"```
事實證明,雖然之前使用load_weights
有效,但我實際上保存了整個 model,並且對於一些已保存的.hdf5 文件它不起作用。 更改為使用load_model
會正確加載所有這些。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.