`load_weights` requires h5py报错解决

今天在pycharm上跑神经网络时在保存模型读入权重时报错:

loaded_model = model_from_json(loaded_model_json)  # 读入网络结构
loaded_model.load_weights("model.h5")  # 读入权重
ImportError: `load_weights` requires h5py.

对于这个问题,网友们给出的回答无非是以下方法:

pip install h5py
conda install h5py

如果运行完以上语句,你的代码可以跑了,那么恭喜你,你的问题解决了。

但当我在Anaconda Prompt中下载h5py后,发现问题并没有解决,新的问题出现了。

(base) C:\Users\316CJW>pip install h5py
Requirement already satisfied: h5py in c:\users\316cjw\anaconda3\lib\site-packages (2.7.1)
Requirement already satisfied: numpy>=1.7 in c:\users\316cjw\anaconda3\lib\site-packages (from h5py) (1.18.1)
Requirement already satisfied: six in c:\users\316cjw\anaconda3\lib\site-packages (from h5py) (1.14.0)

怎么办呢?我得出的结论是numpy版本高引起安装失败!

解决办法:卸载numpy,安装h5py

pip uninstall numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple h5py

安装成功!

Successfully installed h5py-2.10.0 numpy-1.18.2

如果我的解答对你有帮助的话,别忘了点赞!

 

你可能感兴趣的:(`load_weights` requires h5py报错解决)