Mercurial > hg > segmentation
comparison SegEval.py @ 4:56a2ca9359d0
evaluation script
author | mitian |
---|---|
date | Wed, 08 Apr 2015 11:47:47 +0100 |
parents | bac230fcd7bd |
children | 237799544386 |
comparison
equal
deleted
inserted
replaced
3:bac230fcd7bd | 4:56a2ca9359d0 |
---|---|
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 = 8 # Rank of decomposition for the boundaries | 51 rank = 4 # 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 |
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 for novelty based method''' | 124 '''Peak picking settings for novelty based method''' |
125 self.threshold = 50 | 125 self.threshold = 30 |
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 |
130 self.medfilter_on = True | 130 self.medfilter_on = True |
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 if idx2time: | 142 if idx2time != None: |
143 # Map detected idxs to real time | 143 # Map detected idxs to real time |
144 detection = [idx2time[int(np.rint(i))] for i in detection] + [ao.gt[-1]] | 144 detection = [idx2time[int(np.rint(i))] for i in detection] + [annotation[-1]] |
145 # print 'detection', detection | 145 # print 'detection', detection |
146 detection = np.append(detection, annotation[-1]) | 146 detection = np.append(detection, annotation[-1]) |
147 res = EvalObj() | 147 res = EvalObj() |
148 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 |
149 gt = len(annotation) # Total number of ground truth data points | 149 gt = len(annotation) # Total number of ground truth data points |
176 res.P = res.TP / float(dt) | 176 res.P = res.TP / float(dt) |
177 res.R = res.TP / float(gt) | 177 res.R = res.TP / float(gt) |
178 res.F = 2 * res.P * res.R / (res.P + res.R) | 178 res.F = 2 * res.P * res.R / (res.P + res.R) |
179 return res | 179 return res |
180 | 180 |
181 def wirteIndividualHeader(self, filename): | 181 def writeIndividualHeader(self, filename): |
182 '''Write header of output files for individual features.''' | 182 '''Write header of output files for individual features.''' |
183 | 183 |
184 with open(filename, 'a') as f: | 184 with open(filename, 'a') as f: |
185 csvwriter = csv.writer(f, delimiter=',') | 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', \ | 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', \ |
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', \ | 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', \ | 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', \ | 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']) | 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 | 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): | 193 def writeIndividualRes(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.''' | 194 '''Write result of single detection for individual features.''' |
195 | 195 |
196 with open(filename, 'a') as f: | 196 with open(filename, 'a') as f: |
197 csvwriter = csv.writer(f, delimiter=',') | 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, \ | 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, \ |
206 '''Write header of output files for combined features.''' | 206 '''Write header of output files for combined features.''' |
207 | 207 |
208 with open(filename, 'a') as f: | 208 with open(filename, 'a') as f: |
209 csvwriter = csv.writer(f, delimiter=',') | 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',\ | 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', \ | 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', 'hm_tb_P_0.5', 'hm_tb_R_0.5', 'hm_tb_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', \ | 212 'hm_tb_P_3', 'hm_tb_R_3', 'hm_tb_F_3', 'hm_tp_P_0.5', 'hm_tp_R_0.5', 'hm_tp_F_0.5', 'hm_tp_P_3', 'hm_tp_R_3', 'hm_tp_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', \ | 213 'gt_tb_tp_F_3', 'gt_hm_tb_P_0.5', 'gt_hm_tb_R_0.5', 'gt_hm_tb_F_0.5', 'gt_hm_tb_P_3', 'gt_hm_tb_R_3', 'gt_hm_tb_F_3', 'gt_hm_tp_P_0.5', 'gt_hm_tp_R_0.5', 'gt_hm_tp_F_0.5', 'gt_hm_tp_P_3', 'gt_hm_tp_R_3', 'gt_hm_tp_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']) | 214 'hm_tb_tp_P_0.5', 'hm_tb_tp_R_0.5', 'hm_tb_tp_F_0.5', 'hm_tb_tp_P_3', 'hm_tb_tp_R_3', 'hm_tb_tp_F_3', 'gt_hm_tb_tp_P_0.5', 'gt_hm_tb_tp_R_0.5', 'gt_hm_tb_tp_F_0.5', 'gt_hm_tb_tp_P_3', 'gt_hm_tb_tp_R_3', 'gt_hm_tb_tp_F_3']) |
215 | 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, \ | 216 def writeCombinedRes(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): | 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, gt_hm_tb_tp_res_05, gt_hm_tb_tp_res_3): |
218 '''Write result of single detection for combined features.''' | 218 '''Write result of single detection for combined features.''' |
219 | 219 |
220 with open(filename, 'a') as f: | 220 with open(filename, 'a') as f: |
221 csvwriter = csv.writer(f, delimiter=',') | 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, \ | 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, \ | 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, \ | 224 hm_tb_res_05.P, hm_tb_res_05.R, hm_tb_res_05.F, hm_tb_res_3.P, hm_tb_res_3.R, hm_tb_res_3.F, hm_tp_res_05.P, hm_tp_res_05.R, hm_tp_res_05.F, hm_tp_res_3.P, hm_tp_res_3.R, hm_tp_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, \ | 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_hm_tb_res_05.P, gt_hm_tb_res_05.R, gt_hm_tb_res_05.F, gt_hm_tb_res_3.P, gt_hm_tb_res_3.R, gt_hm_tb_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, \ | 226 gt_hm_tp_res_05.P, gt_hm_tp_res_05.R, gt_hm_tp_res_05.F, gt_hm_tp_res_3.P, gt_hm_tp_res_3.R, gt_hm_tp_res_3.F, hm_tb_tp_res_05.P, hm_tb_tp_res_05.R, hm_tb_tp_res_05.F, hm_tb_tp_res_3.P, hm_tb_tp_res_3.R, hm_tb_tp_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]) | 227 gt_hm_tb_tp_res_05.P, gt_hm_tb_tp_res_05.R, gt_hm_tb_tp_res_05.F, gt_hm_tb_tp_res_3.P, gt_hm_tb_tp_res_3.R, gt_hm_tb_tp_res_3.F]) |
228 | 228 |
229 | 229 def writeMergedHeader(self, filename): |
230 '''Write header of output files merging individual detections.''' | |
231 with open(filename, 'a') as f: | |
232 csvwriter = csv.writer(f, delimiter=',') | |
233 csvwriter.writerow(['audio', 'merged_tp_05', 'merged_fp_05', 'merged_fn_05', 'merged_P_05', 'merged_R_05', 'merged_F_05', 'merged_AD_05', 'merged_DA_05', 'merged_tp_3', \ | |
234 'merged_fp_3', 'merged_fn_3', 'merged_P_3', 'merged_R_3', 'merged_F_3', 'merged_AD_3', 'merged_DA_3']) | |
235 | |
236 def writeMergedRes(self, filename, ao_name, merged_res_05, merged_res_3): | |
237 '''Write results by merging individual detections.''' | |
238 with open(filename, 'a') as f: | |
239 csvwriter = csv.writer(f, delimiter=',') | |
240 csvwriter.writerow([ao_name, merged_res_05.TP, merged_res_05.FP, merged_res_05.FN, merged_res_05.P, merged_res_05.R, merged_res_05.F, merged_res_05.AD, merged_res_05.DA, \ | |
241 merged_res_3.TP, merged_res_3.FP, merged_res_3.FN, merged_res_3.P, merged_res_3.R, merged_res_3.F, merged_res_3.AD, merged_res_3.DA]) | |
242 | |
243 | |
230 def process(self): | 244 def process(self): |
231 '''For the aggregated input features, discard a propertion each time as the pairwise distances within the feature space descending. | 245 '''For the aggregated input features, discard a propertion each time as the pairwise distances within the feature space descending. |
232 In the meanwhile evaluate the segmentation result and track the trend of perfomance changing by measuring the feature selection | 246 In the meanwhile evaluate the segmentation result and track the trend of perfomance changing by measuring the feature selection |
233 threshold - segmentation f measure curve. | 247 threshold - segmentation f measure curve. |
234 ''' | 248 ''' |
254 feature_step_frame = int(0.5 * self.SampleRate / self.gammatoneLen * self.featureStep) | 268 feature_step_frame = int(0.5 * self.SampleRate / self.gammatoneLen * self.featureStep) |
255 aggregation_window, aggregation_step = 100, 50 | 269 aggregation_window, aggregation_step = 100, 50 |
256 featureRate = float(self.SampleRate) / self.stepSize | 270 featureRate = float(self.SampleRate) / self.stepSize |
257 | 271 |
258 audio_files = [x for x in os.listdir(options.GT) if not x.startswith(".") ] | 272 audio_files = [x for x in os.listdir(options.GT) if not x.startswith(".") ] |
259 # audio_files = audio_files[:2] | 273 if options.TEST: |
274 audio_files = audio_files[:1] | |
260 audio_files.sort() | 275 audio_files.sort() |
261 audio_list = [] | 276 audio_list = [] |
262 | 277 |
263 gammatone_feature_list = [i for i in os.listdir(options.GF) if not i.startswith('.')] | 278 gammatone_feature_list = [i for i in os.listdir(options.GF) if not i.startswith('.')] |
264 gammatone_feature_list = ['contrast4', 'rolloff', 'dct'] | 279 gammatone_feature_list = ['contrast6', 'rolloff4', 'dct'] |
265 tempo_feature_list = [i for i in os.listdir(options.TF) if not i.startswith('.')] | 280 tempo_feature_list = [i for i in os.listdir(options.TF) if not i.startswith('.')] |
266 tempo_feature_list = ['intensity_bpm', 'loudness_bpm'] | 281 tempo_feature_list = ['ti', 'tir'] |
267 timbre_feature_list = ['mfcc'] | 282 timbre_feature_list = ['mfcc_harmonic'] |
268 harmonic_feature_list = ['nnls'] | 283 harmonic_feature_list = ['chromagram'] |
269 | 284 |
270 gammatone_feature_list = [join(options.GF, f) for f in gammatone_feature_list] | 285 gammatone_feature_list = [join(options.GF, f) for f in gammatone_feature_list] |
271 timbre_feature_list = [join(options.SF, f) for f in timbre_feature_list] | 286 timbre_feature_list = [join(options.SF, f) for f in timbre_feature_list] |
272 tempo_feature_list = [join(options.TF, f) for f in tempo_feature_list] | 287 tempo_feature_list = [join(options.TF, f) for f in tempo_feature_list] |
273 harmonic_feature_list = [join(options.SF, f) for f in harmonic_feature_list] | 288 harmonic_feature_list = [join(options.SF, f) for f in harmonic_feature_list] |
276 | 291 |
277 # For each audio file, load specific features | 292 # For each audio file, load specific features |
278 for audio in audio_files: | 293 for audio in audio_files: |
279 ao = AudioObj() | 294 ao = AudioObj() |
280 ao.name = splitext(audio)[0] | 295 ao.name = splitext(audio)[0] |
281 print ao.name | |
282 # annotation_file = join(options.GT, ao.name+'.txt') # iso, salami | 296 # annotation_file = join(options.GT, ao.name+'.txt') # iso, salami |
283 # ao.gt = np.genfromtxt(annotation_file, usecols=0) | 297 # ao.gt = np.genfromtxt(annotation_file, usecols=0) |
284 # ao.label = np.genfromtxt(annotation_file, usecols=1, dtype=str) | 298 # ao.label = np.genfromtxt(annotation_file, usecols=1, dtype=str) |
285 annotation_file = join(options.GT, ao.name+'.csv') # qupujicheng | 299 annotation_file = join(options.GT, ao.name+'.csv') # qupujicheng |
286 ao.gt = np.genfromtxt(annotation_file, usecols=0, delimiter=',') | 300 ao.gt = np.genfromtxt(annotation_file, usecols=0, delimiter=',') |
338 aggregation_window, aggregation_step = 1,1 | 352 aggregation_window, aggregation_step = 1,1 |
339 featureRate = float(self.SampleRate) /self.stepSize | 353 featureRate = float(self.SampleRate) /self.stepSize |
340 pca = PCA(n_components=5) | 354 pca = PCA(n_components=5) |
341 | 355 |
342 # Resample and normalise features | 356 # Resample and normalise features |
357 step = ao.tempo_features.shape[0] | |
343 ao.gammatone_features = resample(ao.gammatone_features, step) | 358 ao.gammatone_features = resample(ao.gammatone_features, step) |
344 ao.gammatone_features = normaliseFeature(ao.gammatone_features) | 359 ao.gammatone_features = normaliseFeature(ao.gammatone_features) |
345 ao.timbre_features = resample(ao.timbre_features, step) | 360 ao.timbre_features = resample(ao.timbre_features, step) |
346 ao.timbre_features = normaliseFeature(ao.timbre_features) | 361 ao.timbre_features = normaliseFeature(ao.timbre_features) |
347 ao.harmonic_features = resample(ao.harmonic_features, step) | 362 ao.harmonic_features = resample(ao.harmonic_features, step) |
348 ao.harmonic_features = normaliseFeature(ao.harmonic_features) | 363 ao.harmonic_features = normaliseFeature(ao.harmonic_features) |
349 ao.tempo_features = normaliseFeature(ao.harmonic_features) | 364 ao.tempo_features = normaliseFeature(ao.tempo_features) |
350 | 365 |
351 pca.fit(ao.gammatone_features) | 366 pca.fit(ao.gammatone_features) |
352 ao.gammatone_features = pca.transform(ao.gammatone_features) | 367 ao.gammatone_features = pca.transform(ao.gammatone_features) |
353 ao.gammatone_ssm = getSSM(ao.gammatone_features) | 368 ao.gammatone_ssm = getSSM(ao.gammatone_features) |
354 | 369 |
377 outfile5 = join(options.OUTPUT, 'combined_novelty.csv') | 392 outfile5 = join(options.OUTPUT, 'combined_novelty.csv') |
378 outfile6 = join(options.OUTPUT, 'combined_foote.csv') | 393 outfile6 = join(options.OUTPUT, 'combined_foote.csv') |
379 outfile7 = join(options.OUTPUT, 'combined_sf.csv') | 394 outfile7 = join(options.OUTPUT, 'combined_sf.csv') |
380 outfile8 = join(options.OUTPUT, 'combined_cnmf.csv') | 395 outfile8 = join(options.OUTPUT, 'combined_cnmf.csv') |
381 | 396 |
382 self.wirteIndividualHeader(outfile1) | 397 outfile9 = join(options.OUTPUT, 'individual_merged.csv') |
383 self.wirteIndividualHeader(outfile2) | 398 |
384 self.wirteIndividualHeader(outfile3) | 399 self.writeIndividualHeader(outfile1) |
385 self.wirteIndividualHeader(outfile4) | 400 self.writeIndividualHeader(outfile2) |
386 | 401 self.writeIndividualHeader(outfile3) |
387 # self.wirteCombinedlHeader(outfile5) | 402 self.writeIndividualHeader(outfile4) |
388 # self.wirteCombinedlHeader(outfile6) | 403 |
389 self.wirteCombinedlHeader(outfile7) | 404 # self.writeCombinedHeader(outfile5) |
390 # self.wirteCombinedlHeader(outfile8) | 405 # self.writeCombinedHeader(outfile6) |
406 self.writeCombinedHeader(outfile7) | |
407 self.writeCombinedHeader(outfile8) | |
408 | |
409 self.writeMergedHeader(outfile9) | |
391 | 410 |
392 print 'Segmenting using %s method' %options.BOUNDARY | 411 print 'Segmenting using %s method' %options.BOUNDARY |
393 for i,ao in enumerate(audio_list): | 412 for i,ao in enumerate(audio_list): |
394 print 'processing: %s' %ao.name | 413 print 'processing: %s' %ao.name |
395 | 414 |
451 tempo_foote_05 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | 470 tempo_foote_05 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
452 tempo_foote_3 = self.pairwiseF(ao.gt, tempo_foote_idxs, tolerance=3, 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) |
453 timbre_foote_05 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=0.5, 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) |
454 timbre_foote_3 = self.pairwiseF(ao.gt, timbre_foote_idxs, tolerance=3, 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) |
455 | 474 |
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) | 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) |
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) | 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) |
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) | 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) |
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) | 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) |
460 | 479 |
461 | 480 |
462 ############################################################################################################################################ | 481 ############################################################################################################################################ |
463 # Experiment 2: segmentation using combined features. | 482 # Experiment 2: segmentation using combined features. |
464 | 483 |
467 gt_tb = np.hstack([ao.gammatone_features, ao.timbre_features]) | 486 gt_tb = np.hstack([ao.gammatone_features, ao.timbre_features]) |
468 gt_tp = np.hstack([ao.gammatone_features, ao.tempo_features]) | 487 gt_tp = np.hstack([ao.gammatone_features, ao.tempo_features]) |
469 hm_tb = np.hstack([ao.harmonic_features, ao.timbre_features]) | 488 hm_tb = np.hstack([ao.harmonic_features, ao.timbre_features]) |
470 hm_tp = np.hstack([ao.harmonic_features, ao.tempo_features]) | 489 hm_tp = np.hstack([ao.harmonic_features, ao.tempo_features]) |
471 tb_tp = np.hstack([ao.timbre_features, ao.tempo_features]) | 490 tb_tp = np.hstack([ao.timbre_features, ao.tempo_features]) |
491 gt_hm_tb = np.hstack([ao.gammatone_features, ao.harmonic_features, ao.timbre_features]) | |
472 gt_hm_tp = np.hstack([ao.gammatone_features, ao.harmonic_features, ao.tempo_features]) | 492 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]) | 493 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]) | 494 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]) | 495 gt_hm_tb_tp = np.hstack([ao.gammatone_features, ao.harmonic_features, ao.timbre_features, ao.tempo_features]) |
476 | 496 |
497 # Evaluting and writing results. | |
477 gt_hm_sf_idxs = sf_S.segmentation(gt_hm) | 498 gt_hm_sf_idxs = sf_S.segmentation(gt_hm) |
478 gt_tb_sf_idxs = sf_S.segmentation(gt_tb) | 499 gt_tb_sf_idxs = sf_S.segmentation(gt_tb) |
479 gt_tp_sf_idxs = sf_S.segmentation(gt_tp) | 500 gt_tp_sf_idxs = sf_S.segmentation(gt_tp) |
480 hm_tb_sf_idxs = sf_S.segmentation(hm_tb) | 501 hm_tb_sf_idxs = sf_S.segmentation(hm_tb) |
481 hm_tp_sf_idxs = sf_S.segmentation(hm_tp) | 502 hm_tp_sf_idxs = sf_S.segmentation(hm_tp) |
484 gt_hm_tp_sf_idxs = sf_S.segmentation(gt_hm_tp) | 505 gt_hm_tp_sf_idxs = sf_S.segmentation(gt_hm_tp) |
485 gt_tb_tp_sf_idxs = sf_S.segmentation(gt_tb_tp) | 506 gt_tb_tp_sf_idxs = sf_S.segmentation(gt_tb_tp) |
486 hm_tb_tp_sf_idxs = sf_S.segmentation(hm_tb_tp) | 507 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) | 508 gt_hm_tb_tp_sf_idxs = sf_S.segmentation(gt_hm_tb_tp) |
488 | 509 |
489 gt_hm_05 = self.pairwiseF(ao.gt, gt_hm_sf_idxs, tolerance=0.5, combine=1.0) | 510 gt_hm_cnmf_idxs = cnmf_S.segmentation(gt_hm, rank=4, R=R, h=h, niter=300) |
490 gt_tb_05 = self.pairwiseF(ao.gt, gt_tb_sf_idxs, tolerance=0.5, combine=1.0) | 511 gt_tb_cnmf_idxs = cnmf_S.segmentation(gt_tb, rank=4, R=R, h=h, niter=300) |
491 gt_tp_05 = self.pairwiseF(ao.gt, gt_tp_sf_idxs, tolerance=0.5, combine=1.0) | 512 gt_tp_cnmf_idxs = cnmf_S.segmentation(gt_tp, rank=4, R=R, h=h, niter=300) |
492 hm_tb_05 = self.pairwiseF(ao.gt, hm_tb_sf_idxs, tolerance=0.5, combine=1.0) | 513 hm_tb_cnmf_idxs = cnmf_S.segmentation(hm_tb, rank=4, R=R, h=h, niter=300) |
493 hm_tp_05 = self.pairwiseF(ao.gt, hm_tp_sf_idxs, tolerance=0.5, combine=1.0) | 514 hm_tp_cnmf_idxs = cnmf_S.segmentation(hm_tp, rank=4, R=R, h=h, niter=300) |
494 tb_tp_05 = self.pairwiseF(ao.gt, tb_tp_sf_idxs, tolerance=0.5, combine=1.0) | 515 tb_tp_cnmf_idxs = cnmf_S.segmentation(tb_tp, rank=4, R=R, h=h, niter=300) |
495 gt_hm_tb_05 = self.pairwiseF(ao.gt, gt_hm_tb_sf_idxs, tolerance=0.5, combine=1.0) | 516 gt_hm_tb_cnmf_idxs = cnmf_S.segmentation(gt_hm_tb, rank=6, R=R, h=h, niter=300) |
496 gt_hm_tp_05 = self.pairwiseF(ao.gt, gt_hm_tp_sf_idxs, tolerance=0.5, combine=1.0) | 517 gt_hm_tp_cnmf_idxs = cnmf_S.segmentation(gt_hm_tp, rank=6, R=R, h=h, niter=300) |
497 gt_tb_tp_05 = self.pairwiseF(ao.gt, gt_tb_tp_sf_idxs, tolerance=0.5, combine=1.0) | 518 gt_tb_tp_cnmf_idxs = cnmf_S.segmentation(gt_tb_tp, rank=6, R=R, h=h, niter=300) |
498 hm_tb_tp_05 = self.pairwiseF(ao.gt, hm_tb_tp_sf_idxs, tolerance=0.5, combine=1.0) | 519 hm_tb_tp_cnmf_idxs = cnmf_S.segmentation(hm_tb_tp, rank=6, R=R, h=h, niter=300) |
499 gt_hm_tb_tp_05 = self.pairwiseF(ao.gt, gt_hm_tb_tp_sf_idxs, tolerance=0.5, combine=1.0) | 520 gt_hm_tb_tp_cnmf_idxs = cnmf_S.segmentation(gt_hm_tb_tp, rank=8, R=R, h=h, niter=300) |
500 | 521 |
501 gt_hm_3 = self.pairwiseF(ao.gt, gt_hm_sf_idxs, tolerance=3, combine=1.0) | 522 gt_hm_sf_05 = self.pairwiseF(ao.gt, gt_hm_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
502 gt_tb_3 = self.pairwiseF(ao.gt, gt_tb_sf_idxs, tolerance=3, combine=1.0) | 523 gt_tb_sf_05 = self.pairwiseF(ao.gt, gt_tb_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
503 gt_tp_3 = self.pairwiseF(ao.gt, gt_tp_sf_idxs, tolerance=3, combine=1.0) | 524 gt_tp_sf_05 = self.pairwiseF(ao.gt, gt_tp_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
504 hm_tb_3 = self.pairwiseF(ao.gt, hm_tb_sf_idxs, tolerance=3, combine=1.0) | 525 hm_tb_sf_05 = self.pairwiseF(ao.gt, hm_tb_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
505 hm_tp_3 = self.pairwiseF(ao.gt, hm_tp_sf_idxs, tolerance=3, combine=1.0) | 526 hm_tp_sf_05 = self.pairwiseF(ao.gt, hm_tp_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
506 tb_tp_3 = self.pairwiseF(ao.gt, tb_tp_sf_idxs, tolerance=3, combine=1.0) | 527 tb_tp_sf_05 = self.pairwiseF(ao.gt, tb_tp_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
507 gt_hm_tb_3 = self.pairwiseF(ao.gt, gt_hm_tb_sf_idxs, tolerance=3, combine=1.0) | 528 gt_hm_tb_sf_05 = self.pairwiseF(ao.gt, gt_hm_tb_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
508 gt_hm_tp_3 = self.pairwiseF(ao.gt, gt_hm_tp_sf_idxs, tolerance=3, combine=1.0) | 529 gt_hm_tp_sf_05 = self.pairwiseF(ao.gt, gt_hm_tp_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
509 gt_tb_tp_3 = self.pairwiseF(ao.gt, gt_tb_tp_sf_idxs, tolerance=3, combine=1.0) | 530 gt_tb_tp_sf_05 = self.pairwiseF(ao.gt, gt_tb_tp_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
510 hm_tb_tp_3 = self.pairwiseF(ao.gt, hm_tb_tp_sf_idxs, tolerance=3, combine=1.0) | 531 hm_tb_tp_sf_05 = self.pairwiseF(ao.gt, hm_tb_tp_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
511 gt_hm_tb_tp_3 = self.pairwiseF(ao.gt, gt_hm_tb_tp_sf_idxs, tolerance=3, combine=1.0) | 532 gt_hm_tb_tp_sf_05 = self.pairwiseF(ao.gt, gt_hm_tb_tp_sf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) |
533 | |
534 gt_hm_sf_3 = self.pairwiseF(ao.gt, gt_hm_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
535 gt_tb_sf_3 = self.pairwiseF(ao.gt, gt_tb_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
536 gt_tp_sf_3 = self.pairwiseF(ao.gt, gt_tp_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
537 hm_tb_sf_3 = self.pairwiseF(ao.gt, hm_tb_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
538 hm_tp_sf_3 = self.pairwiseF(ao.gt, hm_tp_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
539 tb_tp_sf_3 = self.pairwiseF(ao.gt, tb_tp_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
540 gt_hm_tb_sf_3 = self.pairwiseF(ao.gt, gt_hm_tb_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
541 gt_hm_tp_sf_3 = self.pairwiseF(ao.gt, gt_hm_tp_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
542 gt_tb_tp_sf_3 = self.pairwiseF(ao.gt, gt_tb_tp_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
543 hm_tb_tp_sf_3 = self.pairwiseF(ao.gt, hm_tb_tp_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
544 gt_hm_tb_tp_sf_3 = self.pairwiseF(ao.gt, gt_hm_tb_tp_sf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
545 | |
546 gt_hm_cnmf_05 = self.pairwiseF(ao.gt, gt_hm_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
547 gt_tb_cnmf_05 = self.pairwiseF(ao.gt, gt_tb_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
548 gt_tp_cnmf_05 = self.pairwiseF(ao.gt, gt_tp_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
549 hm_tb_cnmf_05 = self.pairwiseF(ao.gt, hm_tb_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
550 hm_tp_cnmf_05 = self.pairwiseF(ao.gt, hm_tp_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
551 tb_tp_cnmf_05 = self.pairwiseF(ao.gt, tb_tp_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
552 gt_hm_tb_cnmf_05 = self.pairwiseF(ao.gt, gt_hm_tb_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
553 gt_hm_tp_cnmf_05 = self.pairwiseF(ao.gt, gt_hm_tp_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
554 gt_tb_tp_cnmf_05 = self.pairwiseF(ao.gt, gt_tb_tp_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
555 hm_tb_tp_cnmf_05 = self.pairwiseF(ao.gt, hm_tb_tp_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
556 gt_hm_tb_tp_cnmf_05 = self.pairwiseF(ao.gt, gt_hm_tb_tp_cnmf_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
557 | |
558 gt_hm_cnmf_3 = self.pairwiseF(ao.gt, gt_hm_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
559 gt_tb_cnmf_3 = self.pairwiseF(ao.gt, gt_tb_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
560 gt_tp_cnmf_3 = self.pairwiseF(ao.gt, gt_tp_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
561 hm_tb_cnmf_3 = self.pairwiseF(ao.gt, hm_tb_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
562 hm_tp_cnmf_3 = self.pairwiseF(ao.gt, hm_tp_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
563 tb_tp_cnmf_3 = self.pairwiseF(ao.gt, tb_tp_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
564 gt_hm_tb_cnmf_3 = self.pairwiseF(ao.gt, gt_hm_tb_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
565 gt_hm_tp_cnmf_3 = self.pairwiseF(ao.gt, gt_hm_tp_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
566 gt_tb_tp_cnmf_3 = self.pairwiseF(ao.gt, gt_tb_tp_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
567 hm_tb_tp_cnmf_3 = self.pairwiseF(ao.gt, hm_tb_tp_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
568 gt_hm_tb_tp_cnmf_3 = self.pairwiseF(ao.gt, gt_hm_tb_tp_cnmf_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
512 | 569 |
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\ | 570 self.writeCombinedRes(outfile7, ao.name, gt_hm_sf_05, gt_hm_sf_3, gt_tb_sf_05, gt_tb_sf_3, gt_tp_sf_05, gt_tp_sf_3, hm_tb_sf_05, hm_tb_sf_3, hm_tp_sf_05, hm_tp_sf_3, tb_tp_sf_05, tb_tp_sf_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) | 571 gt_hm_tb_sf_05, gt_hm_tb_sf_3, gt_hm_tp_sf_05, gt_hm_tp_sf_3, gt_tb_tp_sf_05, gt_tb_tp_sf_3, hm_tb_tp_sf_05, hm_tb_tp_sf_3, gt_hm_tb_tp_sf_05, gt_hm_tb_tp_sf_3) |
572 | |
573 self.writeCombinedRes(outfile8, ao.name, gt_hm_cnmf_05, gt_hm_cnmf_3, gt_tb_cnmf_05, gt_tb_cnmf_3, gt_tp_cnmf_05, gt_tp_cnmf_3, hm_tb_cnmf_05, hm_tb_cnmf_3, hm_tp_cnmf_05, hm_tp_cnmf_3, tb_tp_cnmf_05, tb_tp_cnmf_3,\ | |
574 gt_hm_tb_cnmf_05, gt_hm_tb_cnmf_3, gt_hm_tp_cnmf_05, gt_hm_tp_cnmf_3, gt_tb_tp_cnmf_05, gt_tb_tp_cnmf_3, hm_tb_tp_cnmf_05, hm_tb_tp_cnmf_3, gt_hm_tb_tp_cnmf_05, gt_hm_tb_tp_cnmf_3) | |
515 | 575 |
516 ############################################################################################################################################ | 576 ############################################################################################################################################ |
517 # Experiment 3: Pruning boundaries detected by individual boundary algorithms. | 577 # Experiment 3: Pruning boundaries detected by individual boundary algorithms. |
518 | 578 |
519 | 579 # Use different boundary methods for different features |
580 gammatone_idxs, harmonic_idxs, timbre_idxs, tempo_idxs = gammatone_sf_idxs, harmonic_sf_idxs, timbre_sf_idxs, tempo_sf_idxs | |
581 bound_candidates = list(gammatone_idxs) + list(harmonic_idxs) + list(timbre_idxs) + list(tempo_idxs) | |
582 bound_candidates.sort() | |
583 | |
584 nBounds = len(bound_candidates) | |
585 final_idxs = [] | |
586 idx = 0 | |
587 tol = 10 # tolerance window of merging boundary scores | |
588 while idx < nBounds: | |
589 temp = [bound_candidates[idx]] | |
590 pos = [idx] | |
591 idx += 1 | |
592 while (idx + tol < nBounds and np.max(bound_candidates[idx: idx+tol]) > 0): | |
593 temp += [bound_candidates[idx+delta] for delta in xrange(tol) if (bound_candidates[idx]+delta in bound_candidates)] | |
594 pos += [idx+delta for delta in xrange(tol) if (bound_candidates[idx]+delta in bound_candidates)] | |
595 idx += tol | |
596 if len(temp) == 1: | |
597 final_idxs.append(temp[0]) | |
598 else: | |
599 final_idxs.append(int(np.rint(np.mean(temp)))) | |
600 | |
601 merged_05 = self.pairwiseF(ao.gt, final_idxs, tolerance=0.5, combine=1.0, idx2time=ao.ssm_timestamps) | |
602 merged_3 = self.pairwiseF(ao.gt, final_idxs, tolerance=3, combine=1.0, idx2time=ao.ssm_timestamps) | |
603 | |
604 self.writeMergedRes(outfile9, ao.name, merged_05, merged_3) | |
605 | |
520 # if options.BOUNDARY == 'novelty': | 606 # if options.BOUNDARY == 'novelty': |
521 # gammatone_novelty, smoothed_gammatone_novelty, gammatone_bound_idxs = novelty_S.process(ao.gammatone_ssm, self.kernel_size, peak_picker) | 607 # 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) | 608 # 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) | 609 # 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) | 610 # harmonic_novelty, smoothed_tempo_novelty, harmonic_bound_idxs = novelty_S.process(ao.harmonic_ssm, self.kernel_size, peak_picker) |