History

updated to new bench-pitch, fixed gettruth updated to new bench-pitch, fixed gettruth

Paul Brossier committed 20 years ago

Commit 5d1c0701 parent 43938de3 files · +142 −55Browse files

Showing the changes to python (3 of 3 files). Show all

Unified · Split

3 files
  1. python/aubio/bench/node.py +1 −1
  2. python/aubio/task/pitch.py +34 −12
  3. python/test/bench/pitch/bench-pitch +107 −42
python/aubio/bench/node.py+1−1
@@ -25,7 +25,7 @@ def list_files(datapath,filter='f', maxdepth = -1): · 24 unmodified lines
25 sys.exit(1)25 sys.exit(1)
26 if maxdepth >= 0: maxstring = " -maxdepth %d " % maxdepth 26 if maxdepth >= 0: maxstring = " -maxdepth %d " % maxdepth
27 else: maxstring = ""27 else: maxstring = ""
28 cmd = '%s' * 5 % ('find ',datapath,maxstring,' -type ',filter)28 cmd = '%s' * 6 % ('find ',datapath,maxstring,' -type ',filter, "| sort -n")
29 return runcommand(cmd)29 return runcommand(cmd)
30 30
31def list_wav_files(datapath,maxdepth = -1):31def list_wav_files(datapath,maxdepth = -1):
python/aubio/task/pitch.py+34−12
@@ -60,9 +60,9 @@ class taskpitch(task): · 59 unmodified lines
60 return False,False60 return False,False
61 elif floatpit:61 elif floatpit:
62 try:62 try:
63 self.truth = aubio_miditofreq(float(floatpit))63 self.truth = float(floatpit)
64 print "ground truth found in filename:", self.truth64 #print "ground truth found in filename:", self.truth
65 tasksil = tasksilence(self.input)65 tasksil = tasksilence(self.input,params=self.params)
66 time,pitch =[],[]66 time,pitch =[],[]
67 while(tasksil.readsize==tasksil.params.hopsize):67 while(tasksil.readsize==tasksil.params.hopsize):
68 tasksil()68 tasksil()
@@ -83,10 +83,10 @@ class taskpitch(task): · 14 unmodified lines
83 time, pitch = [], []83 time, pitch = [], []
84 for i in range(len(values)):84 for i in range(len(values)):
85 time.append(values[i][0])85 time.append(values[i][0])
86 pitch.append(values[i][1])86 pitch.append(aubio_freqtomidi(values[i][1]))
87 return time,pitch87 return time,pitch
88 88
89 def eval(self,results):89 def oldeval(self,results):
90 def mmean(l):90 def mmean(l):
91 return sum(l)/max(float(len(l)),1)91 return sum(l)/max(float(len(l)),1)
92 92
@@ -104,23 +104,44 @@ class taskpitch(task): · 11 unmodified lines
104 med = percental(res,len(res)/2) 104 med = percental(res,len(res)/2)
105 return self.truth, self.truth-med, self.truth-avg105 return self.truth, self.truth-med, self.truth-avg
106 106
107 def neweval(self,results):107 def eval(self,pitch,tol=0.9):
108 timet,pitcht = self.gettruth()108 timet,pitcht = self.gettruth()
109 for i in timet:109 pitch = [aubio_freqtomidi(i) for i in pitch]
110 print results[i]110 for i in range(len(pitch)):
111 return self.truth, self.truth-med, self.truth-avg111 if pitch[i] == "nan" or pitch[i] == -1:
112 pitch[i] = -1
113 time = [ i*self.params.step for i in range(len(pitch)) ]
114 assert len(timet) == len(time)
115 assert len(pitcht) == len(pitch)
116 osil, esil, opit, epit, echr = 0, 0, 0, 0, 0
117 for i in range(len(pitcht)):
118 if pitcht[i] == -1: # currently silent
119 osil += 1 # count a silence
120 if pitch[i] == -1. or pitch[i] == "nan":
121 esil += 1 # found a silence
122 else:
123 opit +=1
124 if abs(pitcht[i] - pitch[i]) < tol:
125 epit += 1
126 echr += 1
127 elif abs(pitcht[i] - pitch[i]) % 12. < tol:
128 echr += 1
129 #else:
130 # print timet[i], pitcht[i], time[i], pitch[i]
131 #print "origsilence", "foundsilence", "origpitch", "foundpitch", "orig pitchroma", "found pitchchroma"
132 #print 100.*esil/float(osil), 100.*epit/float(opit), 100.*echr/float(opit)
133 return osil, esil, opit, epit, echr
112 134
113 def plot(self,pitch,wplot,oplots,outplot=None):135 def plot(self,pitch,wplot,oplots,outplot=None):
114 import numarray136 import numarray
115 import Gnuplot137 import Gnuplot
116 138
117 self.eval(pitch)
118 downtime = self.params.step*numarray.arange(len(pitch))139 downtime = self.params.step*numarray.arange(len(pitch))
119 oplots.append(Gnuplot.Data(downtime,pitch,with='lines',140 oplots.append(Gnuplot.Data(downtime,pitch,with='linespoints',
120 title=self.params.pitchmode))141 title=self.params.pitchmode))
121 142
122 143
123 def plotplot(self,wplot,oplots,outplot=None,multiplot = 1):144 def plotplot(self,wplot,oplots,outplot=None,multiplot = 0):
124 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot145 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
125 import re146 import re
126 import Gnuplot147 import Gnuplot
@@ -131,6 +152,7 @@ class taskpitch(task): · 4 unmodified lines
131 # check if ground truth exists152 # check if ground truth exists
132 timet,pitcht = self.gettruth()153 timet,pitcht = self.gettruth()
133 if timet and pitcht:154 if timet and pitcht:
155 pitcht = [aubio_miditofreq(i) for i in pitcht]
134 oplots = [Gnuplot.Data(timet,pitcht,with='lines',156 oplots = [Gnuplot.Data(timet,pitcht,with='lines',
135 title='ground truth')] + oplots157 title='ground truth')] + oplots
136 158
python/test/bench/pitch/bench-pitch+107−42
@@ -8,61 +8,104 @@ class benchpitch(bench): · 7 unmodified lines
8 """ list of values to store per file """8 """ list of values to store per file """
9 valuenames = ['mode']9 valuenames = ['mode']
10 """ list of lists to store per file """10 """ list of lists to store per file """
11 valuelists = ['orig', 'mean', 'med']11 valuelists = ['truth', 'osil', 'esil', 'opit', 'epit', 'echr',
12 'Msil', 'Mpit', 'Mchr']
12 """ list of values to print per dir """13 """ list of values to print per dir """
13 printnames = [ 'mode']14 printnames = [ 'mode', 'truth', 'Msil', 'Mpit', 'Mchr']
14 15
15 """ per dir """16 """ per dir """
16 formats = {'mode': "%12s" , 'thres': "%5.4s", 17 formats = {'mode': "%12s" ,
17 'dist': "%5.4s", 'prec': "%5.4s", 'recl': "%5.4s",18 'truth': "%s",
18 'Ttrue': "%5.4s", 'Tfp': "%5.4s", 'Tfn': "%5.4s", 19 'osil': "%s", 'esil': "%s",
19 'Tm': "%5.4s", 'Td': "%5.4s",20 'opit': "%s", 'epit': "%s", 'echr': "%s",
20 'aTtrue':"%5.4s", 'aTfp': "%5.4s", 'aTfn': "%5.4s", 21 'Msil': "%s", 'Mpit': "%s", 'Mchr': "%s"}
21 'aTm': "%5.4s", 'aTd': "%5.4s",
22 'mean': "%5.40s", 'smean': "%5.40s",
23 'amean': "%5.40s", 'samean': "%5.40s"}
24 22
25 def dir_eval(self):23 def dir_eval(self):
26 """ evaluate statistical data over the directory """24 """ evaluate statistical data over the directory """
27 v = self.v25 v = self.v
28
29 v['mode'] = self.params.pitchmode26 v['mode'] = self.params.pitchmode
30 27
31 def file_exec(self,input,output):28 def file_exec(self,input,output):
32 filetask = self.task(input,params=self.params)29 filetask = self.task(input,params=self.params)
33 computed_data = filetask.compute_all()30 computed_data = filetask.compute_all()
34 orig,mean,med = filetask.eval(computed_data)31 osil, esil, opit, epit, echr = filetask.eval(computed_data)
32 self.v['truth'].append(int(filetask.truth))
33 assert opit > 0
35 34
36 self.v['orig'].append(orig)35 self.v['osil'].append(osil)
37 self.v['mean'].append(mean)36 self.v['esil'].append(esil)
38 self.v['med'].append(med)37 self.v['opit'].append(opit)
38 self.v['epit'].append(epit)
39 self.v['echr'].append(echr)
40
41 self.v['Msil'].append(esil/float(osil)*100.)
42 self.v['Mpit'].append(epit/float(opit)*100.)
43 self.v['Mchr'].append(echr/float(opit)*100.)
39 #print results#, computed_data44 #print results#, computed_data
40 #print input, results, results - float(input.split('.')[-2])45 #print input, results, results - float(input.split('.')[-2])
41 46
42 def run_bench(self,modes=['schmitt']):47 def run_bench(self,modes=['schmitt']):
43 from os.path import basename48 from os.path import basename
44 d = []
45 self.modes = modes49 self.modes = modes
46 self.pretty_titles()50 self.pretty_titles()
51 d = []
47 for mode in self.modes:52 for mode in self.modes:
48 self.params.pitchmode = mode53 self.params.pitchmode = mode
49 self.dir_eval_print()54 self.dir_eval_print()
50 self.plotpitchtessiture(d,55 truth = [i for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
51 self.v['orig'], 56 allOsil = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
52 self.v['med'],57 allEsil = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
53 plottitle=self.v['mode'],58 allOpit = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
54 plotmode='points')59 allEpit = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
55 #d.append('beta = .25,orig(x) title \"-2 octave\"')60 allEchr = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
56 d.append('beta = .50,orig(x) title \"-1 octave\"')61 allMsil = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
57 d.append('beta = 1.0,orig(x) title \"original\"')62 allMpit = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
58 d.append('beta = 2.0,orig(x) title \"+1 octave\"')63 allMchr = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)]
59 title = basename(self.datadir)64 for i in range(len(self.v['truth'])):
65 allOsil[self.v['truth'][i]-min(self.v['truth'])] += self.v['osil'][i]
66 allEsil[self.v['truth'][i]-min(self.v['truth'])] += self.v['esil'][i]
67 allOpit[self.v['truth'][i]-min(self.v['truth'])] += self.v['opit'][i]
68 allEpit[self.v['truth'][i]-min(self.v['truth'])] += self.v['epit'][i]
69 allEchr[self.v['truth'][i]-min(self.v['truth'])] += self.v['echr'][i]
70 for i in range(len(truth)):
71 allMsil[i] = allEsil[i]/float(allOsil[i])*100.
72 allMpit[i] = allEpit[i]/float(allOpit[i])*100.
73 allMchr[i] = allEchr[i]/float(allOpit[i])*100.
74
75 plot = []
76 self.plotpitchtessiture(plot,
77 truth,
78 allMpit,
79 plottitle="%s %s" % (self.v['mode'],self.params.bufsize),
80 plotmode='lines')
81 self.plotpitchtessiture(plot,
82 truth,
83 allMchr,
84 plottitle="%s %s" % (self.v['mode'],"%12"),
85 plotmode='lines')
86 """
87 self.plotpitchtessiture(plot,
88 truth,
89 allMsil,
90 plottitle="%s %s" % (self.v['mode'],"sil"),
91 plotmode='lines')
92 """
93 title = basename(self.datadir)
94 d.append(plot)
60 outplot = "_-_".join(('pitchtessiture',title))95 outplot = "_-_".join(('pitchtessiture',title))
96 self.xmin = 20. #min(self.v['truth'])
97 self.xmax = 110. #max(self.v['truth'])
61 for ext in ('ps','png','svg',''):98 for ext in ('ps','png','svg',''):
62 self.plotplotpitchtessiture(d,99 self.plotplotpitchtessiture(d,
63 plottitle=title,100 plottitle="".join(['Performance against MIDI Note number (',
101 title,
102 ", %s" % len(self.sndlist), " samples)"]),
64 outplot=outplot,103 outplot=outplot,
65 extension=ext)104 extension=ext)
105 #d.append('beta = .25,orig(x) title \"-2 octave\"')
106 #d.append('beta = .50,orig(x) title \"-1 octave\"')
107 #d.append('beta = 1.0,orig(x) title \"original\"')
108 #d.append('beta = 2.0,orig(x) title \"+1 octave\"')
66 109
67 """110 """
68 Plot functions 111 Plot functions
@@ -72,18 +115,38 @@ class benchpitch(bench): · 3 unmodified lines
72 import Gnuplot, Gnuplot.funcutils115 import Gnuplot, Gnuplot.funcutils
73 d.append(Gnuplot.Data(lx, ly, with=plotmode, title="%s" % (plottitle) ))116 d.append(Gnuplot.Data(lx, ly, with=plotmode, title="%s" % (plottitle) ))
74 117
75 def plotplotpitchtessiture(self,d,plottitle='',outplot=0,extension=''):118 def plotplotpitchtessiture(self,d,plottitle='',outplot=0,extension='',multiplot=1):
76 from aubio.gnuplot import gnuplot_create119 from aubio.gnuplot import gnuplot_create
77 g = gnuplot_create(outplot=outplot,extension=extension) 120 g = gnuplot_create(outplot=outplot,extension=extension)
78 g.title(plottitle)121 #g.title(plottitle)
79 g('orig(x) = beta*x')122 #g('orig(x) = beta*x')
80 g.xlabel('original pitch (Hz)')123 #g.xlabel('original pitch (Hz)')
81 g.ylabel('detected pitch (Hz)')124 #g.ylabel('detected pitch (Hz)')
82 g('set key left top')125 #g('set key left top')
83 g('set log xy')126 #g('set log xy')
84 g('set xrange [50:2000]')127 #g('set xrange [50:2000]')
85 g('set yrange [50:2000]')128 g('set yrange [0:100]')
86 g.plot(*d)129 #g.plot(*d)
130 if multiplot:
131 g('set multiplot')
132 for i in range(len(d)):
133 # plot onset detection functions
134 g('set size 1,%f' % ( 1.0/float(len(d)) ) )
135 g('set origin 0,%f' % ( 1.0*float(len(d)-i-1)/float(len(d)) ) )
136 # erase axis
137 g('set border 3')
138 g('set xtics nomirror')
139 g('set ytics nomirror')
140 g('set key left top')
141 g('set xrange [%f:%f]' % (self.xmin,self.xmax)) #(self.xmax - (self.xmax-self.xmin)*5./4.,self.xmax))
142 #g.ylabel('%Correct detections')
143 if i == len(d)-1:
144 g.xlabel(plottitle)
145 g.plot(*d[i])
146 g('unset title')
147 g('unset multiplot')
148 else:
149 g.plot(*d)
87 150
88 151
89if __name__ == "__main__":152if __name__ == "__main__":
@@ -93,13 +156,15 @@ if __name__ == "__main__": · 3 unmodified lines
93 if len(sys.argv) > 2:156 if len(sys.argv) > 2:
94 for each in sys.argv[3:-1]: print each157 for each in sys.argv[3:-1]: print each
95 modes = ['schmitt', 'yin', 'mcomb', 'fcomb']158 modes = ['schmitt', 'yin', 'mcomb', 'fcomb']
96 #modes = ['fcomb']159 modes = ['schmitt', 'yin', 'fcomb']
97 160
98 params = taskparams()161 params = taskparams()
99 params.bufsize = 4096 162 params.bufsize = 2048
100 params.hopsize = params.bufsize/4163 params.hopsize = params.bufsize/8
101 params.silence = -1000.164 params.silence = -60.
102 params.pitchsmooth = 50165 params.pitchsmooth = 0
166 params.pitchmax = 20000
167 params.pitchmin = 20
103 benchpitch = benchpitch(datapath,params=params)168 benchpitch = benchpitch(datapath,params=params)
104 benchpitch.task = taskpitch169 benchpitch.task = taskpitch
105 170

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t