Browse Source

Move feature extraction to separate folder, Init batch_feature_extractor

master
Apostolos Fanakis 6 years ago
parent
commit
32d4297c89
No known key found for this signature in database GPG Key ID: 56CE2DEDE9F1FB78
  1. 20
      classifier/feature_extraction/README.md
  2. BIN
      classifier/feature_extraction/__pycache__/feature_extractor.cpython-36.pyc
  3. 17
      classifier/feature_extraction/batch_feature_extractor.py
  4. 14
      classifier/feature_extraction/feature_extractor.py

20
classifier/README.md → classifier/feature_extraction/README.md

@ -1,16 +1,20 @@
# Feature extraction
The file `feature_extractor` is a python module that uses the open-source library [Essentia](http://essentia.upf.edu/documentation/index.html) to extract audio features from a file in the path specified in the first parameter and save the features' values to a binary file in the path specified in the second parameter.
The file `feature_extractor` is a python module that uses the open-source library [Essentia](http://essentia.upf.edu/documentation/index.html) to extract audio features from an audio file in the path specified in the first parameter and save the features' values to a json file in the path specified in the second parameter.
The module can be imported or executed as a script using one of the following commands
`python feature_extractor.py <audio_file_path> <extracted_features_file_path> <audio_file_sample_rate>`
or
`python3 feature_extractor.py <audio_file_path> <extracted_features_file_path> <audio_file_sample_rate>`
A python script is also provided for a batch feature extraction. The script can be executed using one of the following commands:
`python batch_feature_extractor.py <audio_files_directory> <feature_files_directory> <audio_files_sample_rate>`
or
`python3 batch_feature_extractor.py <audio_files_directory> <feature_files_directory> <audio_files_sample_rate>`
**Dependencies:**
- essentia
- numpy
- scipy
- matplotlib
All dependencies are available both for python2 and python3 versions and can all be installed using the commands `pip install <package_name>` or `pip3 install <package_name>` for python2 and python3 respectively.
The module can be imported or executed as a script using one of the following commands
`python feature_extractor.py <audio_file_path> <extracted_features_file_path> <audio_file_sample_rate>`
or
`python3 feature_extractor.py <audio_file_path> <extracted_features_file_path> <audio_file_sample_rate>`
All dependencies are available both for python2 and python3 versions and can all be installed using the commands `pip install <package_name>` or `pip3 install <package_name>` for python2 and python3 respectively.

BIN
classifier/feature_extraction/__pycache__/feature_extractor.cpython-36.pyc

Binary file not shown.

17
classifier/feature_extraction/batch_feature_extractor.py

@ -0,0 +1,17 @@
import sys
from os import listdir
from os.path import isfile, join
import multiprocessing as mp
from feature_extractor import extractFeatures
audioFiles = [file for file in listdir(sys.argv[1]) if isfile(join(sys.argv[1], file))]
# Without multithreading
# for file in audioFiles:
# extractFeatures(sys.argv[1] + file,
# sys.argv[2] + file[0:file.rfind('.')] + '.json', int(sys.argv[3]))
pool = mp.Pool(processes = 8)
[pool.apply(extractFeatures, args=(sys.argv[1] + file,
sys.argv[2] + file[0:file.rfind('.')] + '.json',
int(sys.argv[3]))) for file in audioFiles]

14
classifier/feature_extractor.py → classifier/feature_extraction/feature_extractor.py

@ -1,13 +1,15 @@
# import essentia.standard
import essentia
import essentia.standard
from essentia.standard import *
import essentia.streaming
from pylab import plot, show, figure, imshow
import matplotlib.pyplot as plt
from essentia.standard import (MonoLoader, Windowing, Spectrum, MFCC,
ZeroCrossingRate, SpectralCentroidTime, RollOff, Flux, FrameGenerator,
YamlOutput)
# Disable annoying info level logging
essentia.log.infoActive = False
def extractFeatures(audioPath, outputPath, sampleRate):
# Loads the audio file specified
loader = essentia.standard.MonoLoader(filename = audioPath, sampleRate = sampleRate)
loader = MonoLoader(filename = audioPath, sampleRate = sampleRate)
audio = loader()
# Sets up the functions that will be used
Loading…
Cancel
Save