From 2508b8eed68c192f109301acfae011ac6833e085 Mon Sep 17 00:00:00 2001 From: Koba Khitalishvili Date: Wed, 9 Sep 2020 14:55:11 -0400 Subject: [PATCH 1/5] added max files per folder parameter --- pyAudioAnalysis/MidTermFeatures.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyAudioAnalysis/MidTermFeatures.py b/pyAudioAnalysis/MidTermFeatures.py index 543fca0f6..c44c1c239 100644 --- a/pyAudioAnalysis/MidTermFeatures.py +++ b/pyAudioAnalysis/MidTermFeatures.py @@ -134,7 +134,7 @@ def mid_feature_extraction(signal, sampling_rate, mid_window, mid_step, def directory_feature_extraction(folder_path, mid_window, mid_step, short_window, short_step, - compute_beat=True): + compute_beat=True, max_files=1000): """ This function extracts the mid-term features of the WAVE files of a particular folder. @@ -157,7 +157,7 @@ def directory_feature_extraction(folder_path, mid_window, mid_step, for files in types: wav_file_list.extend(glob.glob(os.path.join(folder_path, files))) - wav_file_list = sorted(wav_file_list) + wav_file_list = sorted(wav_file_list)[0:max_files] wav_file_list2, mid_feature_names = [], [] for i, file_path in enumerate(wav_file_list): print("Analyzing file {0:d} of {1:d}: {2:s}".format(i + 1, @@ -217,7 +217,7 @@ def directory_feature_extraction(folder_path, mid_window, mid_step, def multiple_directory_feature_extraction(path_list, mid_window, mid_step, short_window, short_step, - compute_beat=False): + compute_beat=False, max_files = 1000): """ Same as dirWavFeatureExtraction, but instead of a single dir it takes a list of paths as input and returns a list of feature matrices. @@ -242,7 +242,7 @@ def multiple_directory_feature_extraction(path_list, mid_window, mid_step, f, fn, feature_names = \ directory_feature_extraction(d, mid_window, mid_step, short_window, short_step, - compute_beat=compute_beat) + compute_beat=compute_beat, max_files=max_files) if f.shape[0] > 0: # if at least one audio file has been found in the provided folder: features.append(f) From c58a4ff7d8947149403835f65774b13d43302f4f Mon Sep 17 00:00:00 2001 From: Koba Khitalishvili Date: Wed, 9 Sep 2020 14:57:07 -0400 Subject: [PATCH 2/5] added max_files per folder parameter --- pyAudioAnalysis/audioTrainTest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyAudioAnalysis/audioTrainTest.py b/pyAudioAnalysis/audioTrainTest.py index 524b7e184..ca421ec58 100644 --- a/pyAudioAnalysis/audioTrainTest.py +++ b/pyAudioAnalysis/audioTrainTest.py @@ -282,7 +282,7 @@ def train_random_forest_regression(features, labels, n_estimators): def extract_features_and_train(paths, mid_window, mid_step, short_window, short_step, classifier_type, model_name, - compute_beat=False, train_percentage=0.90): + compute_beat=False, train_percentage=0.90, max_files = 1000): """ This function is used as a wrapper to segment-based audio feature extraction and classifier training. @@ -304,7 +304,7 @@ def extract_features_and_train(paths, mid_window, mid_step, short_window, features, class_names, _ = \ aF.multiple_directory_feature_extraction(paths, mid_window, mid_step, short_window, short_step, - compute_beat=compute_beat) + compute_beat=compute_beat, max_files=max_files) if len(features) == 0: print("trainSVM_feature ERROR: No data found in any input folder!") From c2ee9ea09a360b0098336606a9b6f48259d0399d Mon Sep 17 00:00:00 2001 From: Koba Khitalishvili Date: Wed, 9 Sep 2020 20:53:23 -0400 Subject: [PATCH 3/5] random max file selection --- pyAudioAnalysis/MidTermFeatures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyAudioAnalysis/MidTermFeatures.py b/pyAudioAnalysis/MidTermFeatures.py index c44c1c239..324df3790 100644 --- a/pyAudioAnalysis/MidTermFeatures.py +++ b/pyAudioAnalysis/MidTermFeatures.py @@ -157,7 +157,7 @@ def directory_feature_extraction(folder_path, mid_window, mid_step, for files in types: wav_file_list.extend(glob.glob(os.path.join(folder_path, files))) - wav_file_list = sorted(wav_file_list)[0:max_files] + wav_file_list = np.random.shuffle(sorted(wav_file_list))[0:max_files] wav_file_list2, mid_feature_names = [], [] for i, file_path in enumerate(wav_file_list): print("Analyzing file {0:d} of {1:d}: {2:s}".format(i + 1, From 4c20d4cb7b97646cada67d2acf207d2f7863788e Mon Sep 17 00:00:00 2001 From: Koba Khitalishvili Date: Wed, 9 Sep 2020 21:18:56 -0400 Subject: [PATCH 4/5] added random choice of files in folder --- pyAudioAnalysis/MidTermFeatures.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyAudioAnalysis/MidTermFeatures.py b/pyAudioAnalysis/MidTermFeatures.py index 324df3790..eb55535f0 100644 --- a/pyAudioAnalysis/MidTermFeatures.py +++ b/pyAudioAnalysis/MidTermFeatures.py @@ -157,7 +157,8 @@ def directory_feature_extraction(folder_path, mid_window, mid_step, for files in types: wav_file_list.extend(glob.glob(os.path.join(folder_path, files))) - wav_file_list = np.random.shuffle(sorted(wav_file_list))[0:max_files] + wav_file_list = sorted(wav_file_list)[0:max_files] + np.random.shuffle(wav_file_list) wav_file_list2, mid_feature_names = [], [] for i, file_path in enumerate(wav_file_list): print("Analyzing file {0:d} of {1:d}: {2:s}".format(i + 1, From f4d7140aa0a8d0c5692adc076ca5c2c1efb547bb Mon Sep 17 00:00:00 2001 From: Koba Khitalishvili Date: Wed, 9 Sep 2020 21:19:07 -0400 Subject: [PATCH 5/5] added random choice of files in folder