当前位置:网站首页>【错误】加载h5权重出错AttributeError: ‘str‘ object has no attribute ‘decode‘

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

2022-07-08 00:25:00 there2belief

问题

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

原网站

版权声明
本文为[there2belief]所创,转载请带上原文链接,感谢
https://blog.csdn.net/dou3516/article/details/125656421