python,tensorflow报错AttributeError: ‘str’ object has no attribute 'decode’
今天重装了一下anaconda,然后配置了一下深度学习环境,安装完毕后加载之前训练的模型,发现一直报这个错误: File "D:\anaconda3\envs\tf1131\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = _deserialize_model(f, custom_objects, compile) File "D:\anaconda3\envs\tf1131\lib\site-packages\keras\engine\saving.py", line 224, in _deserialize_model model_config = json.loads(model_config.decode('utf-8')) AttributeError: 'str' object has no attribute 'decode' 一开始以为是python字符串编码解码的问题,换了项目运行之后还是报这个问题,但是这次跟上次不太一样,提示是加载模型文件的问题 File "D:\anaconda3\envs\tf1131\lib\site-packages\keras\engine\network.py", line 1166, in load_weights f, self.layers, reshape=reshape) File "D:\anaconda3\envs\tf1131\lib\site-packages\keras\engine\saving.py", line 1004, in **load_weights_from_hdf5_group** original_keras_version = f.attrs['keras_version'].decode('utf8') AttributeError: 'str' object has no attribute 'decode' 最后搜索发现是anaconda自带安装的h5py版本是 3.1.0的,太高了,最后将h5py的版本降为2.10.0的即可 pip install h5py==2.10.0
|