所以我试图使用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]
应该返回数组维度的列。
但为什么它会在这里返回错误
答案 0 :(得分:2)
好的,我发现了问题。
问题是我的一个分类器没有足够的文件,它需要至少2.所以在添加更多文件之后再次工作了!
答案 1 :(得分:0)
同样的问题可能是由于培训文件夹中的文件数量不同 例如:
+Training
+Bubble - 6 files
+glass - 6 files
+bounce - 8 files
然后它也会生成相同的错误,因为它无法生成所需的数组矩阵(在dirsWavFeatureExtraction
内使用audioFeatureExtraction.py
函数。)
我找到的解决方案是训练文件夹中应该有相同数量的文件
已解决的例子:
+Training
+Bubble - 6 files
+glass - 6 files
+bounce - 6 files