Changeset 75139a9
- Timestamp:
- Dec 16, 2005, 2:26:25 AM (19 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 336cf77
- Parents:
- 257debc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/bench-onset
r257debc r75139a9 4 4 from aubio.bench.node import * 5 5 6 datapath = "%s%s" % (DATADIR,'/onset/DB') 6 class onset_parameters: 7 def __init__(self): 8 """ set default parameters """ 9 self.silence = -70 10 self.derivate = False 11 self.localmin = False 12 self.bufsize = 512 13 self.hopsize = 256 14 self.samplerate = 44100 15 self.tol = 0.05 16 self.step = float(self.hopsize)/float(self.samplerate) 17 self.threshold = 0.1 18 self.mode = 'dual' 19 20 class taskonset(task): 21 22 def pretty_print(self,values): 23 for i in range(len(values)): 24 print self.formats[i] % values[i], 25 print 26 27 def compute_results(self): 28 self.P = 100*float(self.expc-self.missed-self.merged)/(self.expc-self.missed-self.merged + self.bad+self.doubled) 29 self.R = 100*float(self.expc-self.missed-self.merged)/(self.expc-self.missed-self.merged + self.missed+self.merged) 30 if self.R < 0: self.R = 0 31 self.F = 2* self.P*self.R / (self.P+self.R) 32 33 self.values = [self.params.mode, 34 "%2.3f" % self.params.threshold, 35 self.orig, 36 self.expc, 37 self.missed, 38 self.merged, 39 self.bad, 40 self.doubled, 41 (self.orig-self.missed-self.merged), 42 "%2.3f" % (100*float(self.orig-self.missed-self.merged)/(self.orig)), 43 "%2.3f" % (100*float(self.bad+self.doubled)/(self.orig)), 44 "%2.3f" % (100*float(self.orig-self.missed)/(self.orig)), 45 "%2.3f" % (100*float(self.bad)/(self.orig)), 46 "%2.3f" % self.P, 47 "%2.3f" % self.R, 48 "%2.3f" % self.F ] 49 50 def compute_onset(self,input,output): 51 from aubio.tasks import getonsets, get_onset_mode 52 from aubio.onsetcompare import onset_roc, onset_diffs 53 from aubio.txtfile import read_datafile 54 amode = 'roc' 55 vmode = 'verbose' 56 vmode = '' 57 lres, ofunc = getonsets(input, 58 self.params.threshold, 59 self.params.silence, 60 mode=get_onset_mode(self.params.mode), 61 localmin=self.params.localmin, 62 derivate=self.params.derivate, 63 bufsize=self.params.bufsize, 64 hopsize=self.params.hopsize, 65 storefunc=False) 66 67 for i in range(len(lres)): lres[i] = lres[i]*self.params.step 68 ltru = read_datafile(input.replace('.wav','.txt'),depth=0) 69 if vmode=='verbose': 70 print "Running with mode %s" % self.params.mode, 71 print " and threshold %f" % self.params.threshold, 72 print " on file", input 73 #print ltru; print lres 74 if amode == 'localisation': 75 l = onset_diffs(ltru,lres,self.params.tol) 76 mean = 0 77 for i in l: mean += i 78 if len(l): print "%.3f" % (mean/len(l)) 79 else: print "?0" 80 elif amode == 'roc': 81 orig, missed, merged, expc, bad, doubled = onset_roc(ltru,lres,self.params.tol) 82 self.orig += orig 83 self.missed += missed 84 self.merged += merged 85 self.expc += expc 86 self.bad += bad 87 self.doubled += doubled 88 self.compute_results() 89 90 def compute_data(self): 91 self.orig, self.missed, self.merged, self.expc, \ 92 self.bad, self.doubled = 0, 0, 0, 0, 0, 0 93 act_on_data(self.compute_onset,self.datadir,self.resdir, \ 94 suffix='',filter='f -name \'*.wav\'') 95 96 def run_bench(self,modes=['dual'],thresholds=[0.5]): 97 self.modes = modes 98 self.thresholds = thresholds 99 100 self.pretty_print(self.titles) 101 for mode in self.modes: 102 self.params.mode = mode 103 for threshold in self.thresholds: 104 self.params.threshold = threshold 105 self.compute_data() 106 self.compute_results() 107 self.pretty_print(self.values) 108 109 def auto_learn(self,modes=['dual'],thresholds=[0.1,1.5]): 110 """ simple dichotomia like algorithm to optimise threshold """ 111 self.modes = modes 112 self.pretty_print(self.titles) 113 for mode in self.modes: 114 steps = 10 115 lesst = thresholds[0] 116 topt = thresholds[1] 117 self.params.mode = mode 118 119 self.params.threshold = topt 120 self.compute_data() 121 self.pretty_print(self.values) 122 topF = self.F 123 124 self.params.threshold = lesst 125 self.compute_data() 126 self.pretty_print(self.values) 127 lessF = self.F 128 129 for i in range(steps): 130 self.params.threshold = ( lesst + topt ) * .5 131 self.compute_data() 132 self.pretty_print(self.values) 133 if self.F == 100.0 or self.F == topF: 134 print "assuming we converged, stopping" 135 break 136 #elif abs(self.F - topF) < 0.01 : 137 # print "done converging" 138 # break 139 if topF < self.F: 140 #lessF = topF 141 #lesst = topt 142 topF = self.F 143 topt = self.params.threshold 144 elif lessF < self.F: 145 lessF = self.F 146 lesst = self.params.threshold 147 if topt == lesst: 148 lesst /= 2. 149 150 151 #modes = [ 'complex' ] 152 modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual'] 153 #thresholds = [1.5] 154 thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5] 155 156 #datapath = "%s%s" % (DATADIR,'/onset/DB/*/') 157 datapath = "%s%s" % (DATADIR,'/onset/DB/PercussivePhrases/RobertRich') 7 158 respath = '/var/tmp/DB-testings' 8 159 9 MODES = 'hfc', 'complexdomain', 'energy', 'phase', 'specdiff', 'kl', 'mkl' 10 THRESHOLD = range(1,14,1) 160 taskonset = taskonset(datapath,respath) 11 161 12 # prepareresultpath 13 act_on_results(mkdir,datapath,respath,filter='d') 162 taskonset.params = onset_parameters() 14 163 15 def compute_data(input,output): 16 aubiocmd = "%s%s %s%s" % \ 17 ("LD_LIBRARY_PATH=",LD_LIBRARY_PATH,AUBIOHOME,"/examples/aubioonset") 18 for m in MODES: 19 for k in THRESHOLD: 20 cmd = "%s --input \"%s\" --onset %s --threshold %s > \"%s--%s--%s.txt\"" \ 21 % (aubiocmd,input,m,k/10.,output,m,k/10.) 22 runcommand(cmd,debug=1) 164 taskonset.titles = [ 'mode', 'thres', 'orig', 'expc', 'missd', 'mergd', 165 'bad', 'doubl', 'corrt', 'GD', 'FP', 'GD-merged', 'FP-pruned', 166 'prec', 'recl', 'dist' ] 167 taskonset.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s", 168 "| %6s", "| %6s", "| %6s", "| %8s", "| %8s", "| %8s", "| %8s", 169 "| %6s", "| %6s", "| %6s"] 23 170 24 25 # computedata 26 act_on_data(compute_data,datapath,respath,suffix='',filter='f -name \'*.wav\'') 171 #taskonset.run_bench(modes=modes,thresholds=thresholds) 172 taskonset.auto_learn(modes=modes) 27 173 28 174 # gatherdata
Note: See TracChangeset
for help on using the changeset viewer.