pyAudioAnalysis,元组索引超出范围

pyAudioAnalysis, Tuple index out of range

所以我正在尝试使用 pyAudioAnalysis library 制作一个基本的情绪分类器,并且我收集了一个小数据样本来测试它是否有效。我的代码如下:

from pyAudioAnalysis import audioAnalysis as aA   

aA.trainClassifierWrapper('svm', False,
                      ["C:\Users\gover_000\Desktop\Angry",
                      "C:\Users\gover_000\Desktop\Happy",
                      "C:\Users\gover_000\Desktop\Sad",
                      "C:\Users\gover_000\Desktop\Scared",
                      "C:\Users\gover_000\Desktop\Neutral"],
                      "testSVM")

如果我执行这个,它会给出这个错误:

Traceback (most recent call last) <ipython-input-7-2e5393432e89> in <module>()
  5                       "C:\Users\gover_000\Desktop\Scared",
  6                       "C:\Users\gover_000\Desktop\Neutral"],
----> 7                       "testSVM")

C:\Users\gover_000\Documents\GitHub\Emotion-Recognition-Prototype\pyAudioAnalysis\audioAnalysis.pyc in trainClassifierWrapper(method, beatFeatures, directories, modelName)
     88         raise Exception("At least 2 directories are needed")
     89     aT.featureAndTrain(directories, 1, 1, aT.shortTermWindow, aT.shortTermStep,
---> 90                        method.lower(), modelName, computeBEAT=beatFeatures)
     91 
     92 

C:\Users\gover_000\Documents\GitHub\Emotion-Recognition-Prototype\pyAudioAnalysis\audioTrainTest.pyc in featureAndTrain(listOfDirs, mtWin, mtStep, stWin, stStep, classifierType, modelName, computeBEAT, perTrain)
    275     featureNames = ["features" + str(d + 1) for d in range(numOfFeatures)]
    276 
--> 277     writeTrainDataToARFF(modelName, features, classNames, featureNames)
    278 
    279     for i, f in enumerate(features):

C:\Users\gover_000\Documents\GitHub\Emotion-Recognition-Prototype\pyAudioAnalysis\audioTrainTest.pyc in writeTrainDataToARFF(modelName, features, classNames, featureNames)
   1097     for c, fe in enumerate(features):
   1098         for i in range(fe.shape[0]):
-> 1099             for j in range(fe.shape[1]):
   1100                 f.write("{0:f},".format(fe[i, j]))
   1101             f.write(classNames[c]+"\n")

IndexError: tuple index out of range

我知道 shape[1] 应该 return 数组维度的列。 但为什么 return 这里出错

好的,我找到问题了。

问题是我的一个分类器没有足够的文件,它至少需要 2 个。所以在添加更多后它再次工作!

同样的问题可能是由于训练文件夹中的文件数量不同 例如:

+Training
  +Bubble - 6 files
  +glass - 6 files
  +bounce - 8 files

那么它也会产生相同的错误,因为它无法生成所需的数组矩阵(在 audioFeatureExtraction.py 中使用 dirsWavFeatureExtraction 函数)。

我找到的解决方案是训练文件夹中的文件数量应该相同

已解决的示例:

+Training
  +Bubble - 6 files
  +glass - 6 files
  +bounce - 6 files