IndexError: list index out of range in " labels += [i.split('/')[-2]] "

IndexError: list index out of range in " labels += [i.split('/')[-2]] "

我是 TensorFlow 的新手 python。我正在尝试 运行 并在 https://www.kaggle.com/sunyuanxi/speech-recognition-keras 中学习“使用 Keras 的语音识别”,但我对下面的这部分代码有疑问,无法调试错误。 我真的需要你帮助我。 谢谢

labels = []
for i in glob('C:\Users\SAHAR\conda_code\tamrin_deep_speech\train\audio\*\*.wav'):
    print("a")
    labels += [i.split('/')[-2]]
    print("b")
labels = np.unique(np.array(labels), return_counts=True)

d = {}
for i in range(len(labels[0])):
    d[labels[0][i]] = labels[1][i]
print(d)

    IndexError                                Traceback (most recent call last)
<ipython-input-9-ecc5faf1bf75> in <module>
      2 for i in glob('C:\Users\SAHAR\conda_code\tamrin_deep_speech\train\audio\*\*.wav'):
      3     print("a")
----> 4     labels += [i.split('/')[-2]]
      5     print("b")
      6 labels = np.unique(np.array(labels), return_counts=True)

IndexError: list index out of range

the source of the code

在 windows 上,路径分隔符是“\”而不是“/”。 尝试使用:

labels += [i.split('\')[-2]]

当您在“/”上拆分字符串时。只需检查拆分后的列表是否包含元素。看起来在你的情况下,拆分后的一些列表是空的