完美解决 AttributeError: ‘str‘ object has no attribute ‘decode‘

问题描述:

  File "/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 234, in load_weights
    return super(Model, self).load_weights(filepath, by_name, skip_mismatch)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/network.py", line 1222, in load_weights
    hdf5_format.load_weights_from_hdf5_group(f, self.layers)
  File "/opt/conda/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 651, in load_weights_from_hdf5_group
    original_keras_version = f.attrs['keras_version'].decode('utf8')
AttributeError: 'str' object has no attribute 'decode'

原因

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

解决方案

1.卸载h5py3.1.0版本,安装h5py2.10.0版本。
2.重启编译器
pip install h5py==2.10.0

完美解决 AttributeError: ‘str‘ object has no attribute ‘decode‘_第1张图片

你可能感兴趣的:(python使用技巧,报错记录,tensorflow,keras,python)