更新 - 进一步的复杂性 - ImportError: `load_weights` 需要 h5py

问题描述 投票:0回答:1

我正在使用以前保存的模型,但是,当我尝试加载模型时,我收到以下错误消息:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-11-f8d353bad309> in <module>
----> 1 estimator, corpus_encoder, label_encoder, tokenizer = load_model(MODEL_PATH, loss=weighted_binary_crossentropy)

<ipython-input-6-03f944f0a51f> in load_model(model_base_dir, loss, optimizer, metrics)
      9         json_file.close()
     10     model = model_from_json(loaded_model_json)
---> 11     model.load_weights(os.path.join(MODEL_PATH, 'model.h5'))
     12     model.compile(loss=loss, optimizer=optimizer, metrics=metrics)
     13     # loading context_encoder

~\anaconda3\envs\davis_env\lib\site-packages\keras\engine\network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
   1154         """
   1155         if h5py is None:
-> 1156             raise ImportError('`load_weights` requires h5py.')
   1157         with h5py.File(filepath, mode='r') as f:
   1158             if 'layer_names' not in f.attrs and 'model_weights' in f:

ImportError: `load_weights` requires h5py.

我已经安装了

cython
h5py
,如在这里这里

找到的答案中所述

还有其他解决办法吗?

我正在使用

tensorflow
版本
1.12.0
keras
版本
2.2.4

更新:

当只是尝试导入 h5py (通过``import h5py``)时,我收到以下错误消息:

ImportError                               Traceback (most recent call last)
<ipython-input-15-c9f0b8c65221> in <module>
----> 1 import h5py

~\anaconda3\envs\davis_env\lib\site-packages\h5py\__init__.py in <module>
     32         raise
     33 
---> 34 from . import version
     35 
     36 if version.hdf5_version_tuple != version.hdf5_built_version_tuple:

~\anaconda3\envs\davis_env\lib\site-packages\h5py\version.py in <module>
     15 
     16 from collections import namedtuple
---> 17 from . import h5 as _h5
     18 import sys
     19 import numpy

h5py\h5.pyx in init h5py.h5()

ImportError: DLL load failed: The specified procedure could not be found.```




python tensorflow keras h5py
1个回答
0
投票

我对 h5py 软件包也有同样的问题,并发现我安装的 opencv 软件包也包含 h5py。我错误地安装了 opencv 而不是 opencv-python。 我通过卸载 opencv 并重新安装 opencv 解决了这个问题

pip uninstall opencv    
pip install opencv-python

即使您已经安装了正确的 opencv-python 软件包,也可以通过重新安装正确的 opencv-python 软件包来解决此 h5py 问题。

© www.soinside.com 2019 - 2024. All rights reserved.