Skip to content

Added max_files parameter to extract_features_and_train #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pyAudioAnalysis/MidTermFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = sorted(wav_file_list)
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,
Expand Down Expand Up @@ -217,7 +218,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.
Expand All @@ -242,7 +243,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)
Expand Down
4 changes: 2 additions & 2 deletions pyAudioAnalysis/audioTrainTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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!")
Expand Down