解决“AttributeError: ‘str‘ object has no attribute ‘decode‘”问题

2023-05-16

问题描述

在跑代码的时候出现报错提示

Traceback (most recent call last):
  File "multi_detect_Nerual.py", line 4, in <module>
    import BiLSTM.bilstm_speech_seg_predict as nerual_seg
  File "/home/xxx/xxx/xxx/BiLSTM/bilstm_speech_seg_predict.py", line 23, in <module>
    model.load_weights(h5_model_file)
  File "/home/xxx/anaconda3/envs/xxx/lib/python3.7/site-packages/keras/engine/network.py", line 1166, in load_weights
    f, self.layers, reshape=reshape)
  File "/home/xxx/anaconda3/envs/xxx/lib/python3.7/site-packages/keras/engine/saving.py", line 1004, in load_weights_from_hdf5_group
    original_keras_version = f.attrs['keras_version'].decode('utf8')
AttributeError: 'str' object has no attribute 'decode'

问题分析

该报错意思是:属性错误:'str'对象没有'decode'属性

解决方法

最简单的方法,不用修改代码

pip install 'h5py<3.0.0' -i https://pypi.tuna.tsinghua.edu.cn/simple

如下所示,问题解决!

Colocations handled automatically by placer.
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
bidirectional_1 (Bidirection (None, 200, 256)          167936    
_________________________________________________________________
bidirectional_2 (Bidirection (None, 200, 256)          394240    
_________________________________________________________________
time_distributed_1 (TimeDist (None, 200, 32)           8224      
_________________________________________________________________
time_distributed_2 (TimeDist (None, 200, 32)           1056      
_________________________________________________________________
time_distributed_3 (TimeDist (None, 200, 1)            33        
=================================================================
Total params: 571,489
Trainable params: 571,489
Non-trainable params: 0
_________________________________________________________________
2022-10-24 15:01:09.369530: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 AVX512F FMA
2022-10-24 15:01:09.391688: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3400000000 Hz
2022-10-24 15:01:09.396757: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x55ba4e0a7330 executing computations on platform Host. Devices:
2022-10-24 15:01:09.396799: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
(35, 3841)
(73, 200, 35)
(73, 200, 1)
The segmentation point for this audio file is listed (Unit: /s) [ 5.888  7.248  8.8   11.664 13.056 19.408 21.216 22.896 26.16  28.4
 30.928 33.424 40.688 50.512 53.936]

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

解决“AttributeError: ‘str‘ object has no attribute ‘decode‘”问题 的相关文章

随机推荐