From 32d4297c891522315a99a28405ed14bbba88cd52 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 1 Dec 2018 21:02:31 +0200 Subject: [PATCH] Move feature extraction to separate folder, Init batch_feature_extractor --- classifier/{ => feature_extraction}/README.md | 20 +++++++++++------- .../feature_extractor.cpython-36.pyc | Bin 0 -> 1536 bytes .../batch_feature_extractor.py | 17 +++++++++++++++ .../feature_extractor.py | 14 ++++++------ 4 files changed, 37 insertions(+), 14 deletions(-) rename classifier/{ => feature_extraction}/README.md (51%) create mode 100644 classifier/feature_extraction/__pycache__/feature_extractor.cpython-36.pyc create mode 100644 classifier/feature_extraction/batch_feature_extractor.py rename classifier/{ => feature_extraction}/feature_extractor.py (80%) diff --git a/classifier/README.md b/classifier/feature_extraction/README.md similarity index 51% rename from classifier/README.md rename to classifier/feature_extraction/README.md index d507e21..9c81058 100644 --- a/classifier/README.md +++ b/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 ` +or +`python3 feature_extractor.py ` + +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 ` +or +`python3 batch_feature_extractor.py ` **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 ` or `pip3 install ` 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 ` -or -`python3 feature_extractor.py ` \ No newline at end of file +All dependencies are available both for python2 and python3 versions and can all be installed using the commands `pip install ` or `pip3 install ` for python2 and python3 respectively. \ No newline at end of file diff --git a/classifier/feature_extraction/__pycache__/feature_extractor.cpython-36.pyc b/classifier/feature_extraction/__pycache__/feature_extractor.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1323d3fd9201141547436f14b150a1d289a1b640 GIT binary patch literal 1536 zcma)6Pj4eN6u0MJJd;07+OE_Eg!Y;P%_2A=V3iW~KzFOQqQU}2R_tjeJ01ty>9*D6 zLJ+rJ;8XCGd__X)SK!3+q*SXt;gR3(&3kX`=l6b|&$`|0V;B7RM+>39&^sdm{cD)! zHxL|gTq5c*D6tG^AVV6;h(gDK!%qh(Lg25&-G37?^1`yO&ZuZEe+j#Z_; zQ;ZAk(u<TOY7I&!uYGpkq9MaPrz*!8KIl{%Jmnd0-^EAhr+VG3t0Rj9^g)$HrTI|1_yOk55T@#w;SB6TON7m zDO&H>okg2>>zz%2QKR?j{-eHA?>_4Ndhbym)caold3k|sr^b92&bD_K)*atgj-W~V zuZDpmc~OcAis&-K%%1AVgbpCMEP^7}2a!TC%dZ72HJzz(w|EDQJ2NeLI;m zBZdJ@iwX*V243BTS`Tpp1?nJlewjDp@2_C7H1}Qeaj=D2HcHo6rtL&4>6t(eu3$6X zboYF&g_*08LuQ4#hyEcN((x$`&c-l3PFy7O*^EXDqpD%3VMFAS+^1}5=dCWR_+DsJ zfU~OuaB9yD9eELZ;qQ?49MQy!6oezf7@%IkTy&yTsWWd38RxnU+VBZY*@_qHgxNXG zRKq#1H)nQ9*-)OwO$<$d^uT;d%meN90M?-4?M&0a%v@kR0;`v>lZ%`B(C+plu`L57 zTPqyAwXNTncDKsIn*Z4!117ZX%QBrQk>}=5q(6X7|G6H`l@uekRK}`O<)fEJN1u)^ zlzwBDY$nX;cvafsq-53?@Y#u03%IIgbpG<2PhPBHrX+j$6>Y~zhDv-unZ3OYE62qrkepy3RjBqU*mdjSc-?k6TeC+vXV zKm9;|1mE2rytlW~&zj0}N2XKBifTI5eF(hwUBCBTAMWct0Qi+XwD%C0S8=BK|7AwQ zgoXqzEY&5=iYiwx;M`ZDNy^1bT~yX*;4jv6>Oym4T*UO{l?%bs^x+-xA>`x87gF(6 UDZccXnjQ#(pGPDhhuhQt3j)`pHvj+t literal 0 HcmV?d00001 diff --git a/classifier/feature_extraction/batch_feature_extractor.py b/classifier/feature_extraction/batch_feature_extractor.py new file mode 100644 index 0000000..7c65815 --- /dev/null +++ b/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] diff --git a/classifier/feature_extractor.py b/classifier/feature_extraction/feature_extractor.py similarity index 80% rename from classifier/feature_extractor.py rename to classifier/feature_extraction/feature_extractor.py index ef09ffe..a29190c 100644 --- a/classifier/feature_extractor.py +++ b/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