tyiannak / pyAudioAnalysis

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

ValueError: operands could not be broadcast together with shapes (5,5) (4,4) #368

Closed MiPlayer123 closed 2 years ago

MiPlayer123 commented 2 years ago

I am geting the following error when running aT.extract_features_and_train(["<path>\Audio Classification\BabyCry","<path>\Audio Classification\GlassBreaking", "<path>\Audio Classification\Gunshot", "<path>\Audio Classification\Falling", "<path>\Audio Classification\Background"], 1.0, 1.0, aT.shortTermWindow, aT.shortTermStep, "randomforest", "randomForest2", False). All the data in the folders are .wav files

<more outputs>
Feature extraction complexity ratio: 26.6 x realtime
Analyzing file 1 of 3: <path>\Audio Classification\Background\2019-05-24-12-26-34-355000__1.wav
Analyzing file 2 of 3: <path>\Audio Classification\Background\2019-05-24-12-26-34-355000__22.wav
Analyzing file 3 of 3:<path>\Audio Classification\Background\2019-05-24-12-26-34-355000__24.wav
Feature extraction complexity ratio: 25.8 x realtime
Param = 10.00000 - classifier Evaluation Experiment 1 of 26
Traceback (most recent call last):
  File "<path>\main.py", line 3, in <module>
    aT.extract_features_and_train(["<path>\Audio Classification\BabyCry","<path>\GlassBreaking", "D:\Research\Datasets\Audio Classification\Gunshot", "<path>\Audio Classification\Falling", "<path>\Audio Classification\Background"], 1.0, 1.0, aT.shortTermWindow, aT.shortTermStep, "randomforest", "randomForest2", False)
  File "<path>t\anaconda3\lib\site-packages\pyAudioAnalysis\audioTrainTest.py", line 298, in extract_features_and_train
    best_param = evaluate_classifier(features, class_names, classifier_type,
  File "<path>\anaconda3\lib\site-packages\pyAudioAnalysis\audioTrainTest.py", line 623, in evaluate_classifier
    cm = cm + cmt
ValueError: operands could not be broadcast together with shapes (5,5) (4,4) 
tyiannak commented 2 years ago

You are not using the latest version of the library. That is an old bug that should be fixed by now (it randomly happened when few samples existed in any of the classes). But, in any case this is fixed in the latest version of the library, so please update your dependencies.

MiPlayer123 commented 2 years ago

I updated the library, but I am running into new errors:

Param = 10.00000 - classifier Evaluation Experiment 81 of 127
Param = 10.00000 - classifier Evaluation Experiment 82 of 127
Param = 10.00000 - classifier Evaluation Experiment 83 of 127
Param = 10.00000 - classifier Evaluation Experiment 84 of 127
Param = 10.00000 - classifier Evaluation Experiment 85 of 127
Param = 10.00000 - classifier Evaluation Experiment 86 of 127
Param = 10.00000 - classifier Evaluation Experiment 87 of 127
Param = 10.00000 - classifier Evaluation Experiment 88 of 127
Param = 10.00000 - classifier Evaluation Experiment 89 of 127
Traceback (most recent call last):
  File "D:\Research\Scripts\main.py", line 3, in <module>
    aT.extract_features_and_train(["<path>\Audio Classification\BabyCry","<path>\Audio Classification\GlassBreaking", "<path>\Audio Classification\Gunshot", "<path>\Audio Classification\Falling", "<path>\Audio Classification\Background"], 1.0, 1.0, aT.shortTermWindow, aT.shortTermStep, "randomforest", "randomForest2", False)
  File "<path>\anaconda3\lib\site-packages\pyAudioAnalysis\audioTrainTest.py", line 307, in extract_features_and_train
    best_param = evaluate_classifier(features, class_names, classifier_type,
  File <path>\anaconda3\lib\site-packages\pyAudioAnalysis\audioTrainTest.py", line 694, in evaluate_classifier
    cmt = np.insert(cmt, missing_classes, 0, axis=0)
  File "<__array_function__ internals>", line 5, in insert
  File "<path>\anaconda3\lib\site-packages\numpy\lib\function_base.py", line 4672, in insert
    old_mask[indices] = False
IndexError: index 5 is out of bounds for axis 0 with size 5

Is there a way I can resolve these issues by modifying my dataset, or is it a bug?

tyiannak commented 2 years ago

Is it possible to send me the data so that I can reproduce the error?

MiPlayer123 commented 2 years ago

I figured out the issue. I only had 4 files in one of the folders while the rest had hundreds, but as soon as I added a lot more files to it worked. Let me know if you would still like the data.

tyiannak commented 2 years ago

Thank for the answer @MiPlayer123 . No need to send me the data. I've added a new issue to add an error if number of samples if is not sufficient.