keras中AttributeError: ‘bytes‘ object has no attribute ‘encode‘解决方案

遇到的问题

执行keras的预测程序时,在载入网络权重数据时出现

AttributeError: 'str' object has no attribute 'decode'

在这里插入图片描述
参考:
keras与h5py版本不兼容

pip install h5py==2.10

将h5py降级

出现新问题:
在这里插入图片描述

AttributeError: 'bytes' object has no attribute 'encode'

原因

python3中,编码的时候区分了字符串和二进制
python3在bytes和str两种类型转换,所需要的函数依次是encode(),decode()
在这里插入图片描述
详细:
浅析Python3中的bytes和str类型

解决方案

找到报错的文件,将bytes类型数据n后的.encode(‘utf-8’)删除即可。

在这里插入图片描述


版权声明:本文为u011642016原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。