报错信息:
AttributeError: ‘str‘ object has no attribute ‘decode‘
报错语句所在位置:
model_config = json.loads(model_config.decode('utf-8')
报错原因:
tensorflow某一些版本不支持h5py>=3.0.0,所以要安装低版本的h5py
解决方法:
pip install h5py==2.10.0
或
conda install h5py==2.10.0
如果你选择用conda
装h5py
可能会接着报下面的错误:
File "D:\soft\anaconda\envs\pytorch\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\saving.py", line 205, in load_model
raise ImportError('`load_model` requires h5py.')
ImportError: `load_model` requires h5py.
或者下面的错误:
File "D:\soft\anaconda\envs\pytorch\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\saving.py", line 235, in load_model
with h5py.File(filepath, mode='r') as f:
AttributeError: module 'h5py' has no attribute 'File'
我猜测这是因为我一开始用pip
已经安装了一个高版本的h5py
,然后又用conda
安装了一个2.10.0版本的h5py
,所以现在虚拟环境中有conda
和pip
混着的h5py
,而且版本可能还不一样。所以你最好卸载干净后再重新安装h5py
:
pip uninstall h5py
conda install h5py