diff 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
line wrap: on
line diff
--- a/SegEval.py	Wed Apr 08 11:47:47 2015 +0100
+++ b/SegEval.py	Thu Apr 09 17:54:49 2015 +0100
@@ -139,19 +139,26 @@
 	def pairwiseF(self, annotation, detection, tolerance=3.0, combine=1.0, idx2time=None):
 		'''Pairwise F measure evaluation of detection rates.'''
 		
+		res = EvalObj()
+		res.TP, res.FP, res.FN = 0, 0, 0	
+		res.P, res.R, res.F = 0.0, 0.0, 0.0
+		res.AD, res.DA = 0.0, 0.0
+		
+		if len(detection) == 0:
+			return res
+
+		gt = len(annotation)	# Total number of ground truth data points
+		dt = len(detection) # Total number of experimental data points
+		foundIdx = []	
+		D_AD = np.zeros(gt)
+		D_DA = np.zeros(dt)
+		
 		if idx2time != None:
 			# Map detected idxs to real time
 			detection = [idx2time[int(np.rint(i))] for i in detection] + [annotation[-1]]
 		# print 'detection', detection
 		detection = np.append(detection, annotation[-1])
-		res = EvalObj()
-		res.TP = 0	# Total number of matched ground truth and experimental data points
-		gt = len(annotation)	# Total number of ground truth data points
-		dt = len(detection) # Total number of experimental data points
-		foundIdx = []	
-		D_AD = np.zeros(gt)
-		D_DA = np.zeros(dt)
-
+		
 		for dtIdx in xrange(dt):
 			D_DA[dtIdx] = np.min(abs(detection[dtIdx] - annotation))
 		for gtIdx in xrange(gt):
@@ -168,7 +175,6 @@
 		res.AD = np.mean(D_AD)		
 		res.DA = np.mean(D_DA)
 		
-		res.P, res.R, res.F = 0.0, 0.0, 0.0
 		
 		if res.TP == 0:
 			return res
@@ -293,12 +299,12 @@
 		for audio in audio_files:
 			ao = AudioObj()
 			ao.name = splitext(audio)[0]
-			# annotation_file = join(options.GT, ao.name+'.txt') # iso, salami
-			# ao.gt = np.genfromtxt(annotation_file, usecols=0)	
-			# ao.label = np.genfromtxt(annotation_file, usecols=1, dtype=str)
-			annotation_file = join(options.GT, ao.name+'.csv') # qupujicheng
-			ao.gt = np.genfromtxt(annotation_file, usecols=0, delimiter=',')	
-			ao.label = np.genfromtxt(annotation_file, usecols=1, delimiter=',', dtype=str)
+			annotation_file = join(options.GT, ao.name+'.txt') # iso, salami
+			ao.gt = np.genfromtxt(annotation_file, usecols=0)	
+			ao.label = np.genfromtxt(annotation_file, usecols=1, dtype=str)
+			# annotation_file = join(options.GT, ao.name+'.csv') # qupujicheng
+			# ao.gt = np.genfromtxt(annotation_file, usecols=0, delimiter=',')	
+			# ao.label = np.genfromtxt(annotation_file, usecols=1, delimiter=',', dtype=str)
 
 			gammatone_featureset, timbre_featureset, tempo_featureset, harmonic_featureset = [], [], [], []
 			for feature in gammatone_feature_list:
@@ -472,10 +478,10 @@
 			timbre_foote_05 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps)
 			timbre_foote_3 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps)
 			
-			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)
-			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)
-			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)
-			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)
+			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)
+			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)
+			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)
+			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)
 			
 			
 			############################################################################################################################################