refactored testing suite file to no longer depend on file naming convention

This commit is contained in:
Will Drevo 2014-07-01 20:24:53 -04:00
parent 4f4a50ba9f
commit b966225ad4
15 changed files with 29 additions and 43 deletions

0
.gitignore vendored Normal file → Executable file
View file

0
DEPENDENCIES.md Normal file → Executable file
View file

0
LICENSE.md Normal file → Executable file
View file

0
README.md Normal file → Executable file
View file

0
dejavu.cnf.SAMPLE Normal file → Executable file
View file

0
dejavu/database_sql.py Normal file → Executable file
View file

0
dejavu/decoder.py Normal file → Executable file
View file

0
example.py Normal file → Executable file
View file

0
plots/accuracy.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

0
plots/blurred_lines_vertical.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 296 KiB

After

Width:  |  Height:  |  Size: 296 KiB

0
plots/matching_time.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

0
plots/spectrogram_peaks.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 498 KiB

After

Width:  |  Height:  |  Size: 498 KiB

0
plots/spectrogram_zoomed.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 405 KiB

After

Width:  |  Height:  |  Size: 405 KiB

0
scripts/generate-test-files.py Normal file → Executable file
View file

64
scripts/results_dejavu.py → test.py Normal file → Executable file
View file

@ -11,6 +11,8 @@ import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.animation as animation import matplotlib.animation as animation
from optparse import OptionParser from optparse import OptionParser
from dejavu.decoder import path_to_songname
import ast
##### #####
### Test files are in specific format: ### Test files are in specific format:
@ -21,42 +23,35 @@ DEFAULT_FS = 44100
DEFAULT_WINDOW_SIZE = 4096 DEFAULT_WINDOW_SIZE = 4096
DEFAULT_OVERLAP_RATIO = 0.5 DEFAULT_OVERLAP_RATIO = 0.5
#FIELD_SONG_ID = 'song_id'
FIELD_SONG_NAME = 'song_name' FIELD_SONG_NAME = 'song_name'
FIELD_CONFIDENCE = 'confidence' FIELD_CONFIDENCE = 'confidence'
FIELD_QUERY_TIME = 'match_time' FIELD_QUERY_TIME = 'match_time'
FIELD_OFFSET = 'offset' FIELD_OFFSET = 'offset'
# Parse options # Parse options
usage = "usage: %prog [options] DEJAVU_PATH TEST_FOLDER" usage = "usage: %prog [options] DEJAVU_PATH TEST_FOLDER"
parser = OptionParser(usage=usage, version="%prog 1.1") parser = OptionParser(usage=usage, version="%prog 1.1")
parser.add_option("--no-log", parser.add_option("--no-log",
action="store_false", action="store_false",
dest="log", dest="log",
default=True, default=True,
help='Disables logging' help='Disables logging')
)
parser.add_option("--log-file", parser.add_option("--log-file",
dest="log_file", dest="log_file",
default="results-compare.log", default="results-compare.log",
metavar="LOG_FILE", metavar="LOG_FILE",
help='Set the path and filename of the log file' help='Set the path and filename of the log file')
)
parser.add_option("--test-seconds", parser.add_option("--test-seconds",
action="append", action="append",
dest="test_seconds", dest="test_seconds",
default=[], default=[],
metavar="Xsec", metavar="Xsec",
help='Appends seconds to test suit' help='Appends seconds to test suit')
)
parser.add_option("--results-folder", parser.add_option("--results-folder",
action="store", action="store",
dest="results_folder", dest="results_folder",
metavar="FOLDER", metavar="FOLDER",
help='Sets the path where the results are saved' help='Sets the path where the results are saved')
)
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -72,6 +67,7 @@ if options.log == True:
if options.results_folder != "" and options.results_folder[len(options.results_folder) - 1] != '/': if options.results_folder != "" and options.results_folder[len(options.results_folder) - 1] != '/':
options.results_folder += "/" options.results_folder += "/"
# ensure results folder exists
try: try:
os.stat(options.results_folder) os.stat(options.results_folder)
except: except:
@ -96,6 +92,11 @@ class DejavuTest (object):
# variable match results (yes, no, invalid) # variable match results (yes, no, invalid)
self.result_match = [[0 for x in xrange(self.n_columns)] for x in xrange(self.n_lines)] self.result_match = [[0 for x in xrange(self.n_columns)] for x in xrange(self.n_lines)]
print "columns:", self.n_columns
print "length of test files:", len(self.test_files)
print "lines:", self.n_lines
print "result_match matrix:", self.result_match
# variable match precision (if matched in the corrected time) # variable match precision (if matched in the corrected time)
self.result_matching_times = [[0 for x in xrange(self.n_columns)] for x in xrange(self.n_lines)] self.result_matching_times = [[0 for x in xrange(self.n_columns)] for x in xrange(self.n_lines)]
@ -112,33 +113,23 @@ class DejavuTest (object):
if secs == sec: if secs == sec:
return i return i
def get_line_id ( self,artist, song ): def get_line_id (self, song):
elem = artist + " - " + song
for i, s in enumerate(self.test_songs): for i, s in enumerate(self.test_songs):
if elem == s: if song == s:
return i return i
self.test_songs.append(song)
self.test_songs.append(elem)
return len(self.test_songs) - 1 return len(self.test_songs) - 1
def begin(self): def begin(self):
for f in self.test_files: for f in self.test_files:
log_msg('--------------------------------------------------') log_msg('--------------------------------------------------')
log_msg('file: %s' % f) log_msg('file: %s' % f)
# get column # get column
col = self.get_column_id(re.findall("[0-9]*sec",f)[0]) col = self.get_column_id(re.findall("[0-9]*sec",f)[0])
song = path_to_songname(f).split("_")[0] # format: XXXX_offset_length.mp3
# get artist and song line = self.get_line_id (song)
artist = re.findall("^[^\-]+",f) result = subprocess.check_output(["python", args[0] + "/dejavu.py", 'recognize', 'file', self.test_folder+"/"+f])
artist = artist[0].rstrip()
song = re.findall("\-[^\_]+",f)
song = song[0].lstrip("- ")
line = self.get_line_id ( artist, song)
result = subprocess.check_output([args[0], 'recognize', 'file', self.test_folder+"/"+f])
log_msg('RESULT: %s' % result.strip() ) log_msg('RESULT: %s' % result.strip() )
if result.strip() == "None": if result.strip() == "None":
@ -155,20 +146,14 @@ class DejavuTest (object):
result = result.replace("\':", '":') result = result.replace("\':", '":')
result = result.replace("\',", '",') result = result.replace("\',", '",')
result = json.loads(result) # which song did we predict?
result = ast.literal_eval(result)
artist_result = re.findall("^[^\-]+",result[FIELD_SONG_NAME]) print "result", result
artist_result = artist_result[0].rstrip() song_result = result["song_name"]
song_result = re.findall("\-[^\_]+",result[FIELD_SONG_NAME])
song_result = song_result[0].lstrip("- ")
log_msg('artist: %s' % artist)
log_msg('artist_result: %s' % artist_result)
log_msg('song: %s' % song) log_msg('song: %s' % song)
log_msg('song_result: %s' % song_result) log_msg('song_result: %s' % song_result)
if artist_result != artist or song_result != song: if song_result != song:
log_msg('invalid match') log_msg('invalid match')
self.result_match[line][col] = 'invalid' self.result_match[line][col] = 'invalid'
self.result_matching_times[line][col] = 0 self.result_matching_times[line][col] = 0
@ -176,6 +161,7 @@ class DejavuTest (object):
self.result_match_confidence[line][col] = 0 self.result_match_confidence[line][col] = 0
else: else:
log_msg('correct match') log_msg('correct match')
print self.result_match
self.result_match[line][col] = 'yes' self.result_match[line][col] = 'yes'
self.result_query_duration[line][col] = round(result[FIELD_QUERY_TIME],3) self.result_query_duration[line][col] = round(result[FIELD_QUERY_TIME],3)
self.result_match_confidence[line][col] = result[FIELD_CONFIDENCE] self.result_match_confidence[line][col] = result[FIELD_CONFIDENCE]