【错误】加载h5权重出错AttributeError: ‘str‘ object has no attribute ‘decode‘

2023-05-16

问题

tensorflow在python3.7环境加载python3.6环境的h5权重时出错
AttributeError: 'str' object has no attribute 'decode'

解决思路

根据问题提示,意思是,属性错误:“str”对象没有属性“decode”

网上出现该问题多是python3和2的差异导致

例如:python3.5和Python2.7在套接字返回值解码上的区别 

python在bytes和str两种类型转换,所需要的函数依次是encode(),decode()

笔者是出现在python3.7与python3.6

解决方法

T1、直接去掉
直接去掉decode('utf8')

tips:str通过encode()方法可以编码为指定的bytes。反过来,当从网络或磁盘上读取了字节流,那么读到的数据就是bytes。要把bytes变为str,就需要用decode()方法。反之,则使用encode()方法即可!

T2、众多网友好评的建议
pip install 'h5py<3.0.0' -i https://pypi.tuna.tsinghua.edu.cn/simple


————————————————
Thanks to:https://blog.csdn.net/qq_41185868/article/details/82079079

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【错误】加载h5权重出错AttributeError: ‘str‘ object has no attribute ‘decode‘ 的相关文章

随机推荐