首页 > 其他分享 >original_keras_version = f.attrs['keras_version'].decode('utf8') 'str'

original_keras_version = f.attrs['keras_version'].decode('utf8') 'str'

时间:2023-02-03 22:44:07浏览次数:49  
标签:load keras decode version attrs h5py

 

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

标签:load,keras,decode,version,attrs,h5py
From: https://www.cnblogs.com/emanlee/p/17090635.html

相关文章