tyiannak / pyAudioAnalysis

Python Audio Analysis Library: Feature Extraction, Classification, Segmentation and Applications
Apache License 2.0
5.9k stars 1.2k forks source link

error in audioTrainTest.extract_features_and_train if class folder contain only 1 sample #378

Closed JohnYeung-dojjy closed 2 years ago

JohnYeung-dojjy commented 2 years ago
295 for feat in features:
296         temp = []
297         for i in range(feat.shape[0]):
298             temp_fv = feat[i, :]

if one of the class folder has only 1 sample, feat will be an 1d array of shape (, 136). And line 398 will give an error as it tries to access 1d array with 2d indices (feat[i, :])

I propose the following fix

for feat in features:
    if feat.ndim == 1: # this class has only 1 sample
        feat = feat.reshape((1, feat.shape[0]))
    temp = []
    for i in range(feat.shape[0]):
        temp_fv = feat[i, :]