keras加载模型load_model时报错:AttributeError: ‘str‘ object has no attribute ‘decode‘ “
背景使用Keras训练了一个模型,训练好后保存为h5文件。再次加载这个模型时,报错了:AttributeError: ‘str‘ object has no attribute ‘decode‘ “:我是使用 keras_to_tensorflow.py 这个脚本的时候报的错。解决网上说了一些报这个错误的解决方法。python2和python3的编码方式不一致导致h5py包的版本不对导致第一种情况
·
背景
使用Keras训练了一个模型,训练好后保存为h5文件。
再次加载这个模型时,报错了:AttributeError: ‘str‘ object has no attribute ‘decode‘ “:
我是使用 keras_to_tensorflow.py 这个脚本的时候报的错。
解决
网上说了一些报这个错误的解决方法。
- python2和python3的编码方式不一致导致
- h5py包的版本不对导致
第一种情况基本可以排除,因为我是用Anaconda安装的tf,python使用的是3.6,没有python2。
第二种情况是非常可能的,因为我使用conda list查看时,版本为3.1.0。
于是,执行指令:
pip install h5py==2.10
安装了指定版本为2.10的包,重试程序,成功了!
小结
没什么可总结的,遇到问题,可能有多种解决方法,选择适合自己的那一种。
更多推荐


所有评论(0)