comparison SegEval.py @ 5:237799544386

catch 0 detection (when features are empty)
author mitian
date Thu, 09 Apr 2015 17:54:49 +0100
parents 56a2ca9359d0
children 294f66d285af
comparison
equal deleted inserted replaced
4:56a2ca9359d0 5:237799544386
137 137
138 138
139 def pairwiseF(self, annotation, detection, tolerance=3.0, combine=1.0, idx2time=None): 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 res = EvalObj()
143 res.TP, res.FP, res.FN = 0, 0, 0
144 res.P, res.R, res.F = 0.0, 0.0, 0.0
145 res.AD, res.DA = 0.0, 0.0
146
147 if len(detection) == 0:
148 return res
149
150 gt = len(annotation) # Total number of ground truth data points
151 dt = len(detection) # Total number of experimental data points
152 foundIdx = []
153 D_AD = np.zeros(gt)
154 D_DA = np.zeros(dt)
155
142 if idx2time != None: 156 if idx2time != None:
143 # Map detected idxs to real time 157 # Map detected idxs to real time
144 detection = [idx2time[int(np.rint(i))] for i in detection] + [annotation[-1]] 158 detection = [idx2time[int(np.rint(i))] for i in detection] + [annotation[-1]]
145 # print 'detection', detection 159 # print 'detection', detection
146 detection = np.append(detection, annotation[-1]) 160 detection = np.append(detection, annotation[-1])
147 res = EvalObj() 161
148 res.TP = 0 # Total number of matched ground truth and experimental data points
149 gt = len(annotation) # Total number of ground truth data points
150 dt = len(detection) # Total number of experimental data points
151 foundIdx = []
152 D_AD = np.zeros(gt)
153 D_DA = np.zeros(dt)
154
155 for dtIdx in xrange(dt): 162 for dtIdx in xrange(dt):
156 D_DA[dtIdx] = np.min(abs(detection[dtIdx] - annotation)) 163 D_DA[dtIdx] = np.min(abs(detection[dtIdx] - annotation))
157 for gtIdx in xrange(gt): 164 for gtIdx in xrange(gt):
158 D_AD[gtIdx] = np.min(abs(annotation[gtIdx] - detection)) 165 D_AD[gtIdx] = np.min(abs(annotation[gtIdx] - detection))
159 for dtIdx in xrange(dt): 166 for dtIdx in xrange(dt):
166 res.FN = max(0, gt - res.TP) 173 res.FN = max(0, gt - res.TP)
167 174
168 res.AD = np.mean(D_AD) 175 res.AD = np.mean(D_AD)
169 res.DA = np.mean(D_DA) 176 res.DA = np.mean(D_DA)
170 177
171 res.P, res.R, res.F = 0.0, 0.0, 0.0
172 178
173 if res.TP == 0: 179 if res.TP == 0:
174 return res 180 return res
175 181
176 res.P = res.TP / float(dt) 182 res.P = res.TP / float(dt)
291 297
292 # For each audio file, load specific features 298 # For each audio file, load specific features
293 for audio in audio_files: 299 for audio in audio_files:
294 ao = AudioObj() 300 ao = AudioObj()
295 ao.name = splitext(audio)[0] 301 ao.name = splitext(audio)[0]
296 # annotation_file = join(options.GT, ao.name+'.txt') # iso, salami 302 annotation_file = join(options.GT, ao.name+'.txt') # iso, salami
297 # ao.gt = np.genfromtxt(annotation_file, usecols=0) 303 ao.gt = np.genfromtxt(annotation_file, usecols=0)
298 # ao.label = np.genfromtxt(annotation_file, usecols=1, dtype=str) 304 ao.label = np.genfromtxt(annotation_file, usecols=1, dtype=str)
299 annotation_file = join(options.GT, ao.name+'.csv') # qupujicheng 305 # annotation_file = join(options.GT, ao.name+'.csv') # qupujicheng
300 ao.gt = np.genfromtxt(annotation_file, usecols=0, delimiter=',') 306 # ao.gt = np.genfromtxt(annotation_file, usecols=0, delimiter=',')
301 ao.label = np.genfromtxt(annotation_file, usecols=1, delimiter=',', dtype=str) 307 # ao.label = np.genfromtxt(annotation_file, usecols=1, delimiter=',', dtype=str)
302 308
303 gammatone_featureset, timbre_featureset, tempo_featureset, harmonic_featureset = [], [], [], [] 309 gammatone_featureset, timbre_featureset, tempo_featureset, harmonic_featureset = [], [], [], []
304 for feature in gammatone_feature_list: 310 for feature in gammatone_feature_list:
305 for f in os.listdir(feature): 311 for f in os.listdir(feature):
306 if f[:f.find('_vamp')]==ao.name: 312 if f[:f.find('_vamp')]==ao.name:
470 tempo_foote_05 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) 476 tempo_foote_05 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps)
471 tempo_foote_3 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) 477 tempo_foote_3 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps)
472 timbre_foote_05 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) 478 timbre_foote_05 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps)
473 timbre_foote_3 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) 479 timbre_foote_3 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps)
474 480
475 self.writeIndividualRes(outfile1, ao.name, gt_novelty_05, gt_novelty_3, harmonic_novelty_05, harmonic_novelty_3, tempo_novelty_05, timbre_novelty_05, timbre_novelty_05, timbre_novelty_3) 481 self.writeIndividualRes(outfile1, ao.name, gt_novelty_05, gt_novelty_3, harmonic_novelty_05, harmonic_novelty_3, tempo_novelty_05, tempo_novelty_3, timbre_novelty_05, timbre_novelty_3)
476 self.writeIndividualRes(outfile2, ao.name, gt_cnmf_05, gt_cnmf_3, harmonic_cnmf_05, harmonic_cnmf_3, tempo_cnmf_05, timbre_cnmf_05, timbre_cnmf_05, timbre_cnmf_3) 482 self.writeIndividualRes(outfile2, ao.name, gt_cnmf_05, gt_cnmf_3, harmonic_cnmf_05, harmonic_cnmf_3, tempo_cnmf_05, tempo_cnmf_3, timbre_cnmf_05, timbre_cnmf_3)
477 self.writeIndividualRes(outfile3, ao.name, gt_sf_05, gt_sf_3, harmonic_sf_05, harmonic_sf_3, tempo_sf_05, timbre_sf_05, timbre_sf_05, timbre_sf_3) 483 self.writeIndividualRes(outfile3, ao.name, gt_sf_05, gt_sf_3, harmonic_sf_05, harmonic_sf_3, tempo_sf_05, tempo_sf_3, timbre_sf_05, timbre_sf_3)
478 self.writeIndividualRes(outfile4, ao.name, gt_foote_05, gt_foote_3, harmonic_foote_05, harmonic_foote_3, tempo_foote_05, timbre_foote_05, timbre_foote_05, timbre_foote_3) 484 self.writeIndividualRes(outfile4, ao.name, gt_foote_05, gt_foote_3, harmonic_foote_05, harmonic_foote_3, tempo_foote_05, tempo_foote_3, timbre_foote_05, timbre_foote_3)
479 485
480 486
481 ############################################################################################################################################ 487 ############################################################################################################################################
482 # Experiment 2: segmentation using combined features. 488 # Experiment 2: segmentation using combined features.
483 489