Mercurial > hg > segmentation
comparison SegEval.py @ 3:bac230fcd7bd
add linux build of levinsonext
author | mitian |
---|---|
date | Tue, 07 Apr 2015 17:58:37 +0100 |
parents | ef1fd8b0f3c4 |
children | 56a2ca9359d0 |
comparison
equal
deleted
inserted
replaced
2:ef1fd8b0f3c4 | 3:bac230fcd7bd |
---|---|
46 import novelty as novelty_S | 46 import novelty as novelty_S |
47 | 47 |
48 # Algorithm params | 48 # Algorithm params |
49 h = 8 # Size of median filter for features in C-NMF | 49 h = 8 # Size of median filter for features in C-NMF |
50 R = 15 # Size of the median filter for the activation matrix C-NMF | 50 R = 15 # Size of the median filter for the activation matrix C-NMF |
51 rank = 4 # Rank of decomposition for the boundaries | 51 rank = 8 # Rank of decomposition for the boundaries |
52 rank_labels = 6 # Rank of decomposition for the labels | 52 rank_labels = 6 # Rank of decomposition for the labels |
53 R_labels = 6 # Size of the median filter for the labels | 53 R_labels = 6 # Size of the median filter for the labels |
54 # Foote | 54 # Foote |
55 M = 2 # Median filter for the audio features (in beats) | 55 M = 2 # Median filter for the audio features (in beats) |
56 Mg = 32 # Gaussian kernel size | 56 Mg = 32 # Gaussian kernel size |
119 | 119 |
120 '''Settings for extracting tempogram features.''' | 120 '''Settings for extracting tempogram features.''' |
121 self.tempoWindow = 6.0 | 121 self.tempoWindow = 6.0 |
122 self.bpmBands = [30, 45, 60, 80, 100, 120, 180, 240, 400, 600] | 122 self.bpmBands = [30, 45, 60, 80, 100, 120, 180, 240, 400, 600] |
123 | 123 |
124 '''Peak picking settings''' | 124 '''Peak picking settings for novelty based method''' |
125 self.threshold = 50 | 125 self.threshold = 50 |
126 self.confidence_threshold = 0.5 | 126 self.confidence_threshold = 0.5 |
127 self.delta_threshold = 0.0 | 127 self.delta_threshold = 0.0 |
128 self.backtracking_threshold = 1.9 | 128 self.backtracking_threshold = 1.9 |
129 self.polyfitting_on = True | 129 self.polyfitting_on = True |
134 self.bCoeffs = [0.1600, 0.3200, 0.1600] | 134 self.bCoeffs = [0.1600, 0.3200, 0.1600] |
135 self.cutoff = 0.34 | 135 self.cutoff = 0.34 |
136 self.medianWin = 7 | 136 self.medianWin = 7 |
137 | 137 |
138 | 138 |
139 def pairwiseF(self, annotation, detection, tolerance=3.0, combine=1.0): | 139 def pairwiseF(self, annotation, detection, tolerance=3.0, combine=1.0, idx2time=None): |
140 '''Pairwise F measure evaluation of detection rates.''' | 140 '''Pairwise F measure evaluation of detection rates.''' |
141 | 141 |
142 if idx2time: | |
143 # Map detected idxs to real time | |
144 detection = [idx2time[int(np.rint(i))] for i in detection] + [ao.gt[-1]] | |
142 # print 'detection', detection | 145 # print 'detection', detection |
143 detection = np.append(detection, annotation[-1]) | 146 detection = np.append(detection, annotation[-1]) |
144 res = EvalObj() | 147 res = EvalObj() |
145 res.TP = 0 # Total number of matched ground truth and experimental data points | 148 res.TP = 0 # Total number of matched ground truth and experimental data points |
146 gt = len(annotation) # Total number of ground truth data points | 149 gt = len(annotation) # Total number of ground truth data points |
173 res.P = res.TP / float(dt) | 176 res.P = res.TP / float(dt) |
174 res.R = res.TP / float(gt) | 177 res.R = res.TP / float(gt) |
175 res.F = 2 * res.P * res.R / (res.P + res.R) | 178 res.F = 2 * res.P * res.R / (res.P + res.R) |
176 return res | 179 return res |
177 | 180 |
178 | 181 def wirteIndividualHeader(self, filename): |
182 '''Write header of output files for individual features.''' | |
183 | |
184 with open(filename, 'a') as f: | |
185 csvwriter = csv.writer(f, delimiter=',') | |
186 csvwriter.writerow(['audio', 'gammatone_tp_05', 'gammatone_fp_05', 'gammatone_fn_05', 'gammatone_P_05', 'gammatone_R_05', 'gammatone_F_05', 'gammatone_AD_05', 'gammatone_DA_05', 'gammatone_tp_3', \ | |
187 'gammatone_fp_3', 'gammatone_fn_3', 'gammatone_P_3', 'gammatone_R_3', 'gammatone_F_3', 'gammatone_AD_3', 'gammatone_DA_3', 'harmonic_tp_05', 'harmonic_fp_05', 'harmonic_fn_05', 'harmonic_P_05', \ | |
188 'harmonic_R_05', 'harmonic_F_05', 'harmonic_AD_05', 'harmonic_DA_05', 'harmonic_tp_3', 'harmonic_fp_3', 'harmonic_fn_3', 'harmonic_P_3', 'harmonic_R_3', 'harmonic_F_3', 'harmonic_AD_3', 'harmonic_DA_3', \ | |
189 'timbre_tp_05', 'timbre_fp_05', 'timbre_fn_05', 'timbre_P_05', 'timbre_R_05', 'timbre_F_05', 'timbre_AD_05', 'timbre_DA_05', 'timbre_tp_3', 'timbre_fp_3', 'timbre_fn_3', 'timbre_P_3', 'timbre_R_3', \ | |
190 'timbre_F_3', 'timbre_AD_3', 'timbre_DA_3', 'tempo_tp_05', 'tempo_fp_05', 'tempo_fn_05', 'tempo_P_05', 'tempo_R_05', 'tempo_F_05', 'tempo_AD_05', 'tempo_DA_05', \ | |
191 'tempo_tp_3', 'tempo_fp_3', 'tempo_fn_3', 'tempo_P_3', 'tempo_R_3', 'tempo_F_3', 'tempo_AD_3', 'tempo_DA_3']) | |
192 | |
193 def wirteIndividualRes(self, filename, ao_name, gt_res_05, gt_res_3, harmonic_res_05, harmonic_res_3, timbre_res_05, timbre_res_3, tempo_res_05, tempo_res_3): | |
194 '''Write result of single detection for individual features.''' | |
195 | |
196 with open(filename, 'a') as f: | |
197 csvwriter = csv.writer(f, delimiter=',') | |
198 csvwriter.writerow([ao_name, gt_res_05.TP, gt_res_05.FP, gt_res_05.FN, gt_res_05.P, gt_res_05.R, gt_res_05.F, gt_res_05.AD, gt_res_05.DA, gt_res_3.TP, gt_res_3.FP, gt_res_3.FN, gt_res_3.P, \ | |
199 gt_res_3.R, gt_res_3.F, gt_res_3.AD, gt_res_3.DA, harmonic_res_05.TP, harmonic_res_05.FP, harmonic_res_05.FN, harmonic_res_05.P, harmonic_res_05.R, harmonic_res_05.F, harmonic_res_05.AD, harmonic_res_05.DA, \ | |
200 harmonic_res_3.TP, harmonic_res_3.FP, harmonic_res_3.FN, harmonic_res_3.P, harmonic_res_3.R, harmonic_res_3.F, harmonic_res_3.AD, harmonic_res_3.DA, timbre_res_05.TP, timbre_res_05.FP, \ | |
201 timbre_res_05.FN, timbre_res_05.P, timbre_res_05.R, timbre_res_05.F, timbre_res_05.AD, timbre_res_05.DA, timbre_res_3.TP, timbre_res_3.FP, timbre_res_3.FN, timbre_res_3.P, timbre_res_3.R, timbre_res_3.F, \ | |
202 timbre_res_3.AD, timbre_res_3.DA, tempo_res_05.TP, tempo_res_05.FP, tempo_res_05.FN, tempo_res_05.P, tempo_res_05.R, tempo_res_05.F, tempo_res_05.AD, tempo_res_05.DA, tempo_res_3.TP, tempo_res_3.FP, \ | |
203 tempo_res_3.FN, tempo_res_3.P, tempo_res_3.R, tempo_res_3.F, tempo_res_3.AD, tempo_res_3.DA]) | |
204 | |
205 def writeCombinedHeader(self, filename): | |
206 '''Write header of output files for combined features.''' | |
207 | |
208 with open(filename, 'a') as f: | |
209 csvwriter = csv.writer(f, delimiter=',') | |
210 csvwriter.writerow(['audio', 'gt_tb_P_0.5', 'gt_tb_R_0.5', 'gt_tb_F_0.5', 'gt_tb_P_3', 'gt_tb_R_3', 'gt_tb_F_3', 'gt_tp_P_0.5', 'gt_tp_R_0.5', 'gt_tp_F_0.5', 'gt_tp_P_3', 'gt_tp_R_3', 'gt_tp_F_3',\ | |
211 'gt_hm_P_0.5', 'gt_hm_R_0.5', 'gt_hm_F_0.5', 'gt_hm_P_3', 'gt_hm_R_3', 'gt_hm_F_3', 'tb_tp_P_0.5', 'tb_tp_R_0.5', 'tb_tp_F_0.5', 'tb_tp_P_3', 'tb_tp_R_3', 'tb_tp_F_3', 'tb_hm_P_0.5', 'tb_hm_R_0.5', 'tb_hm_F_0.5', \ | |
212 'tb_hm_P_3', 'tb_hm_R_3', 'tb_hm_F_3', 'tp_hm_P_0.5', 'tp_hm_R_0.5', 'tp_hm_F_0.5', 'tp_hm_P_3', 'tp_hm_R_3', 'tp_hm_F_3', 'gt_tb_tp_P_0.5', 'gt_tb_tp_R_0.5', 'gt_tb_tp_F_0.5', 'gt_tb_tp_P_3', 'gt_tb_tp_R_3', \ | |
213 'gt_tb_tp_F_3', 'gt_tb_hm_P_0.5', 'gt_tb_hm_R_0.5', 'gt_tb_hm_F_0.5', 'gt_tb_hm_P_3', 'gt_tb_hm_R_3', 'gt_tb_hm_F_3', 'gt_tp_hm_P_0.5', 'gt_tp_hm_R_0.5', 'gt_tp_hm_F_0.5', 'gt_tp_hm_P_3', 'gt_tp_hm_R_3', 'gt_tp_hm_F_3', \ | |
214 'tb_tp_hm_P_0.5', 'tb_tp_hm_R_0.5', 'tb_tp_hm_F_0.5', 'tb_tp_hm_P_3', 'tb_tp_hm_R_3', 'tb_tp_hm_F_3', 'gt_tb_tp_hm_P_0.5', 'gt_tb_tp_hm_R_0.5', 'gt_tb_tp_hm_F_0.5', 'gt_tb_tp_hm_P_3', 'gt_tb_tp_hm_R_3', 'gt_tb_tp_hm_F_3']) | |
215 | |
216 def wirteCombinedRes(self, filename, ao_name, gt_hm_res_05, gt_hm_res_3, gt_tb_res_05, gt_tb_res_3, gt_tp_res_05, gt_tp_res_3, hm_tb_res_05, hm_tb_res_3, hm_tp_res_05, hm_tp_res_3, \ | |
217 tb_tp_res_05, tb_tp_res_3, gt_hm_tb_res_05, gt_hm_tb_res_3, gt_hm_tp_res_05, gt_hm_tp_res_3, gt_tb_tp_res_05, gt_tb_tp_res_3, hm_tb_tp_res_05, hm_tb_tp_res_3): | |
218 '''Write result of single detection for combined features.''' | |
219 | |
220 with open(filename, 'a') as f: | |
221 csvwriter = csv.writer(f, delimiter=',') | |
222 csvwriter.writerow([ao_name, gt_tb_res_05.P, gt_tb_res_05.R, gt_tb_res_05.F, gt_tb_res_3.P, gt_tb_res_3.R, gt_tb_res_3.F, gt_tp_res_05.P, gt_tp_res_05.R, gt_tp_res_05.F, gt_tp_res_3.P, gt_tp_res_3.R, gt_tp_res_3.F, \ | |
223 gt_hm_res_05.P, gt_hm_res_05.R, gt_hm_res_05.F, gt_hm_res_3.P, gt_hm_res_3.R, gt_hm_res_3.F, tb_tp_res_05.P, tb_tp_res_05.R, tb_tp_res_05.F, tb_tp_res_3.P, tb_tp_res_3.R, tb_tp_res_3.F, \ | |
224 tb_hm_res_05.P, tb_hm_res_05.R, tb_hm_res_05.F, tb_hm_res_3.P, tb_hm_res_3.R, tb_hm_res_3.F, tp_hm_res_05.P, tp_hm_res_05.R, tp_hm_res_05.F, tp_hm_res_3.P, tp_hm_res_3.R, tp_hm_res_3.F, \ | |
225 gt_tb_tp_res_05.P, gt_tb_tp_res_05.R, gt_tb_tp_res_05.F, gt_tb_tp_res_3.P, gt_tb_tp_res_3.R, gt_tb_tp_res_3.F, gt_tb_hm_res_05.P, gt_tb_hm_res_05.R, gt_tb_hm_res_05.F, gt_tb_hm_res_3.P, gt_tb_hm_res_3.R, gt_tb_hm_res_3.F, \ | |
226 gt_tp_hm_res_05.P, gt_tp_hm_res_05.R, gt_tp_hm_res_05.F, gt_tp_hm_res_3.P, gt_tp_hm_res_3.R, gt_tp_hm_res_3.F, tb_tp_hm_res_05.P, tb_tp_hm_res_05.R, tb_tp_hm_res_05.F, tb_tp_hm_res_3.P, tb_tp_hm_res_3.R, tb_tp_hm_res_3.F, \ | |
227 gt_tb_tp_hm_res_05.P, gt_tb_tp_hm_res_05.R, gt_tb_tp_hm_res_05.F, gt_tb_tp_hm_res_3.P, gt_tb_tp_hm_res_3.R, gt_tb_tp_hm_res_3.F]) | |
228 | |
229 | |
179 def process(self): | 230 def process(self): |
180 '''For the aggregated input features, discard a propertion each time as the pairwise distances within the feature space descending. | 231 '''For the aggregated input features, discard a propertion each time as the pairwise distances within the feature space descending. |
181 In the meanwhile evaluate the segmentation result and track the trend of perfomance changing by measuring the feature selection | 232 In the meanwhile evaluate the segmentation result and track the trend of perfomance changing by measuring the feature selection |
182 threshold - segmentation f measure curve. | 233 threshold - segmentation f measure curve. |
183 ''' | 234 ''' |
315 | 366 |
316 ao.ssm_timestamps = np.array(map(lambda x: ao.tempo_timestamps[aggregation_step*x], np.arange(0, ao.gammatone_ssm.shape[0]))) | 367 ao.ssm_timestamps = np.array(map(lambda x: ao.tempo_timestamps[aggregation_step*x], np.arange(0, ao.gammatone_ssm.shape[0]))) |
317 | 368 |
318 audio_list.append(ao) | 369 audio_list.append(ao) |
319 | 370 |
320 # Segment input audio using specified boundary retrieval method. | 371 # Prepare output files. |
372 outfile1 = join(options.OUTPUT, 'individual_novelty.csv') | |
373 outfile2 = join(options.OUTPUT, 'individual_foote.csv') | |
374 outfile3 = join(options.OUTPUT, 'individual_sf.csv') | |
375 outfile4 = join(options.OUTPUT, 'individual_cnmf.csv') | |
376 | |
377 outfile5 = join(options.OUTPUT, 'combined_novelty.csv') | |
378 outfile6 = join(options.OUTPUT, 'combined_foote.csv') | |
379 outfile7 = join(options.OUTPUT, 'combined_sf.csv') | |
380 outfile8 = join(options.OUTPUT, 'combined_cnmf.csv') | |
381 | |
382 self.wirteIndividualHeader(outfile1) | |
383 self.wirteIndividualHeader(outfile2) | |
384 self.wirteIndividualHeader(outfile3) | |
385 self.wirteIndividualHeader(outfile4) | |
386 | |
387 # self.wirteCombinedlHeader(outfile5) | |
388 # self.wirteCombinedlHeader(outfile6) | |
389 self.wirteCombinedlHeader(outfile7) | |
390 # self.wirteCombinedlHeader(outfile8) | |
391 | |
321 print 'Segmenting using %s method' %options.BOUNDARY | 392 print 'Segmenting using %s method' %options.BOUNDARY |
322 for i,ao in enumerate(audio_list): | 393 for i,ao in enumerate(audio_list): |
323 print 'processing: %s' %ao.name | 394 print 'processing: %s' %ao.name |
395 | |
396 ############################################################################################################################################ | |
397 # Experiment 1: segmentation using individual features. | |
398 | |
399 gammatone_novelty, smoothed_gammatone_novelty, gammatone_novelty_idxs = novelty_S.process(ao.gammatone_ssm, self.kernel_size, peak_picker) | |
400 timbre_novelty, smoothed_timbre_novelty, timbre_novelty_idxs = novelty_S.process(ao.timbre_ssm, self.kernel_size, peak_picker) | |
401 tempo_novelty, smoothed_harmonic_novelty, tempo_novelty_idxs = novelty_S.process(ao.tempo_ssm, self.kernel_size, peak_picker) | |
402 harmonic_novelty, smoothed_tempo_novelty, harmonic_novelty_idxs = novelty_S.process(ao.harmonic_ssm, self.kernel_size, peak_picker) | |
403 | |
404 gammatone_cnmf_idxs = cnmf_S.segmentation(ao.gammatone_features, rank=rank, R=R, h=h, niter=300) | |
405 timbre_cnmf_idxs = cnmf_S.segmentation(ao.timbre_features, rank=rank, R=R, h=h, niter=300) | |
406 tempo_cnmf_idxs = cnmf_S.segmentation(ao.tempo_features, rank=rank, R=R, h=h, niter=300) | |
407 harmonic_cnmf_idxs = cnmf_S.segmentation(ao.harmonic_features, rank=rank, R=R, h=h, niter=300) | |
408 | |
409 gammatone_foote_idxs = foote_S.segmentation(ao.gammatone_features, M=M, Mg=Mg, L=L) | |
410 timbre_foote_idxs = foote_S.segmentation(ao.timbre_features, M=M, Mg=Mg, L=L) | |
411 tempo_foote_idxs = foote_S.segmentation(ao.tempo_features, M=M, Mg=Mg, L=L) | |
412 harmonic_foote_idxs = foote_S.segmentation(ao.harmonic_features, M=M, Mg=Mg, L=L) | |
413 | |
414 gammatone_sf_idxs = sf_S.segmentation(ao.gammatone_features) | |
415 timbre_sf_idxs = sf_S.segmentation(ao.timbre_features) | |
416 tempo_sf_idxs = sf_S.segmentation(ao.tempo_features) | |
417 harmonic_sf_idxs = sf_S.segmentation(ao.harmonic_features) | |
324 | 418 |
325 # Experiment 1: segmentation using individual features. | 419 # Evaluate and write results. |
326 if options.BOUNDARY == 'novelty': | 420 gt_novelty_05 = self.pairwiseF(ao.gt, gammatone_novelty_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
327 # Peak picking from the novelty curve | 421 gt_novelty_3 = self.pairwiseF(ao.gt, gammatone_novelty_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
328 gammatone_novelty, smoothed_gammatone_novelty, gammatone_bound_idxs = novelty_S.process(ao.gammatone_ssm, self.kernel_size, peak_picker) | 422 harmonic_novelty_05 = self.pairwiseF(ao.gt, harmonic_novelty_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
329 timbre_novelty, smoothed_timbre_novelty, timbre_bound_idxs = novelty_S.process(ao.timbre_ssm, self.kernel_size, peak_picker) | 423 harmonic_novelty_3 = self.pairwiseF(ao.gt, harmonic_novelty_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
330 tempo_novelty, smoothed_harmonic_novelty, tempo_bound_idxs = novelty_S.process(ao.tempo_ssm, self.kernel_size, peak_picker) | 424 tempo_novelty_05 = self.pairwiseF(ao.gt, tempo_novelty_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
331 harmonic_novelty, smoothed_tempo_novelty, harmonic_bound_idxs = novelty_S.process(ao.harmonic_ssm, self.kernel_size, peak_picker) | 425 tempo_novelty_3 = self.pairwiseF(ao.gt, tempo_novelty_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
332 | 426 timbre_novelty_05 = self.pairwiseF(ao.gt, timbre_novelty_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
333 if options.BOUNDARY == 'cnmf': | 427 timbre_novelty_3 = self.pairwiseF(ao.gt, timbre_novelty_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
334 gammatone_bound_idxs = cnmf_S.segmentation(ao.gammatone_features, rank=rank, R=R, h=8, niter=300) | 428 |
335 timbre_bound_idxs = cnmf_S.segmentation(ao.timbre_features, rank=rank, R=R, h=h, niter=300) | 429 gt_cnmf_05 = self.pairwiseF(ao.gt, gammatone_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
336 tempo_bound_idxs = cnmf_S.segmentation(ao.tempo_features, rank=rank, R=R, h=h, niter=300) | 430 gt_cnmf_3 = self.pairwiseF(ao.gt, gammatone_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
337 harmonic_bound_idxs = cnmf_S.segmentation(ao.harmonic_features, rank=rank, R=R, h=h, niter=300) | 431 harmonic_cnmf_05 = self.pairwiseF(ao.gt, harmonic_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
338 | 432 harmonic_cnmf_3 = self.pairwiseF(ao.gt, harmonic_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
339 if options.BOUNDARY == 'foote': | 433 tempo_cnmf_05 = self.pairwiseF(ao.gt, tempo_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
340 gammatone_bound_idxs = foote_S.segmentation(ao.gammatone_features, M=M, Mg=Mg, L=L) | 434 tempo_cnmf_3 = self.pairwiseF(ao.gt, tempo_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
341 timbre_bound_idxs = foote_S.segmentation(ao.timbre_features, M=M, Mg=Mg, L=L) | 435 timbre_cnmf_05 = self.pairwiseF(ao.gt, timbre_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
342 tempo_bound_idxs = foote_S.segmentation(ao.tempo_features, M=M, Mg=Mg, L=L) | 436 timbre_cnmf_3 = self.pairwiseF(ao.gt, timbre_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
343 harmonic_bound_idxs = foote_S.segmentation(ao.harmonic_features, M=M, Mg=Mg, L=L) | 437 |
344 | 438 gt_sf_05 = self.pairwiseF(ao.gt, gammatone_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
345 if options.BOUNDARY == 'sf': | 439 gt_sf_3 = self.pairwiseF(ao.gt, gammatone_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
346 gammatone_bound_idxs = sf_S.segmentation(ao.gammatone_features) | 440 harmonic_sf_05 = self.pairwiseF(ao.gt, harmonic_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
347 timbre_bound_idxs = sf_S.segmentation(ao.timbre_features) | 441 harmonic_sf_3 = self.pairwiseF(ao.gt, harmonic_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
348 tempo_bound_idxs = sf_S.segmentation(ao.tempo_features) | 442 tempo_sf_05 = self.pairwiseF(ao.gt, tempo_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
349 harmonic_bound_idxs = sf_S.segmentation(ao.harmonic_features) | 443 tempo_sf_3 = self.pairwiseF(ao.gt, tempo_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
350 | 444 timbre_sf_05 = self.pairwiseF(ao.gt, timbre_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
351 if options.LABEL == 'fmc2d': | 445 timbre_sf_3 = self.pairwiseF(ao.gt, timbre_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
352 gammatone_bound_labels = fmc2d_S.compute_similarity(gammatone_bound_idxs, xmeans=True, N=N) | 446 |
353 timbre_bound_labels = fmc2d_S.compute_similarity(timbre_bound_idxs, xmeans=True, N=N) | 447 gt_foote_05 = self.pairwiseF(ao.gt, gammatone_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
354 tempo_bound_labels = fmc2d_S.compute_similarity(tempo_bound_idxs, xmeans=True, N=N) | 448 gt_foote_3 = self.pairwiseF(ao.gt, gammatone_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
355 harmonic_bound_labels = fmc2d_S.compute_similarity(harmonic_bound_idxs, xmeans=True, N=N) | 449 harmonic_foote_05 = self.pairwiseF(ao.gt, harmonic_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
356 | 450 harmonic_foote_3 = self.pairwiseF(ao.gt, harmonic_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
357 if options.LABEL == 'cnmf': | 451 tempo_foote_05 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
358 gammatone_bound_labels = cnmf_S.compute_labels(gammatone_bound_idxs, est_bound_idxs, nFrames) | 452 tempo_foote_3 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
359 timbre_bound_labels = cnmf_S.compute_labels(timbre_bound_idxs, est_bound_idxs, nFrames) | 453 timbre_foote_05 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
360 tempo_bound_labels = cnmf_S.compute_labels(tempo_bound_idxs, est_bound_idxs, nFrames) | 454 timbre_foote_3 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) |
361 harmonic_bound_labels = cnmf_S.compute_labels(harmonic_bound_idxs, est_bound_idxs, nFrames) | 455 |
362 | 456 self.writeIndividualRes(ao.name, outfile1, gt_novelty_05, gt_novelty_3, harmonic_novelty_05, harmonic_novelty_3, tempo_novelty_05, timbre_novelty_05, timbre_novelty_05, timbre_novelty_3) |
363 gammatone_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in gammatone_novelty_peaks] | 457 self.writeIndividualRes(ao.name, outfile2, gt_cnmf_05, gt_cnmf_3, harmonic_cnmf_05, harmonic_cnmf_3, tempo_cnmf_05, timbre_cnmf_05, timbre_cnmf_05, timbre_cnmf_3) |
364 timbre_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in timbre_novelty_peaks] | 458 self.writeIndividualRes(ao.name, outfile3, gt_sf_05, gt_sf_3, harmonic_sf_05, harmonic_sf_3, tempo_sf_05, timbre_sf_05, timbre_sf_05, timbre_sf_3) |
365 harmonic_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in harmonic_novelty_peaks] | 459 self.writeIndividualRes(ao.name, outfile4, gt_foote_05, gt_foote_3, harmonic_foote_05, harmonic_foote_3, tempo_foote_05, timbre_foote_05, timbre_foote_05, timbre_foote_3) |
366 tempo_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in tempo_novelty_peaks] | 460 |
367 | 461 |
368 # Experiment 2: Trying combined features using the best boundary retrieval method | 462 ############################################################################################################################################ |
369 ao_featureset = [ao.gammatone_features, ao.harmonic_features, ao.timbre_features, ao.tempo_features] | 463 # Experiment 2: segmentation using combined features. |
370 feature_sel = [int(x) for x in options.FEATURES if x.isdigit()] | 464 |
371 fused_featureset = [ao_featureset[i] for i in feature_sel] | 465 # Dumping features. |
372 | 466 gt_hm = np.hstack([ao.gammatone_features, ao.harmonic_features]) |
467 gt_tb = np.hstack([ao.gammatone_features, ao.timbre_features]) | |
468 gt_tp = np.hstack([ao.gammatone_features, ao.tempo_features]) | |
469 hm_tb = np.hstack([ao.harmonic_features, ao.timbre_features]) | |
470 hm_tp = np.hstack([ao.harmonic_features, ao.tempo_features]) | |
471 tb_tp = np.hstack([ao.timbre_features, ao.tempo_features]) | |
472 gt_hm_tp = np.hstack([ao.gammatone_features, ao.harmonic_features, ao.tempo_features]) | |
473 gt_tb_tp = np.hstack([ao.gammatone_features, ao.timbre_features, ao.tempo_features]) | |
474 hm_tb_tp = np.hstack([ao.harmonic_features, ao.timbre_features, ao.tempo_features]) | |
475 gt_hm_tb_tp = np.hstack([ao.gammatone_features, ao.harmonic_features, ao.timbre_features, ao.tempo_features]) | |
476 | |
477 gt_hm_sf_idxs = sf_S.segmentation(gt_hm) | |
478 gt_tb_sf_idxs = sf_S.segmentation(gt_tb) | |
479 gt_tp_sf_idxs = sf_S.segmentation(gt_tp) | |
480 hm_tb_sf_idxs = sf_S.segmentation(hm_tb) | |
481 hm_tp_sf_idxs = sf_S.segmentation(hm_tp) | |
482 tb_tp_sf_idxs = sf_S.segmentation(tb_tp) | |
483 gt_hm_tb_sf_idxs = sf_S.segmentation(gt_hm_tb) | |
484 gt_hm_tp_sf_idxs = sf_S.segmentation(gt_hm_tp) | |
485 gt_tb_tp_sf_idxs = sf_S.segmentation(gt_tb_tp) | |
486 hm_tb_tp_sf_idxs = sf_S.segmentation(hm_tb_tp) | |
487 gt_hm_tb_tp_sf_idxs = sf_S.segmentation(gt_hm_tb_tp) | |
488 | |
489 gt_hm_05 = self.pairwiseF(ao.gt, gt_hm_sf_idxs, tolerance=0.5, combine=1.0) | |
490 gt_tb_05 = self.pairwiseF(ao.gt, gt_tb_sf_idxs, tolerance=0.5, combine=1.0) | |
491 gt_tp_05 = self.pairwiseF(ao.gt, gt_tp_sf_idxs, tolerance=0.5, combine=1.0) | |
492 hm_tb_05 = self.pairwiseF(ao.gt, hm_tb_sf_idxs, tolerance=0.5, combine=1.0) | |
493 hm_tp_05 = self.pairwiseF(ao.gt, hm_tp_sf_idxs, tolerance=0.5, combine=1.0) | |
494 tb_tp_05 = self.pairwiseF(ao.gt, tb_tp_sf_idxs, tolerance=0.5, combine=1.0) | |
495 gt_hm_tb_05 = self.pairwiseF(ao.gt, gt_hm_tb_sf_idxs, tolerance=0.5, combine=1.0) | |
496 gt_hm_tp_05 = self.pairwiseF(ao.gt, gt_hm_tp_sf_idxs, tolerance=0.5, combine=1.0) | |
497 gt_tb_tp_05 = self.pairwiseF(ao.gt, gt_tb_tp_sf_idxs, tolerance=0.5, combine=1.0) | |
498 hm_tb_tp_05 = self.pairwiseF(ao.gt, hm_tb_tp_sf_idxs, tolerance=0.5, combine=1.0) | |
499 gt_hm_tb_tp_05 = self.pairwiseF(ao.gt, gt_hm_tb_tp_sf_idxs, tolerance=0.5, combine=1.0) | |
500 | |
501 gt_hm_3 = self.pairwiseF(ao.gt, gt_hm_sf_idxs, tolerance=3, combine=1.0) | |
502 gt_tb_3 = self.pairwiseF(ao.gt, gt_tb_sf_idxs, tolerance=3, combine=1.0) | |
503 gt_tp_3 = self.pairwiseF(ao.gt, gt_tp_sf_idxs, tolerance=3, combine=1.0) | |
504 hm_tb_3 = self.pairwiseF(ao.gt, hm_tb_sf_idxs, tolerance=3, combine=1.0) | |
505 hm_tp_3 = self.pairwiseF(ao.gt, hm_tp_sf_idxs, tolerance=3, combine=1.0) | |
506 tb_tp_3 = self.pairwiseF(ao.gt, tb_tp_sf_idxs, tolerance=3, combine=1.0) | |
507 gt_hm_tb_3 = self.pairwiseF(ao.gt, gt_hm_tb_sf_idxs, tolerance=3, combine=1.0) | |
508 gt_hm_tp_3 = self.pairwiseF(ao.gt, gt_hm_tp_sf_idxs, tolerance=3, combine=1.0) | |
509 gt_tb_tp_3 = self.pairwiseF(ao.gt, gt_tb_tp_sf_idxs, tolerance=3, combine=1.0) | |
510 hm_tb_tp_3 = self.pairwiseF(ao.gt, hm_tb_tp_sf_idxs, tolerance=3, combine=1.0) | |
511 gt_hm_tb_tp_3 = self.pairwiseF(ao.gt, gt_hm_tb_tp_sf_idxs, tolerance=3, combine=1.0) | |
512 | |
513 self.writeCombinedRes(ao.name, outfile7, gt_hm_05, gt_hm_3, gt_tb_05, gt_tb_3, gt_tp_05, gt_tp_3, hm_tb_05, hm_tb_3, hm_tp_05, hm_tp_3, tb_tp_05, tb_tp_3\ | |
514 gt_hm_tb_05, gt_hm_tb_3, gt_hm_tp_05, gt_hm_tp_3, gt_tb_tp_05, gt_tb_tp_3, hm_tb_tp_05, hm_tb_tp_3, gt_hm_tb_tp_05, gt_hm_tb_tp_3) | |
515 | |
516 ############################################################################################################################################ | |
517 # Experiment 3: Pruning boundaries detected by individual boundary algorithms. | |
518 | |
519 | |
520 # if options.BOUNDARY == 'novelty': | |
521 # gammatone_novelty, smoothed_gammatone_novelty, gammatone_bound_idxs = novelty_S.process(ao.gammatone_ssm, self.kernel_size, peak_picker) | |
522 # timbre_novelty, smoothed_timbre_novelty, timbre_bound_idxs = novelty_S.process(ao.timbre_ssm, self.kernel_size, peak_picker) | |
523 # tempo_novelty, smoothed_harmonic_novelty, tempo_bound_idxs = novelty_S.process(ao.tempo_ssm, self.kernel_size, peak_picker) | |
524 # harmonic_novelty, smoothed_tempo_novelty, harmonic_bound_idxs = novelty_S.process(ao.harmonic_ssm, self.kernel_size, peak_picker) | |
525 # | |
526 # if options.BOUNDARY == 'cnmf': | |
527 # gammatone_cnmf_idxs = cnmf_S.segmentation(ao.gammatone_features, rank=rank, R=R, h=8, niter=300) | |
528 # timbre_cnmf_idxs = cnmf_S.segmentation(ao.timbre_features, rank=rank, R=R, h=h, niter=300) | |
529 # tempo_cnmf_idxs = cnmf_S.segmentation(ao.tempo_features, rank=rank, R=R, h=h, niter=300) | |
530 # harmonic_cnmf_idxs = cnmf_S.segmentation(ao.harmonic_features, rank=rank, R=R, h=h, niter=300) | |
531 # | |
532 # if options.BOUNDARY == 'foote': | |
533 # gammatone_foote_idxs = foote_S.segmentation(ao.gammatone_features, M=M, Mg=Mg, L=L) | |
534 # timbre_foote_idxs = foote_S.segmentation(ao.timbre_features, M=M, Mg=Mg, L=L) | |
535 # tempo_foote_idxs = foote_S.segmentation(ao.tempo_features, M=M, Mg=Mg, L=L) | |
536 # harmonic_foote_idxs = foote_S.segmentation(ao.harmonic_features, M=M, Mg=Mg, L=L) | |
537 # | |
538 # if options.BOUNDARY == 'sf': | |
539 # gammatone_sf_idxs = sf_S.segmentation(ao.gammatone_features) | |
540 # timbre_sf_idxs = sf_S.segmentation(ao.timbre_features) | |
541 # tempo_sf_idxs = sf_S.segmentation(ao.tempo_features) | |
542 # harmonic_sf_idxs = sf_S.segmentation(ao.harmonic_features) | |
543 # | |
544 # gammatone_novelty_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in gammatone_novelty_peaks] | |
545 # timbre_novelty_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in timbre_novelty_peaks] | |
546 # harmonic_novelty_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in harmonic_novelty_peaks] | |
547 # tempo_novelty_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in tempo_novelty_peaks] | |
548 # | |
549 # gammatone_cnmf_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in gammatone_cnmf_peaks] | |
550 # timbre_cnmf_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in timbre_cnmf_peaks] | |
551 # harmonic_cnmf_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in harmonic_cnmf_peaks] | |
552 # tempo_cnmf_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in tempo_cnmf_peaks] | |
553 # | |
554 # gammatone_sf_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in gammatone_sf_peaks] | |
555 # timbre_sf_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in timbre_sf_peaks] | |
556 # harmonic_sf_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in harmonic_sf_peaks] | |
557 # tempo_sf_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in tempo_sf_peaks] | |
558 # | |
559 # gammatone_foote_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in gammatone_foote_peaks] | |
560 # timbre_foote_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in timbre_foote_peaks] | |
561 # harmonic_foote_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in harmonic_foote_peaks] | |
562 # tempo_foote_detection = [0.0] + [ao.ssm_timestamps[int(np.rint(i))] for i in tempo_foote_peaks] | |
563 # | |
564 # # Experiment 2: Trying combined features using the best boundary retrieval method | |
565 # ao_featureset = [ao.gammatone_features, ao.harmonic_features, ao.timbre_features, ao.tempo_features] | |
566 # feature_sel = [int(x) for x in options.FEATURES if x.isdigit()] | |
567 # fused_featureset = [ao_featureset[i] for i in feature_sel] | |
568 | |
569 # if options.LABEL == 'fmc2d': | |
570 # gammatone_fmc2d_labels = fmc2d_S.compute_similarity(gammatone_bound_idxs, xmeans=True, N=N) | |
571 # timbre_fmc2d_labels = fmc2d_S.compute_similarity(timbre_bound_idxs, xmeans=True, N=N) | |
572 # tempo_fmc2d_labels = fmc2d_S.compute_similarity(tempo_bound_idxs, xmeans=True, N=N) | |
573 # harmonic_fmc2d_labels = fmc2d_S.compute_similarity(harmonic_bound_idxs, xmeans=True, N=N) | |
574 # | |
575 # if options.LABEL == 'cnmf': | |
576 # gammatone_cnmf_labels = cnmf_S.compute_labels(gammatone_bound_idxs, est_bound_idxs, nFrames) | |
577 # timbre_cnmf_labels = cnmf_S.compute_labels(timbre_bound_idxs, est_bound_idxs, nFrames) | |
578 # tempo_cnmf_labels = cnmf_S.compute_labels(tempo_bound_idxs, est_bound_idxs, nFrames) | |
579 # harmonic_cnmf_labels = cnmf_S.compute_labels(harmonic_bound_idxs, est_bound_idxs, nFrames) | |
580 # | |
581 # | |
582 | |
373 | 583 |
374 | 584 |
375 def main(): | 585 def main(): |
376 | 586 |
377 segmenter = SSMseg() | 587 segmenter = SSMseg() |