tf.keras.models.load_model模型加载时报错

tf.keras.models.load_model模型加载时报错

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\h5f.pyx”, line 156, in h5py.h5f.is_hdf5 OSError

保存模型

model.save('./data/model/lstm1216.h5')

加载模型

tf.keras.models.load_model('./data/model/lstm1216.h5')

报错内容

Traceback (most recent call last):
  File "E:/competition/NLP中文预训练模型泛化能力挑战赛/OCEMOTION/predict.py", line 17, in <module>
    model = tf.keras.models.load_model('./data/model/lstm1216.h5')
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\tensorflow\python\keras\saving\save.py", line 181, in load_model
    isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
  File "D:\Anaconda3\envs\tensorflow_gpu\lib\site-packages\h5py\_hl\base.py", line 44, in is_hdf5
    return h5f.is_hdf5(filename_encode(fname))
  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\h5f.pyx", line 156, in h5py.h5f.is_hdf5
OSError

问题
h5py的版本 2.10.0
hdf5 的版本1.10.6
hdf5的版本过高。
解决
conda install hdf5==1.10.4
参考
https://stackoverflow.com/questions/64626914/oserror-loading-a-h5-saved-model-in-tensorflow-keras-after-updating-the-environ

你可能感兴趣的:(tensorflow,神经网络,深度学习)