original_keras_version = f.attrs['keras_version'].decode('utf8') 'str' object has no attribute 'decode'

 

AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_13758/2975874631.py in <module>
----> 1 ft_model.load_weights('./saved_models/D8.v8.h5')
      2
      3
      4 y_pred = ft_model.predict(X).ravel()
      5 y_pred_list.append(y_pred)

/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/keras/engine/saving.py in load_wrapper(*args, **kwargs)
    490                 os.remove(tmp_filepath)
    491             return res
--> 492         return load_function(*args, **kwargs)
    493
    494     return load_wrapper

/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/keras/engine/network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
   1228             else:
   1229                 saving.load_weights_from_hdf5_group(
-> 1230                     f, self.layers, reshape=reshape)
   1231             if hasattr(f, 'close'):
   1232                 f.close()

/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/keras/engine/saving.py in load_weights_from_hdf5_group(f, layers, reshape)
   1181     """
   1182     if 'keras_version' in f.attrs:
-> 1183         original_keras_version = f.attrs['keras_version'].decode('utf8')
   1184     else:
   1185         original_keras_version = '1'

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

 

=========================================================

 

 

 

原因分析


在安装 tensorflow 时,默认安装 h5py 为3.7.0,而报错是因为你安装的 TF 不支持过高版本的 h5py。


 解决方案


1.卸 载 h5py 3.7.0版本,安装  h5py  2.10.0  版本。

pip uninstall h5py
pip install h5py==2.10.0

 

2.重启编译器

 

REF

http://www.360doc.com/content/22/0624/08/13826502_1037220402.shtml

posted @   emanlee  阅读(196)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
历史上的今天:
2022-02-03 Python 注册表操作
2021-02-03 时间序列数据如何插补缺失值?
2021-02-03 pandas 缺失值处理,插值
2015-02-03 Python根据内嵌的数字将字符串排序(sort by numbers embedded in strings)
2012-02-03 贝赛尔曲线
2012-02-03 样条曲线 spline curves
点击右上角即可分享
微信分享提示