mi@0: #!/usr/bin/env python mi@0: # encoding: utf-8 mi@0: """ mi@0: feature_combine_seg.py mi@0: mi@0: A script to evaluation script for the segmentation results using combinations of different features. mi@0: """ mi@0: mi@0: import matplotlib mi@0: # matplotlib.use('Agg') mi@0: import sys, os, optparse, csv mi@0: from itertools import combinations mi@0: from os.path import join, isdir, isfile, abspath, dirname, basename, split, splitext mi@0: from copy import copy mi@0: from mvpa2.suite import * mi@0: mi@0: import matplotlib.pyplot as plt mi@0: import matplotlib.gridspec as gridspec mi@0: import numpy as np mi@0: from scipy.signal import correlate2d, convolve2d, filtfilt, resample mi@0: from scipy.stats import mode mi@0: from scipy.ndimage import zoom mi@0: from scipy.ndimage.morphology import binary_fill_holes mi@0: from scipy.ndimage.filters import * mi@0: from scipy.spatial.distance import squareform, pdist mi@0: from sklearn.decomposition import PCA mi@0: from sklearn.mixture import GMM mi@0: from sklearn.preprocessing import normalize mi@0: from sklearn.metrics.pairwise import pairwise_distances mi@0: from skimage.transform import hough_line, hough_line_peaks, probabilistic_hough_line mi@0: from skimage.filter import canny, sobel mi@0: from skimage import data, measure, segmentation, morphology mi@0: mi@0: from PeakPickerUtil import PeakPicker mi@0: from gmmdist import * mi@0: from GmmMetrics import GmmDistance mi@0: from RankClustering import rClustering mi@0: from kmeans import Kmeans mi@0: mi@0: def parse_args(): mi@0: # define parser mi@0: op = optparse.OptionParser() mi@0: # IO options mi@0: op.add_option('-g', '--gammatonegram-features', action="store", dest="GF", default='/Volumes/c4dm-03/people/mit/features/gammatonegram/qupujicheng/2048', type="str", help="Loading features from.." ) mi@0: op.add_option('-s', '--spectrogram-features', action="store", dest="SF", default='/Volumes/c4dm-03/people/mit/features/spectrogram/qupujicheng/2048', type="str", help="Loading features from.." ) mi@0: op.add_option('-t', '--tempogram-features', action="store", dest="TF", default='/Volumes/c4dm-03/people/mit/features/tempogram/qupujicheng/tempo_features_6s', type="str", help="Loading features from.." ) mi@0: op.add_option('-a', '--annotations', action="store", dest="GT", default='/Volumes/c4dm-03/people/mit/annotation/qupujicheng/lowercase', type="str", help="Loading annotation files from.. ") mi@0: op.add_option('-o', '--ouput', action="store", dest="OUTPUT", default='/Volumes/c4dm-03/people/mit/segmentation/gammatone/qupujicheng', type="str", help="Write segmentation results to ") mi@0: op.add_option('-p', '--plot-novelty', action="store_true", dest="PLOT", default=False, help="Save novelty curev plot") mi@0: op.add_option('-e', '--test-mode', action="store_true", dest="TEST", default=False, help="Test mode") mi@0: op.add_option('-v', '--verbose-output', action="store_true", dest="VERBOSE", default=False, help="Exported raw detections.") mi@0: mi@0: return op.parse_args() mi@0: options, args = parse_args() mi@0: mi@0: class FeatureObj() : mi@0: __slots__ = ['key', 'audio', 'timestamps', 'gammatone_features', 'tempo_features', 'timbre_features', 'harmonic_features', 'gammatone_ssm', 'tempo_ssm', 'timbre_features', 'harmonic_ssm', 'ssm_timestamps'] mi@0: mi@0: class AudioObj(): mi@0: __slots__ = ['name', 'feature_list', 'gt', 'label', 'gammatone_features', 'tempo_features', 'timbre_features', 'harmonic_features', 'combined_features',\ mi@0: 'gammatone_ssm', 'tempo_ssm', 'timbre_ssm', 'harmonic_ssm', 'combined_ssm', 'ssm', 'ssm_timestamps', 'tempo_timestamps'] mi@0: mi@0: class EvalObj(): mi@0: __slots__ = ['TP', 'FP', 'FN', 'P', 'R', 'F', 'AD', 'DA'] mi@0: mi@0: class SSMseg(object): mi@0: '''The main segmentation object''' mi@0: def __init__(self): mi@0: self.SampleRate = 44100 mi@0: self.NqHz = self.SampleRate/2 mi@0: self.timestamp = [] mi@0: self.previousSample = 0.0 mi@0: self.featureWindow = 6.0 mi@0: self.featureStep = 3.0 mi@0: self.kernel_size = 80 # Adjust this param according to the feature resolution. mi@0: self.blockSize = 4094 mi@0: self.stepSize = 2048 mi@0: mi@0: '''NOTE: Match the following params with those used for feature extraction!''' mi@0: mi@0: '''NOTE: Unlike spectrogram ones, Gammatone features are extracted without an FFT or any overlap. The windowing is done under the purpose of chunking mi@0: the audio to facilitate the gammatone filtering. Despite of the overlap in the time domain, only the first half after the filtering is returned, mi@0: resulting in no overlapping effect in the extracted features. To obtain features for overlapped audio input, make the gammatoneLen equal to blockSize mi@0: and return the whole filter output.''' mi@0: self.gammatoneLen = 2048 mi@0: self.gammatoneBandGroups = [0, 16, 34, 50, 64] mi@0: self.nGammatoneBands = 20 mi@0: self.histRes = 40 mi@0: self.lowFreq = 100 mi@0: self.highFreq = self.SampleRate / 4 mi@0: mi@0: '''Settings for extracting tempogram features.''' mi@0: self.tempoWindow = 6.0 mi@0: self.bpmBands = [30, 45, 60, 80, 100, 120, 180, 240, 400, 600] mi@0: mi@0: '''Peak picking settings''' mi@0: self.threshold = 30 mi@0: self.delta_threshold = 0.5 mi@0: self.backtracking_threshold = 2.4 mi@0: self.polyfitting_on = True mi@0: self.medfilter_on = True mi@0: self.LPfilter_on = True mi@0: self.whitening_on = False mi@0: self.aCoeffs = [1.0000, -0.5949, 0.2348] mi@0: self.bCoeffs = [0.1600, 0.3200, 0.1600] mi@0: self.cutoff = 0.5 mi@0: self.medianWin = 5 mi@0: mi@0: def getGaussianParams(self, length, featureRate, timeWindow): mi@0: mi@0: win_len = round(timeWindow * featureRate) mi@0: win_len = win_len + (win_len % 2) - 1 mi@0: mi@0: # a 50% overlap between windows mi@0: stepsize = ceil(win_len * 0.5) mi@0: num_win = int(floor( (length) / stepsize)) mi@0: gaussian_rate = featureRate / stepsize mi@0: mi@0: return stepsize, num_win, win_len, gaussian_rate mi@0: mi@0: def GaussianDistance(self, feature, featureRate, timeWindow): mi@0: mi@0: stepsize, num_win, win_len, gr = self.getGaussianParams(feature.shape[0], featureRate, timeWindow) mi@0: print 'stepsize, num_win, feature', stepsize, num_win, feature.shape, featureRate, timeWindow mi@0: gaussian_list = [] mi@0: gaussian_timestamps = [] mi@0: tsi = 0 mi@0: mi@0: # f = open('/Users/mitian/Documents/experiments/features.txt','w') mi@0: # print 'divergence computing..' mi@0: for num in xrange(num_win): mi@0: # print num, num * stepsize , (num * stepsize) + win_len mi@0: gf=GaussianFeature(feature[int(num * stepsize) : int((num * stepsize) + win_len), :],2) mi@0: # f.write("\n%s" %str(gf)) mi@0: gaussian_list.append(gf) mi@0: tsi = int(floor( num * stepsize + 1)) mi@0: gaussian_timestamps.append(self.timestamp[tsi]) mi@0: mi@0: # f.close() mi@0: mi@0: # print 'gaussian_list', len(gaussian_list), len(gaussian_timestamps) mi@0: dm = np.zeros((len(gaussian_list), len(gaussian_list))) mi@0: mi@0: for v1, v2 in combinations(gaussian_list, 2): mi@0: i, j = gaussian_list.index(v1), gaussian_list.index(v2) mi@0: dm[i, j] = v1.distance(v2) mi@0: dm[j, i] = v2.distance(v1) mi@0: # print 'dm[i,j]',dm[i,j] mi@0: # sio.savemat("/Users/mitian/Documents/experiments/dm-from-segmenter.mat",{"dm":dm}) mi@0: return dm, gaussian_timestamps mi@0: mi@0: def gaussian_kernel(self, size): mi@0: '''Create a gaussian tapered 45 degrees rotated checkerboard kernel. mi@0: TODO: Unit testing: Should produce this with kernel size 3: mi@0: 0.1353 -0.3679 0.1353 mi@0: 0.3679 1.0000 0.3679 mi@0: 0.1353 -0.3679 0.1353 mi@0: ''' mi@0: n = float(np.ceil(size / 2.0)) mi@0: kernel = np.zeros((size,size)) mi@0: for i in xrange(1,size+1) : mi@0: for j in xrange(1,size+1) : mi@0: gauss = np.exp( -4.0 * (np.square( (i-n)/n ) + np.square( (j-n)/n )) ) mi@0: # gauss = 1 mi@0: if np.logical_xor( j - n > np.floor((i-n) / 2.0), j - n > np.floor((n-i) / 2.0) ) : mi@0: kernel[i-1,j-1] = -gauss mi@0: else: mi@0: kernel[i-1,j-1] = gauss mi@0: return kernel mi@0: mi@0: def getDiagonalSlice(self, ssm, width): mi@0: ''' Return a diagonal slice of the ssm given its width, with 45 degrees rotation. mi@0: Note: requres 45 degrees rotated kernel also.''' mi@0: w = int(np.floor(width/2.0)) mi@0: length = len(np.diagonal(ssm)) mi@0: slice = np.zeros((2*w+1,length)) mi@0: # print 'diagonal', length, w, slice.shape mi@0: for i in xrange(-w, w+1) : mi@0: slice[w+i,:] = np.hstack(( np.zeros(int(np.floor(abs(i)/2.0))), np.diagonal(ssm,i), np.zeros(int(np.ceil(abs(i)/2.0))) )) mi@0: return slice mi@0: mi@0: def getNoveltyCurve(self,dm, kernel_size): mi@0: '''Return novelty score from distance matrix.''' mi@0: mi@0: kernel_size = int(np.floor(kernel_size/2.0)+1) mi@0: slice = self.getDiagonalSlice(dm, kernel_size) mi@0: kernel = self.gaussian_kernel(kernel_size) mi@0: xc = convolve2d(slice,kernel,mode='same') mi@0: xc[abs(xc)>1e+10]=0.00001 mi@0: # print 'xc', xc.shape, xc mi@0: return xc[int(np.floor(xc.shape[0]/2.0)),:] mi@0: mi@0: def mergeBlocks(self, SSM, thresh=0.9, size=5): mi@0: '''Merge consequtive small blocks along the diagonal.''' mi@0: # found = False mi@0: # start = 0 mi@0: # i = 0 mi@0: # while i < len(SSM): mi@0: # j = i + 1 mi@0: # if found: start = i mi@0: # while(j < len(SSM) and SSM[i, j]): mi@0: # if (j-i) > size: mi@0: # found = True mi@0: # i = j mi@0: # # print 'start,end', start, i mi@0: # start = i mi@0: # else: mi@0: # found = False mi@0: # j += 1 mi@0: # if not found: mi@0: # print 'start,end', start, i mi@0: # SSM[start:i, start:i] = 0.9 mi@0: # i = j mi@0: idx = 1 mi@0: while idx < len(SSM): mi@0: i = 0 mi@0: # if ((idx-1-i) > 0 and (idx+1+i) < len(SSM)): mi@0: while ((idx-1-i) > 0 and (idx+1+i) < len(SSM) and SSM[idx-1-i, idx] > 0 and SSM[idx+1+i, idx] > 0): mi@0: i += 1 mi@0: if i > size/2: mi@0: SSM[idx-1-i:min(idx+i,len(SSM)), idx-1-i:min(idx+i,len(SSM))] = 1.0 mi@0: idx += max(1, i) mi@0: return SSM mi@0: mi@0: def getGMMs(self, feature, segment_boundaries): mi@0: '''Return GMMs for located segments''' mi@0: gmm_list = [] mi@0: gmm_list.append(GmmDistance(feature[: segment_boundaries[0], :], components = 1)) mi@0: for i in xrange(1, len(segment_boundaries)): mi@0: gmm_list.append(GmmDistance(feature[segment_boundaries[i-1] : segment_boundaries[i], :], components = 1)) mi@0: return gmm_list mi@0: mi@0: def trackValley(self, onset_index, smoothed_df): mi@0: '''Back track to the valley location of detected peaks''' mi@0: prevDiff = oldDiff = 0.0 mi@0: while (onset_index > 1) : mi@0: diff = smoothed_df[onset_index] - smoothed_df[onset_index-1] mi@0: # if (diff < 0.0 and 0 <= prevDiff < oldDiff * self.backtracking_threshold) : break mi@0: if (diff < 0 and prevDiff >= 0.1 * smoothed_df[onset_index]) : break mi@0: prevDiff = diff mi@0: oldDiff = prevDiff mi@0: onset_index -= 1 mi@0: return onset_index mi@0: mi@0: def normaliseFeature(self, feature_array): mi@0: mi@0: feature_array = np.array(feature_array) mi@0: feature_array[np.isnan(feature_array)] = 0.0 mi@0: feature_array[np.isinf(feature_array)] = 0.0 mi@0: mi@0: if len(feature_array.shape) == 1: mi@0: feature_array = (feature_array - feature_array.min()) / (feature_array.max() - feature_array.min()) mi@0: else: mi@0: mins = feature_array.min(axis=1) mi@0: maxs = feature_array.max(axis=1) mi@0: feature_array = (feature_array - mins[:, np.newaxis]) / (maxs - mins)[:, np.newaxis] mi@0: feature_array[np.isnan(feature_array)] = 0.0 mi@0: return feature_array mi@0: mi@0: def upSample(self, feature_array, step): mi@0: '''Resample downsized tempogram features, tempoWindo should be in accordance with input features''' mi@0: # print feature_array.shape mi@0: sampleRate = 44100 mi@0: stepSize = 1024.0 mi@0: # step = np.ceil(sampleRate/stepSize/5.0) mi@0: feature_array = zoom(feature_array, (step,1)) mi@0: # print 'resampled', feature_array.shape mi@0: return feature_array mi@0: mi@0: def stripeDistance(self, feature_array, feature_len, step, metric='cosine'): mi@0: '''Return distance matrix calculated for 2d time invariant features.''' mi@0: size = feature_array.shape[0] / feature_len mi@0: dm = np.zeros((size, size)) mi@0: mi@0: for i in xrange(size): mi@0: for j in xrange(i, size): mi@0: dm[i, j] = np.sum(pairwise_distances(feature_array[i*step:(i+1)*step, :], feature_array[j*step:(j+1)*step, :], metric)) mi@0: dm[j, i] = dm[i, j] mi@0: # print 'np.nanmax(dm)', np.nanmax(dm) mi@0: dm[np.isnan(dm)] = np.nanmax(dm) mi@0: ssm = 1 - (dm - dm.min()) / (dm.max() - dm.min()) mi@0: np.fill_diagonal(ssm, 1) mi@0: return ssm mi@0: mi@0: mi@0: def getMean(self, feature, winlen, stepsize): mi@0: means = [] mi@0: steps = int((feature.shape[0] - winlen + stepsize) / stepsize) mi@0: for i in xrange(steps): mi@0: means.append(np.mean(feature[i*stepsize:(i*stepsize+winlen), :], axis=0)) mi@0: return np.array(means) mi@0: mi@0: def getStd(self, feature, winlen, stepsize): mi@0: std = [] mi@0: steps = int((feature.shape[0] - winlen + stepsize) / stepsize) mi@0: for i in xrange(steps): mi@0: std.append(np.std(feature[i*stepsize:(i*stepsize+winlen), :], axis=0)) mi@0: return np.array(std) mi@0: mi@0: def getDelta(self, feature): mi@0: delta_feature = np.vstack((np.zeros((1, feature.shape[1])), np.diff(feature, axis=0))) mi@0: return delta_feature mi@0: mi@0: def backtrack(self, onset_index, smoothed_df): mi@0: '''Backtrack the onsets to an earlier 'perceived' location from the actually detected peak... mi@0: This is based on the rationale that the perceived onset tends to be a few frames before the detected peak. mi@0: This tracks the position in the detection function back to where the peak is startng to build up. mi@0: Notice the "out of the blue" parameter: 0.9. (Ideally, this should be tested, evaluated and reported...)''' mi@0: prevDiff = 0.0 mi@0: while (onset_index > 1) : mi@0: diff = smoothed_df[onset_index] - smoothed_df[onset_index-1] mi@0: if diff < prevDiff * self.backtracking_threshold : break mi@0: prevDiff = diff mi@0: onset_index -= 1 mi@0: return onset_index mi@0: mi@0: def trackDF(self, onset1_index, df2): mi@0: '''In the second round of detection, remove the known onsets from the DF by tracking from the peak given by the first round mi@0: to a valley to deminish the recognised peaks on top of which to start new detection.''' mi@0: for idx in xrange(len(onset1_index)) : mi@0: remove = True mi@0: for i in xrange(onset1_index[idx], 1, -1) : mi@0: if remove : mi@0: if df2[i] >= df2[i-1] : mi@0: df2[i] == 0.0 mi@0: else: mi@0: remove = False mi@0: return df2 mi@0: mi@0: def getSSM(self, feature_array, metric='cosine', norm='simple'): mi@0: '''Compute SSM given input feature array. mi@0: args: norm: ['simple', 'remove_noise'] mi@0: ''' mi@0: dm = pairwise_distances(feature_array, metric=metric) mi@0: dm = np.nan_to_num(dm) mi@0: if norm == 'simple': mi@0: ssm = 1 - (dm - np.min(dm)) / (np.max(dm) - np.min(dm)) mi@0: return ssm mi@0: mi@0: def reduceSSM(self, ssm, maxfilter_size = 2, remove_size=50): mi@0: ssm[ssm<0.8] = 0 mi@0: ssm = maximum_filter(ssm,size=maxfilter_size) mi@0: ssm = morphology.remove_small_objects(ssm.astype(bool), min_size=remove_size) mi@0: return ssm mi@0: mi@0: def getPeakFeatures(self, peak_candidates, featureset, winlen): mi@0: ''' mi@0: args: winlen: length of feature window before and after an investigated peak mi@0: featureset: A list of audio features for measuring the dissimilarity. mi@0: mi@0: return: peak_features mi@0: A list of tuples of features for windows before and after each peak. mi@0: ''' mi@0: prev_features = [] mi@0: post_features = [] mi@0: feature_types = len(featureset) mi@0: # print peak_candidates[-1], winlen, featureset[0].shape mi@0: # if peak_candidates[-1] + winlen > featureset[0].shape[0]: mi@0: # peak_candidates = peak_candidates[:-1] mi@0: # for x in peak_candidates: mi@0: # prev_features.append(tuple([featureset[i][x-winlen:x, :] for i in xrange(feature_types)])) mi@0: # post_features.append(tuple([featureset[i][x:x+winlen, :] for i in xrange(feature_types)])) mi@0: prev_features.append(tuple([featureset[i][:peak_candidates[0], :] for i in xrange(feature_types)])) mi@0: post_features.append(tuple([featureset[i][peak_candidates[0]:peak_candidates[1], :] for i in xrange(feature_types)])) mi@0: for idx in xrange(1, len(peak_candidates)-1): mi@0: prev_features.append(tuple([featureset[i][peak_candidates[idx-1]:peak_candidates[idx], :] for i in xrange(feature_types)])) mi@0: post_features.append(tuple([featureset[i][peak_candidates[idx]:peak_candidates[idx+1], :] for i in xrange(feature_types)])) mi@0: prev_features.append(tuple([featureset[i][peak_candidates[-2]:peak_candidates[-1], :] for i in xrange(feature_types)])) mi@0: post_features.append(tuple([featureset[i][peak_candidates[-1]:, :] for i in xrange(feature_types)])) mi@0: return prev_features, post_features mi@0: mi@0: def segmentDev(self, prev_features, post_features): mi@0: '''Deviations are measured for each given feature type. mi@0: peak_candidates: peaks from the 1st round detection mi@0: peak_features: Features for measuring the dissimilarity for parts before and after each peak. mi@0: dtype: tuple. mi@0: ''' mi@0: dev_list = [] mi@0: n_peaks = len(prev_features) mi@0: n_features = len(prev_features[0]) mi@0: # print 'n_peaks, n_features', n_peaks, n_features mi@0: for x in xrange(n_peaks): mi@0: f1, f2 = prev_features[x], post_features[x] mi@0: dev_list.append(tuple([GmmDistance(f1[i], components=1).skl_distance_full(GmmDistance(f2[i], components=1)) for i in xrange(n_features)])) mi@0: return dev_list mi@0: mi@0: def verifyPeaks(self, peak_canditates, dev_list): mi@0: '''Verify peaks from the 1st round detection by applying adaptive thresholding to the deviation list.''' mi@0: mi@0: final_peaks = copy(peak_canditates) mi@0: dev_list = np.array([np.mean(x) for x in dev_list]) # get average of devs of different features mi@0: med_dev = median_filter(dev_list, size=5) mi@0: # print dev_list, np.min(dev_list), np.median(dev_list), np.mean(dev_list), np.std(dev_list) mi@0: dev = dev_list - med_dev mi@0: # print dev mi@0: for i, x in enumerate(dev): mi@0: if x < 0: mi@0: final_peaks.remove(peak_canditates[i]) mi@0: return final_peaks mi@0: mi@0: def pairwiseF(self, annotation, detection, tolerance=3.0, combine=1.0): mi@0: '''Pairwise F measure evaluation of detection rates.''' mi@0: mi@0: # print 'detection', detection mi@0: res = EvalObj() mi@0: res.TP = 0 # Total number of matched ground truth and experimental data points mi@0: gt = len(annotation) # Total number of ground truth data points mi@0: dt = len(detection) # Total number of experimental data points mi@0: foundIdx = [] mi@0: D_AD = np.zeros(gt) mi@0: D_DA = np.zeros(dt) mi@0: mi@0: for dtIdx in xrange(dt): mi@0: # print detection[dtIdx], abs(detection[dtIdx] - annotation) mi@0: D_DA[dtIdx] = np.min(abs(detection[dtIdx] - annotation)) mi@0: # D_DA[dtIdx] = min([abs(annot - detection[dtIdx]) for annot in annotation]) mi@0: for gtIdx in xrange(gt): mi@0: D_AD[gtIdx] = np.min(abs(annotation[gtIdx] - detection)) mi@0: # D_AD[gtIdx] = min([abs(det - annotation[gtIdx]) for det in detection]) mi@0: for dtIdx in xrange(dt): mi@0: if (annotation[gtIdx] >= detection[dtIdx] - tolerance/2.0) and (annotation[gtIdx] <= detection[dtIdx] + tolerance/2.0): mi@0: res.TP = res.TP + 1.0 mi@0: foundIdx.append(gtIdx) mi@0: foundIdx = list(set(foundIdx)) mi@0: res.TP = len(foundIdx) mi@0: res.FP = dt - res.TP mi@0: res.FN = gt - res.TP mi@0: mi@0: res.AD = np.mean(D_AD) mi@0: res.DA = np.mean(D_DA) mi@0: mi@0: res.P, res.R, res.F = 0.0, 0.0, 0.0 mi@0: mi@0: if res.TP == 0: mi@0: return res mi@0: mi@0: res.P = res.TP / float(dt) mi@0: res.R = res.TP / float(gt) mi@0: # res.F = 2 * res.P * res.R / (res.P + res.F) mi@0: res.F = 2.0 / (1.0/res.P + 1.0/res.R) mi@0: # return TP3, FP3, FN3, pairwisePrecision3, pairwiseRecall3, pairwiseFValue3, TP05, FP05, FN05, pairwisePrecision05, pairwiseRecall05, pairwiseFValue05 mi@0: return res mi@0: mi@0: def plotDetection(self, ssm, novelty, smoothed_novelty, gt, det, filename): mi@0: '''Plot performance curve. mi@0: x axis: distance threshold for feature selection; y axis: f measure''' mi@0: mi@0: plt.figure(figsize=(10,16)) mi@0: gt_plot = gt / gt[-1] * len(novelty) mi@0: det_plot = det / gt[-1] * len(novelty) mi@0: mi@0: gs = gridspec.GridSpec(2, 1, height_ratios=[3,1]) mi@0: ax0 = plt.subplot(gs[0]) mi@0: ax1 = plt.subplot(gs[1], sharex=ax0) mi@0: mi@0: ax0.imshow(ssm) mi@0: ax0.vlines(gt_plot, 0, len(ssm), colors ='w', linestyles='solid') mi@0: ax0.vlines(det_plot, 0, len(ssm), colors='k', linestyles='dashed') mi@0: ax1.plot(np.linspace(0, len(novelty)-1, len(novelty)), novelty, 'g', np.linspace(0, len(novelty)-1, len(novelty)), smoothed_novelty,'b') mi@0: y_min, y_max = min([min(novelty), min(smoothed_novelty)]), max([max(novelty), max(smoothed_novelty)]) mi@0: ax1.vlines(gt_plot, y_min, y_max, colors ='r', linestyles='solid') mi@0: ax1.vlines(det_plot, y_min, y_max, colors='k', linestyles='dashed') mi@0: mi@0: # f, ax = plt.subplots(2, sharex=True) mi@0: # ax[0].imshow(ssm) mi@0: # ax[1].plot(np.linspace(0, len(novelty)-1, len(novelty)), novelty) mi@0: # ax[1].vlines(gt_plot, 0, len(novelty), colors ='r', linestyles='solid') mi@0: # ax[1].vlines(det_plot, 0, len(novelty), colors='b', linestyles='dashed') mi@0: # mi@0: # plt.show() mi@0: plt.savefig(filename) mi@0: mi@0: return None mi@0: mi@0: def process(self): mi@0: '''For the aggregated input features, discard a propertion each time as the pairwise distances within the feature space descending. mi@0: In the meanwhile evaluate the segmentation result and track the trend of perfomance changing by measuring the feature selection mi@0: threshold - segmentation f measure curve. mi@0: ''' mi@0: ssom = SimpleSOMMapper((30,30), 800, learning_rate=0.001) mi@0: mi@0: peak_picker = PeakPicker() mi@0: peak_picker.params.alpha = 9.0 # Alpha norm mi@0: peak_picker.params.delta = self.delta_threshold # Adaptive thresholding delta mi@0: peak_picker.params.QuadThresh_a = (100 - self.threshold) / 1000.0 mi@0: peak_picker.params.QuadThresh_b = 0.0 mi@0: peak_picker.params.QuadThresh_c = (100 - self.threshold) / 1500.0 mi@0: peak_picker.params.rawSensitivity = 20 mi@0: peak_picker.params.aCoeffs = self.aCoeffs mi@0: peak_picker.params.bCoeffs = self.bCoeffs mi@0: peak_picker.params.preWin = self.medianWin mi@0: peak_picker.params.postWin = self.medianWin + 1 mi@0: peak_picker.params.LP_on = self.LPfilter_on mi@0: peak_picker.params.Medfilt_on = self.medfilter_on mi@0: peak_picker.params.Polyfit_on = self.polyfitting_on mi@0: peak_picker.params.isMedianPositive = False mi@0: mi@0: # Settings used for feature extraction mi@0: feature_window_frame = int(self.SampleRate / self.gammatoneLen * self.featureWindow) mi@0: feature_step_frame = int(0.5 * self.SampleRate / self.gammatoneLen * self.featureStep) mi@0: aggregation_window, aggregation_step = 100, 50 mi@0: featureRate = float(self.SampleRate) / self.stepSize mi@0: mi@0: audio_files = [x for x in os.listdir(options.GT) if not x.startswith(".") ] mi@0: # audio_files = audio_files[:2] mi@0: audio_files.sort() mi@0: audio_list = [] mi@0: mi@0: gammatone_feature_list = [i for i in os.listdir(options.GF) if not i.startswith('.')] mi@0: gammatone_feature_list = ['rolloff', 'contrast'] mi@0: tempo_feature_list = [i for i in os.listdir(options.TF) if not i.startswith('.')] mi@0: # tempo_feature_list = ['intensity_bpm_renamed', 'loudness_bpm_renamed'] mi@0: timbre_feature_list = ['mfcc'] mi@0: harmonic_feature_list = ['nnls'] mi@0: mi@0: gammatone_feature_list = [join(options.GF, f) for f in gammatone_feature_list] mi@0: timbre_feature_list = [join(options.SF, f) for f in timbre_feature_list] mi@0: tempo_feature_list = [join(options.TF, f) for f in tempo_feature_list] mi@0: harmonic_feature_list = [join(options.SF, f) for f in harmonic_feature_list] mi@0: mi@0: fobj_list = [] mi@0: mi@0: # For each audio file, load specific features mi@0: for audio in audio_files: mi@0: ao = AudioObj() mi@0: ao.name = splitext(audio)[0] mi@0: # print 'audio:', ao.name mi@0: # annotation_file = join(options.GT, ao.name+'.txt') # iso, salami mi@0: # ao.gt = np.genfromtxt(annotation_file, usecols=0) mi@0: # ao.label = np.genfromtxt(annotation_file, usecols=1, dtype=str) mi@0: annotation_file = join(options.GT, ao.name+'.csv') # qupujicheng mi@0: ao.gt = np.genfromtxt(annotation_file, usecols=0, delimiter=',') mi@0: ao.label = np.genfromtxt(annotation_file, usecols=1, delimiter=',', dtype=str) mi@0: mi@0: gammatone_featureset, timbre_featureset, tempo_featureset, harmonic_featureset = [], [], [], [] mi@0: for feature in gammatone_feature_list: mi@0: for f in os.listdir(feature): mi@0: if f[:f.find('_vamp')]==ao.name: mi@0: gammatone_featureset.append(np.genfromtxt(join(feature, f), delimiter=',',filling_values=0.0)[:,1:]) mi@0: break mi@0: if len(gammatone_feature_list) > 1: mi@0: n_frame = np.min([x.shape[0] for x in gammatone_featureset]) mi@0: gammatone_featureset = [x[:n_frame,:] for x in gammatone_featureset] mi@0: ao.gammatone_features = np.hstack((gammatone_featureset)) mi@0: else: mi@0: ao.gammatone_features = gammatone_featureset[0] mi@0: mi@0: for feature in timbre_feature_list: mi@0: for f in os.listdir(feature): mi@0: if f[:f.find('_vamp')]==ao.name: mi@0: timbre_featureset.append(np.genfromtxt(join(feature, f), delimiter=',',filling_values=0.0)[:,1:]) mi@0: break mi@0: if len(timbre_feature_list) > 1: mi@0: n_frame = np.min([x.shape[0] for x in timbre_featureset]) mi@0: timbre_featureset = [x[:n_frame,:] for x in timbre_featureset] mi@0: ao.timbre_features = np.hstack((timbre_featureset)) mi@0: else: mi@0: ao.timbre_features = timbre_featureset[0] mi@0: for feature in tempo_feature_list: mi@0: for f in os.listdir(feature): mi@0: if f[:f.find('_vamp')]==ao.name: mi@0: tempo_featureset.append(np.genfromtxt(join(feature, f), delimiter=',',filling_values=0.0)[1:,1:]) mi@0: ao.tempo_timestamps = np.genfromtxt(join(feature, f), delimiter=',',filling_values=0.0)[1:,0] mi@0: break mi@0: if len(tempo_feature_list) > 1: mi@0: n_frame = np.min([x.shape[0] for x in tempo_featureset]) mi@0: tempo_featureset = [x[:n_frame,:] for x in tempo_featureset] mi@0: ao.tempo_features = np.hstack((tempo_featureset)) mi@0: else: mi@0: ao.tempo_features = tempo_featureset[0] mi@0: for feature in harmonic_feature_list: mi@0: for f in os.listdir(feature): mi@0: if f[:f.find('_vamp')]==ao.name: mi@0: harmonic_featureset.append(np.genfromtxt(join(feature, f), delimiter=',',filling_values=0.0)[:,1:]) mi@0: break mi@0: if len(harmonic_feature_list) > 1: mi@0: n_frame = np.min([x.shape[0] for x in harmonic_featureset]) mi@0: harmonic_featureset = [x[:n_frame,:] for x in harmonic_featureset] mi@0: ao.harmonic_features = np.hstack((harmonic_featureset)) mi@0: else: mi@0: ao.harmonic_features = harmonic_featureset[0] mi@0: mi@0: # # Reshaping features to keep identical dimension mi@0: # n_frames = np.array([ao.gammatone_features.shape[0], ao.harmonic_features.shape[0], ao.timbre_features.shape[0]]).min() mi@0: # step = n_frames / float(ao.tempo_features.shape[0]) mi@0: # # ao.tempo_features = self.upSample(ao.tempo_features, step) mi@0: # ao.gammatone_features = ao.gammatone_features[:n_frames, :] mi@0: # ao.harmonic_features = ao.harmonic_features[:n_frames, :] mi@0: # ao.timbre_features = ao.timbre_features[:n_frames, :] mi@0: # print ao.gammatone_features.shape, ao.harmonic_features.shape, ao.tempo_features.shape, ao.timbre_features.shape mi@0: mi@0: # Reshape features (downsample) to match tempogram ones mi@0: step = ao.tempo_features.shape[0] mi@0: # aggregation_step = (n_frames / (step+1.0)) mi@0: # Get aggregated features for computing ssm mi@0: aggregation_window, aggregation_step = 1,1 mi@0: featureRate = float(self.SampleRate) /self.stepSize mi@0: pca = PCA(n_components=5) mi@0: mi@0: ao.gammatone_features = resample(ao.gammatone_features, step) mi@0: ao.gammatone_features = (ao.gammatone_features - np.min(ao.gammatone_features, axis=-1)[:,np.newaxis]) / (np.max(ao.gammatone_features, axis=-1) - np.min(ao.gammatone_features, axis=-1))[:,np.newaxis] mi@0: ao.gammatone_features[np.isnan(ao.gammatone_features)] = 0.0 mi@0: ao.gammatone_features[np.isinf(ao.gammatone_features)] = 0.0 mi@0: ao.timbre_features = resample(ao.timbre_features, step) mi@0: ao.timbre_features = (ao.timbre_features - np.min(ao.timbre_features, axis=-1)[:,np.newaxis]) / (np.max(ao.timbre_features, axis=-1) - np.min(ao.timbre_features, axis=-1))[:,np.newaxis] mi@0: ao.timbre_features[np.isnan(ao.timbre_features)] = 0.0 mi@0: ao.timbre_features[np.isinf(ao.timbre_features)] = 0.0 mi@0: ao.harmonic_features = resample(ao.harmonic_features, step) mi@0: ao.harmonic_features = (ao.harmonic_features - np.min(ao.harmonic_features, axis=-1)[:,np.newaxis]) / (np.max(ao.harmonic_features, axis=-1) - np.min(ao.harmonic_features, axis=-1))[:,np.newaxis] mi@0: ao.harmonic_features[np.isnan(ao.harmonic_features)] = 0.0 mi@0: ao.harmonic_features[np.isinf(ao.harmonic_features)] = 0.0 mi@0: ao.tempo_features = (ao.tempo_features - np.min(ao.tempo_features, axis=-1)[:,np.newaxis]) / (np.max(ao.tempo_features, axis=-1) - np.min(ao.tempo_features, axis=-1))[:,np.newaxis] mi@0: ao.tempo_features[np.isnan(ao.tempo_features)] = 0.0 mi@0: ao.tempo_features[np.isinf(ao.tempo_features)] = 0.0 mi@0: # print 'resampled', ao.gammatone_features.shape, ao.timbre_features.shape, ao.harmonic_features.shape mi@0: # gt_feature_matrix = (ao.gammatone_features - np.min(ao.gammatone_features, axis=-1)[:,np.newaxis]) / (np.max(ao.gammatone_features, axis=-1) - np.min(ao.gammatone_features, axis=-1))[:,np.newaxis] mi@0: # gt_feature_matrix[np.isnan(gt_feature_matrix)] = 0.0 mi@0: # mean_gt_feature = self.getMean(gt_feature_matrix, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # std_gt_feature = self.getStd(gt_feature_matrix, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # delta_gt_feature = self.getDelta(gt_feature_matrix) mi@0: # mean_dgt_feature = self.getMean(delta_gt_feature, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # std_dgt_feature = self.getStd(delta_gt_feature, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # aggregated_gt_feature = np.hstack((mean_gt_feature, std_gt_feature)) mi@0: # aggregated_gt_feature = np.hstack((mean_gt_feature, std_gt_feature, mean_dgt_feature, std_dgt_feature)) mi@0: # aggregated_gt_feature = ao.gammatone_features mi@0: aggregated_gt_feature = self.getMean(ao.gammatone_features, winlen=aggregation_window, stepsize=aggregation_step) mi@0: pca.fit(aggregated_gt_feature) mi@0: aggregated_gt_feature = pca.transform(aggregated_gt_feature) mi@0: distance_gt_matrix = pairwise_distances(aggregated_gt_feature, metric = 'cosine') mi@0: distance_gt_matrix = np.nan_to_num(distance_gt_matrix) mi@0: ao.gammatone_ssm = 1 - (distance_gt_matrix - distance_gt_matrix.min()) / (distance_gt_matrix.max() - distance_gt_matrix.min()) mi@0: mi@0: # tempo_feature_matrix = (ao.tempo_features - np.min(ao.tempo_features, axis=-1)[:,np.newaxis]) / (np.max(ao.tempo_features, axis=-1) - np.min(ao.tempo_features, axis=-1))[:,np.newaxis] mi@0: # tempo_feature_matrix[np.isnan(tempo_feature_matrix)] = 0.0 mi@0: # mean_tempo_feature = self.getMean(tempo_feature_matrix, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # std_tempo_feature = self.getStd(tempo_feature_matrix, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # delta_tempo_feature = self.getDelta(tempo_feature_matrix) mi@0: # mean_dtempo_feature = self.getMean(delta_tempo_feature, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # std_dtempo_feature = self.getStd(delta_tempo_feature, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # aggregated_tempo_feature = np.hstack((mean_tempo_feature, std_tempo_feature)) mi@0: # aggregated_tempo_feature = np.hstack((mean_tempo_feature, std_tempo_feature, mean_dtempo_feature, std_dtempo_feature)) mi@0: # aggregated_tempo_feature = ao.tempo_features mi@0: aggregated_tempo_feature = self.getMean(ao.tempo_features, winlen=aggregation_window, stepsize=aggregation_step) mi@0: pca.fit(aggregated_tempo_feature) mi@0: aggregated_tempo_feature = pca.transform(aggregated_tempo_feature) mi@0: distance_tempo_matrix = pairwise_distances(aggregated_tempo_feature, metric = 'cosine') mi@0: distance_tempo_matrix = np.nan_to_num(distance_tempo_matrix) mi@0: ao.tempo_ssm = 1 - (distance_tempo_matrix - distance_tempo_matrix.min()) / (distance_tempo_matrix.max() - distance_tempo_matrix.min()) mi@0: mi@0: # timbre_feature_matrix = (ao.timbre_features - np.min(ao.timbre_features, axis=-1)[:,np.newaxis]) / (np.max(ao.timbre_features, axis=-1) - np.min(ao.timbre_features, axis=-1))[:,np.newaxis] mi@0: # timbre_feature_matrix[np.isnan(timbre_feature_matrix)] = 0.0 mi@0: # mean_timbre_feature = self.getMean(timbre_feature_matrix, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # std_timbre_feature = self.getStd(timbre_feature_matrix, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # delta_timbre_feature = self.getDelta(timbre_feature_matrix) mi@0: # mean_dtimbre_feature = self.getMean(delta_timbre_feature, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # std_dtimbre_feature = self.getStd(delta_timbre_feature, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # aggregated_timbre_feature = np.hstack((mean_timbre_feature, std_timbre_feature) mi@0: # aggregated_timbre_feature = np.hstack((mean_timbre_feature, std_timbre_feature, mean_dtimbre_feature, std_dtimbre_feature)) mi@0: # aggregated_timbre_feature = ao.timbre_features mi@0: aggregated_timbre_feature = self.getMean(ao.timbre_features, winlen=aggregation_window, stepsize=aggregation_step) mi@0: pca.fit(aggregated_timbre_feature) mi@0: aggregated_timbre_feature = pca.transform(aggregated_timbre_feature) mi@0: distance_timbre_matrix = pairwise_distances(aggregated_timbre_feature, metric = 'cosine') mi@0: distance_timbre_matrix = np.nan_to_num(distance_timbre_matrix) mi@0: ao.timbre_ssm = 1 - (distance_timbre_matrix - distance_timbre_matrix.min()) / (distance_timbre_matrix.max() - distance_timbre_matrix.min()) mi@0: mi@0: # harmonic_feature_matrix = (ao.harmonic_features - np.min(ao.harmonic_features, axis=-1)[:,np.newaxis]) / (np.max(ao.harmonic_features, axis=-1) - np.min(ao.harmonic_features, axis=-1))[:,np.newaxis] mi@0: # harmonic_feature_matrix[np.isnan(harmonic_feature_matrix)] = 0.0 mi@0: # mean_harmonic_feature = self.getMean(harmonic_feature_matrix, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # std_harmonic_feature = self.getStd(harmonic_feature_matrix, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # delta_harmonic_feature = self.getDelta(harmonic_feature_matrix) mi@0: # mean_dharmonic_feature = self.getMean(delta_harmonic_feature, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # std_dharmonic_feature = self.getStd(delta_harmonic_feature, winlen=aggregation_window, stepsize=aggregation_step) mi@0: # aggregated_harmonic_feature = np.hstack((mean_harmonic_feature, std_harmonic_feature)) mi@0: # aggregated_harmonic_feature = np.hstack((mean_harmonic_feature, std_harmonic_feature, mean_dharmonic_feature, std_dharmonic_feature)) mi@0: aggregated_harmonic_feature = ao.harmonic_features mi@0: aggregated_harmonic_feature = self.getMean(ao.harmonic_features, winlen=aggregation_window, stepsize=aggregation_step) mi@0: pca.fit(aggregated_harmonic_feature) mi@0: aggregated_harmonic_feature = pca.transform(aggregated_harmonic_feature) mi@0: distance_harmonic_matrix = pairwise_distances(aggregated_harmonic_feature, metric = 'cosine') mi@0: distance_harmonic_matrix = np.nan_to_num(distance_harmonic_matrix) mi@0: ao.harmonic_ssm = 1 - (distance_harmonic_matrix - distance_harmonic_matrix.min()) / (distance_harmonic_matrix.max() - distance_harmonic_matrix.min()) mi@0: mi@0: ao.combined_features = np.hstack((aggregated_gt_feature, aggregated_harmonic_feature, aggregated_timbre_feature, aggregated_tempo_feature)) mi@0: pca.fit(ao.combined_features) mi@0: ao.combined_features = pca.transform(ao.combined_features) mi@0: distance_combined_matrix = pairwise_distances(ao.combined_features, metric = 'cosine') mi@0: distance_combined_matrix = np.nan_to_num(distance_combined_matrix) mi@0: ao.combined_ssm = 1 - (distance_combined_matrix - distance_combined_matrix.min()) / (distance_combined_matrix.max() - distance_combined_matrix.min()) mi@0: mi@0: # Resample timestamps mi@0: # ao.ssm_timestamps = np.array(map(lambda step: step * aggregation_step / featureRate, np.arange(0.0, aggregated_gt_feature.shape[0]))) mi@0: ao.ssm_timestamps = np.array(map(lambda x: ao.tempo_timestamps[aggregation_step*x], np.arange(0, ao.gammatone_ssm.shape[0]))) mi@0: # print ao.gammatone_ssm.shape, ao.tempo_ssm.shape, ao.timbre_ssm.shape, ao.harmonic_ssm.shape, len(ao.ssm_timestamps) mi@0: mi@0: # # Save SSMs. mi@0: # gammatone_ssm = copy(ao.gammatone_ssm) mi@0: # gammatone_ssm[gammatone_ssm<0.8]=0.0 mi@0: # plt.figure(figsize=(10, 10)) mi@0: # plt.vlines(ao.gt / ao.gt[-1] * gammatone_ssm.shape[0], 0, gammatone_ssm.shape[0], colors='r') mi@0: # plt.imshow(gammatone_ssm, cmap='Greys') mi@0: # plt.savefig(join(options.OUTPUT, 'ssm', ao.name+'-gammatone.pdf'),format='pdf') mi@0: # mi@0: # tempo_ssm = copy(ao.tempo_ssm) mi@0: # tempo_ssm[tempo_ssm<0.8]=0.0 mi@0: # plt.figure(figsize=(10, 10)) mi@0: # plt.vlines(ao.gt / ao.gt[-1] * tempo_ssm.shape[0], 0, tempo_ssm.shape[0], colors='r') mi@0: # plt.imshow(tempo_ssm, cmap='Greys') mi@0: # plt.savefig(join(options.OUTPUT, 'ssm', ao.name+'-tempo.pdf'),format='pdf') mi@0: # mi@0: # timbre_ssm = copy(ao.timbre_ssm) mi@0: # timbre_ssm[timbre_ssm<0.8]=0.0 mi@0: # plt.figure(figsize=(10, 10)) mi@0: # plt.vlines(ao.gt / ao.gt[-1] * timbre_ssm.shape[0], 0, timbre_ssm.shape[0], colors='r') mi@0: # plt.imshow(timbre_ssm, cmap='Greys') mi@0: # plt.savefig(join(options.OUTPUT, 'ssm', ao.name+'-timbre.pdf'),format='pdf') mi@0: # mi@0: # harmonic_ssm = copy(ao.harmonic_ssm) mi@0: # harmonic_ssm[harmonic_ssm<0.8]=0.0 mi@0: # plt.figure(figsize=(10, 10)) mi@0: # plt.vlines(ao.gt / ao.gt[-1] * harmonic_ssm.shape[0], 0, harmonic_ssm.shape[0], colors='r') mi@0: # plt.imshow(harmonic_ssm, cmap='Greys') mi@0: # plt.savefig(join(options.OUTPUT, 'ssm', ao.name+'-harmonic.pdf'),format='pdf') mi@0: # mi@0: # ssm_cleaned = copy(ao.combined_ssm) mi@0: # ssm_cleaned[ssm_cleaned<0.8] = 0 mi@0: # plt.figure(figsize=(10, 10)) mi@0: # plt.vlines(ao.gt / ao.gt[-1] * ssm_cleaned.shape[0], 0, ssm_cleaned.shape[0], colors='r') mi@0: # plt.imshow(ssm_cleaned, cmap='Greys') mi@0: # plt.savefig(join(options.OUTPUT, 'ssm', ao.name+'-combined.pdf'),format='pdf') mi@0: mi@0: audio_list.append(ao) mi@0: mi@0: # Evaluate individual segmentation results. mi@0: outfile1 = join(options.OUTPUT, 'individualSOM.csv') mi@0: with open(outfile1, 'a') as f: mi@0: csvwriter = csv.writer(f, delimiter=',') mi@0: 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', \ mi@0: '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', \ mi@0: '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', \ mi@0: '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', \ mi@0: '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', \ mi@0: 'tempo_tp_3', 'tempo_fp_3', 'tempo_fn_3', 'tempo_P_3', 'tempo_R_3', 'tempo_F_3', 'tempo_AD_3', 'tempo_DA_3']) mi@0: mi@0: # outfile4 = join(options.OUTPUT, 'individualResDF.csv') mi@0: # with open(outfile4, 'a') as f: mi@0: # csvwriter = csv.writer(f, delimiter=',') mi@0: # 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', \ mi@0: # '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', \ mi@0: # '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', \ mi@0: # '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', \ mi@0: # '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', \ mi@0: # 'tempo_tp_3', 'tempo_fp_3', 'tempo_fn_3', 'tempo_P_3', 'tempo_R_3', 'tempo_F_3', 'tempo_AD_3', 'tempo_DA_3']) mi@0: mi@0: # Fuse novelty curves from individual segmentation results. mi@0: outfile2 = join(options.OUTPUT, 'individualFuseSOM.csv') mi@0: with open(outfile2, 'a') as f: mi@0: csvwriter = csv.writer(f, delimiter=',') mi@0: 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',\ mi@0: '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', \ mi@0: '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', \ mi@0: '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', \ mi@0: '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']) mi@0: mi@0: mi@0: for i,ao in enumerate(audio_list): mi@0: mi@0: print 'processing self organizing maps for %s' %ao.name mi@0: mi@0: # 1.Novelty based segmentation. mi@0: # Correlate an Gaussian on the diagonal to contruct the novelty curve mi@0: # print 'ssm', ao.gammatone_ssm.shape, ao.timbre_ssm.shape, ao.tempo_ssm.shape, ao.harmonic_ssm.shape mi@0: ssom.train(ao.gammatone_features) mi@0: gammatone_som = ssom(ao.gammatone_features) mi@0: ssom.train(ao.timbre_features) mi@0: timbre_som = ssom(ao.timbre_features) mi@0: ssom.train(ao.tempo_features) mi@0: tempo_som = ssom(ao.tempo_features) mi@0: ssom.train(ao.harmonic_features) mi@0: harmonic_som = ssom(ao.harmonic_features) mi@0: mi@0: gammatone_harmonic_features = np.hstack((ao.gammatone_features, ao.harmonic_features)) mi@0: gammatone_timbre_features = np.hstack((ao.gammatone_features, ao.timbre_features)) mi@0: gammatone_tempo_features = np.hstack((ao.gammatone_features, ao.tempo_features)) mi@0: harmonic_timbre_features = np.hstack((ao.harmonic_features, ao.timbre_features)) mi@0: harmonic_tempo_features = np.hstack((ao.harmonic_features, ao.tempo_features)) mi@0: timbre_tempo_features = np.hstack((ao.timbre_features, ao.tempo_features)) mi@0: mi@0: gammatone_harmonic_timbre_features = np.hstack((ao.gammatone_features, ao.harmonic_features, ao.timbre_features)) mi@0: gammatone_harmonic_tempo_features = np.hstack((ao.gammatone_features, ao.harmonic_features, ao.tempo_features)) mi@0: gammatone_timbre_tempo_features = np.hstack((ao.gammatone_features, ao.timbre_features, ao.tempo_features)) mi@0: harmonic_timbre_tempo_features = np.hstack((ao.harmonic_features, ao.timbre_features, ao.tempo_features)) mi@0: mi@0: gammatone_harmonic_timbre_tempo_features = np.hstack((ao.gammatone_features, ao.harmonic_features, ao.timbre_features, ao.tempo_features)) mi@0: mi@0: ssom.train(gammatone_harmonic_features) mi@0: gammatone_harmonic_som = ssom(gammatone_harmonic_features) mi@0: ssom.train(gammatone_timbre_features) mi@0: gammatone_timbre_som = ssom(gammatone_timbre_features) mi@0: ssom.train(gammatone_tempo_features) mi@0: gammatone_tempo_som = ssom(gammatone_tempo_features) mi@0: ssom.train(harmonic_timbre_features) mi@0: harmonic_timbre_som = ssom(harmonic_timbre_features) mi@0: ssom.train(harmonic_timbre_features) mi@0: harmonic_timbre_som = ssom(harmonic_timbre_features) mi@0: ssom.train(harmonic_tempo_features) mi@0: harmonic_tempo_som = ssom(harmonic_tempo_features) mi@0: ssom.train(timbre_tempo_features) mi@0: timbre_tempo_som = ssom(timbre_tempo_features) mi@0: mi@0: ssom.train(gammatone_harmonic_timbre_features) mi@0: gammatone_harmonic_timbre_som = ssom(gammatone_harmonic_timbre_features) mi@0: ssom.train(gammatone_harmonic_tempo_features) mi@0: gammatone_harmonic_tempo_som = ssom(gammatone_harmonic_tempo_features) mi@0: ssom.train(gammatone_timbre_tempo_features) mi@0: gammatone_timbre_tempo_som = ssom(gammatone_timbre_tempo_features) mi@0: ssom.train(harmonic_timbre_tempo_features) mi@0: harmonic_timbre_tempo_som = ssom(harmonic_timbre_tempo_features) mi@0: mi@0: ssom.train(gammatone_harmonic_timbre_tempo_features) mi@0: gammatone_harmonic_timbre_tempo_som = ssom(gammatone_harmonic_timbre_tempo_features) mi@0: mi@0: gammatone_ssm = self.getSSM(gammatone_som) mi@0: harmonic_ssm = self.getSSM(harmonic_som) mi@0: timbre_ssm = self.getSSM(timbre_som) mi@0: tempo_ssm = self.getSSM(tempo_som) mi@0: gammatone_harmonic_ssm = self.getSSM(gammatone_harmonic_som) mi@0: gammatone_timbre_ssm = self.getSSM(gammatone_timbre_som) mi@0: gammatone_tempo_ssm = self.getSSM(gammatone_tempo_som) mi@0: harmonic_timbre_ssm = self.getSSM(harmonic_timbre_som) mi@0: harmonic_tempo_ssm = self.getSSM(harmonic_tempo_som) mi@0: timbre_tempo_ssm = self.getSSM(timbre_tempo_som) mi@0: gammatone_harmonic_timbre_ssm = self.getSSM(gammatone_harmonic_timbre_som) mi@0: gammatone_harmonic_tempo_ssm = self.getSSM(gammatone_harmonic_tempo_som) mi@0: gammatone_timbre_tempo_ssm = self.getSSM(gammatone_timbre_tempo_som) mi@0: harmonic_timbre_tempo_ssm = self.getSSM(harmonic_timbre_tempo_som) mi@0: gammatone_harmonic_timbre_tempo_ssm = self.getSSM(gammatone_harmonic_timbre_tempo_som) mi@0: mi@0: mi@0: # Noise removal in ssm mi@0: reduced_gammatone_ssm = self.reduceSSM(gammatone_ssm) mi@0: reduced_timbre_ssm = self.reduceSSM(timbre_ssm) mi@0: reduced_tempo_ssm = self.reduceSSM(ao.tempo_ssm) mi@0: reduced_harmonic_ssm = self.reduceSSM(ao.harmonic_ssm) mi@0: reduced_gammatone_harmonic_ssm = self.reduceSSM(gammatone_harmonic_ssm) mi@0: reduced_gammatone_timbre_ssm = self.reduceSSM(gammatone_timbre_ssm) mi@0: reduced_gammatone_tempo_ssm = self.reduceSSM(gammatone_tempo_ssm) mi@0: reduced_harmonic_timbre_ssm = self.reduceSSM(harmonic_timbre_ssm) mi@0: reduced_harmonic_tempo_ssm = self.reduceSSM(harmonic_tempo_ssm) mi@0: reduced_timbre_tempo_ssm = self.reduceSSM(timbre_tempo_ssm) mi@0: reduced_gammatone_harmonic_timbre_ssm = self.reduceSSM(gammatone_harmonic_timbre_ssm) mi@0: reduced_gammatone_harmonic_tempo_ssm = self.reduceSSM(gammatone_harmonic_tempo_ssm) mi@0: reduced_gammatone_timbre_tempo_ssm = self.reduceSSM(gammatone_timbre_tempo_ssm) mi@0: reduced_harmonic_timbre_tempo_ssm = self.reduceSSM(harmonic_timbre_tempo_ssm) mi@0: reduced_gammatone_harmonic_timbre_tempo_ssm = self.reduceSSM(gammatone_harmonic_timbre_tempo_ssm) mi@0: mi@0: mi@0: gammatone_novelty = self.getNoveltyCurve(reduced_gammatone_ssm, self.kernel_size) mi@0: gammatone_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gammatone_novelty] mi@0: timbre_novelty = self.getNoveltyCurve(reduced_timbre_ssm, self.kernel_size) mi@0: timbre_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in timbre_novelty] mi@0: tempo_novelty = self.getNoveltyCurve(reduced_tempo_ssm, self.kernel_size) mi@0: tempo_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in tempo_novelty] mi@0: harmonic_novelty = self.getNoveltyCurve(reduced_harmonic_ssm, self.kernel_size) mi@0: harmonic_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in harmonic_novelty] mi@0: mi@0: # Peak picking from the novelty curve mi@0: smoothed_gammatone_novelty, gammatone_novelty_peaks = peak_picker.process(gammatone_novelty) mi@0: gammatone_detection = [ao.ssm_timestamps[int(i)] for i in gammatone_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_timbre_novelty, timbre_novelty_peaks = peak_picker.process(timbre_novelty) mi@0: timbre_detection = [ao.ssm_timestamps[int(i)] for i in timbre_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_harmonic_novelty, harmonic_novelty_peaks = peak_picker.process(harmonic_novelty) mi@0: harmonic_detection = [ao.ssm_timestamps[int(i)] for i in harmonic_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_tempo_novelty, tempo_novelty_peaks = peak_picker.process(tempo_novelty) mi@0: tempo_detection = [ao.ssm_timestamps[int(i)] for i in tempo_novelty_peaks] + [ao.gt[-1]] mi@0: mi@0: gt_res_05 = self.pairwiseF(ao.gt, gammatone_detection, tolerance=0.5, combine=1.0) mi@0: gt_res_3 = self.pairwiseF(ao.gt, gammatone_detection, tolerance=3, combine=1.0) mi@0: harmonic_res_05 = self.pairwiseF(ao.gt, harmonic_detection, tolerance=0.5, combine=1.0) mi@0: harmonic_res_3 = self.pairwiseF(ao.gt, harmonic_detection, tolerance=3, combine=1.0) mi@0: tempo_res_05 = self.pairwiseF(ao.gt, tempo_detection, tolerance=0.5, combine=1.0) mi@0: tempo_res_3 = self.pairwiseF(ao.gt, tempo_detection, tolerance=3, combine=1.0) mi@0: timbre_res_05 = self.pairwiseF(ao.gt, timbre_detection, tolerance=0.5, combine=1.0) mi@0: timbre_res_3 = self.pairwiseF(ao.gt, timbre_detection, tolerance=3, combine=1.0) mi@0: mi@0: with open(outfile1, 'a') as f: mi@0: csvwriter = csv.writer(f, delimiter=',') mi@0: 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, \ mi@0: 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, \ mi@0: 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, \ mi@0: 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, \ mi@0: 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, \ mi@0: tempo_res_3.FN, tempo_res_3.P, tempo_res_3.R, tempo_res_3.F, tempo_res_3.AD, tempo_res_3.DA]) mi@0: mi@0: gt_hm_novelty = self.getNoveltyCurve(reduced_gammatone_harmonic_ssm, self.kernel_size) mi@0: gt_hm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_hm_novelty] mi@0: gt_tb_novelty = self.getNoveltyCurve(reduced_gammatone_timbre_ssm, self.kernel_size) mi@0: gt_tb_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tb_novelty] mi@0: gt_tp_novelty = self.getNoveltyCurve(reduced_gammatone_tempo_ssm, self.kernel_size) mi@0: gt_tp_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tp_novelty] mi@0: hm_tb_novelty = self.getNoveltyCurve(reduced_harmonic_timbre_ssm, self.kernel_size) mi@0: hm_tb_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in hm_tb_novelty] mi@0: hm_tp_novelty = self.getNoveltyCurve(reduced_harmonic_tempo_ssm, self.kernel_size) mi@0: hm_tp_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in hm_tp_novelty] mi@0: tb_tp_novelty = self.getNoveltyCurve(reduced_timbre_tempo_ssm, self.kernel_size) mi@0: tb_tp_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in tb_tp_novelty] mi@0: mi@0: smoothed_gt_tb_novelty, gt_tb_novelty_peaks = peak_picker.process(gt_tb_novelty) mi@0: gt_tb_detection = [ao.ssm_timestamps[int(i)] for i in gt_tb_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_gt_tp_novelty, gt_tp_novelty_peaks = peak_picker.process(gt_tp_novelty) mi@0: gt_tp_detection = [ao.ssm_timestamps[int(i)] for i in gt_tp_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_gt_hm_novelty, gt_hm_novelty_peaks = peak_picker.process(gt_hm_novelty) mi@0: gt_hm_detection = [ao.ssm_timestamps[int(i)] for i in gt_hm_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_tb_tp_novelty, tb_tp_novelty_peaks = peak_picker.process(tb_tp_novelty) mi@0: tb_tp_detection = [ao.ssm_timestamps[int(i)] for i in tb_tp_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_tb_hm_novelty, tb_hm_novelty_peaks = peak_picker.process(tb_hm_novelty) mi@0: tb_hm_detection = [ao.ssm_timestamps[int(i)] for i in tb_hm_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_tp_hm_novelty, tp_hm_novelty_peaks = peak_picker.process(tp_hm_novelty) mi@0: tp_hm_detection = [ao.ssm_timestamps[int(i)] for i in tp_hm_novelty_peaks] + [ao.gt[-1]] mi@0: mi@0: gt_tb_tp_novelty = self.getNoveltyCurve(reduced_gammatone_timbre_tempo_ssm, self.kernel_size) mi@0: gt_tb_tp_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tb_tp_novelty] mi@0: gt_tb_hm_novelty = self.getNoveltyCurve(reduced_gammatone_harmonic_timbre_ssm, self.kernel_size) mi@0: gt_tb_hm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tb_hm_novelty] mi@0: gt_tp_hm_novelty = self.getNoveltyCurve(reduced_gammatone_harmonic_tempo_ssm, self.kernel_size) mi@0: gt_tp_hm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tp_hm_novelty] mi@0: tb_tp_hm_novelty = self.getNoveltyCurve(reduced_harmonic_timbre_tempo_ssm, self.kernel_size) mi@0: tb_tp_hm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in tb_tp_hm_novelty] mi@0: gt_tb_tp_hm_novelty = self.getNoveltyCurve(reduced_gammatone_harmonic_timbre_tempo_ssm, self.kernel_size) mi@0: gt_tb_tp_hm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tb_tp_hm_novelty] mi@0: mi@0: smoothed_gt_tb_tp_novelty, gt_tb_tp_novelty_peaks = peak_picker.process(gt_tb_tp_novelty) mi@0: gt_tb_tp_detection = [ao.ssm_timestamps[int(i)] for i in gt_tb_tp_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_gt_tb_hm_novelty, gt_tb_hm_novelty_peaks = peak_picker.process(gt_tb_hm_novelty) mi@0: gt_tb_hm_detection = [ao.ssm_timestamps[int(i)] for i in gt_tb_hm_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_gt_tp_hm_novelty, gt_tp_hm_novelty_peaks = peak_picker.process(gt_tp_hm_novelty) mi@0: gt_tp_hm_detection = [ao.ssm_timestamps[int(i)] for i in gt_tp_hm_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_tb_tp_hm_novelty, tb_tp_hm_novelty_peaks = peak_picker.process(tb_tp_hm_novelty) mi@0: tb_tp_hm_detection = [ao.ssm_timestamps[int(i)] for i in tb_tp_hm_novelty_peaks] + [ao.gt[-1]] mi@0: smoothed_gt_tb_tp_hm_novelty, gt_tb_tp_hm_novelty_peaks = peak_picker.process(gt_tb_tp_hm_novelty) mi@0: gt_tb_tp_hm_detection = [ao.ssm_timestamps[int(i)] for i in gt_tb_tp_hm_novelty_peaks] + [ao.gt[-1]] mi@0: mi@0: # novelty_peaks = gt_tb_tp_hm_novelty_peaks mi@0: # novelty_detection = [ao.ssm_timestamps[int(i)] for i in novelty_peaks] + [ao.gt[-1]] mi@0: mi@0: if options.PLOT: mi@0: self.plotDetection(ao.ssm, novelty, smoothed_novelty, ao.gt, detection, filename=join(options.OUTPUT+ ao.name)+'.pdf') mi@0: mi@0: gt_tb_res_05 = self.pairwiseF(ao.gt, gt_tb_detection, tolerance=0.5, combine=1.0) mi@0: gt_tb_res_3 = self.pairwiseF(ao.gt, gt_tb_detection, tolerance=3, combine=1.0) mi@0: gt_tp_res_05 = self.pairwiseF(ao.gt, gt_tp_detection, tolerance=0.5, combine=1.0) mi@0: gt_tp_res_3 = self.pairwiseF(ao.gt, gt_tp_detection, tolerance=3, combine=1.0) mi@0: gt_hm_res_05 = self.pairwiseF(ao.gt, gt_hm_detection, tolerance=0.5, combine=1.0) mi@0: gt_hm_res_3 = self.pairwiseF(ao.gt, gt_hm_detection, tolerance=3, combine=1.0) mi@0: tb_tp_res_05 = self.pairwiseF(ao.gt, tb_tp_detection, tolerance=0.5, combine=1.0) mi@0: tb_tp_res_3 = self.pairwiseF(ao.gt, tb_tp_detection, tolerance=3, combine=1.0) mi@0: tb_hm_res_05 = self.pairwiseF(ao.gt, tb_hm_detection, tolerance=0.5, combine=1.0) mi@0: tb_hm_res_3 = self.pairwiseF(ao.gt, tb_hm_detection, tolerance=3, combine=1.0) mi@0: tp_hm_res_05 = self.pairwiseF(ao.gt, tp_hm_detection, tolerance=0.5, combine=1.0) mi@0: tp_hm_res_3 = self.pairwiseF(ao.gt, tp_hm_detection, tolerance=3, combine=1.0) mi@0: mi@0: gt_tb_tp_res_05 = self.pairwiseF(ao.gt, gt_tb_tp_detection, tolerance=0.5, combine=1.0) mi@0: gt_tb_tp_res_3 = self.pairwiseF(ao.gt, gt_tb_tp_detection, tolerance=3, combine=1.0) mi@0: gt_tb_hm_res_05 = self.pairwiseF(ao.gt, gt_tb_hm_detection, tolerance=0.5, combine=1.0) mi@0: gt_tb_hm_res_3 = self.pairwiseF(ao.gt, gt_tb_hm_detection, tolerance=3, combine=1.0) mi@0: gt_tp_hm_res_05 = self.pairwiseF(ao.gt, gt_tp_hm_detection, tolerance=0.5, combine=1.0) mi@0: gt_tp_hm_res_3 = self.pairwiseF(ao.gt, gt_tp_hm_detection, tolerance=3, combine=1.0) mi@0: tb_tp_hm_res_05 = self.pairwiseF(ao.gt, tb_tp_hm_detection, tolerance=0.5, combine=1.0) mi@0: tb_tp_hm_res_3 = self.pairwiseF(ao.gt, tb_tp_hm_detection, tolerance=3, combine=1.0) mi@0: mi@0: gt_tb_tp_hm_res_05 = self.pairwiseF(ao.gt, gt_tb_tp_hm_detection, tolerance=0.5, combine=1.0) mi@0: gt_tb_tp_hm_res_3 = self.pairwiseF(ao.gt, gt_tb_tp_hm_detection, tolerance=3, combine=1.0) mi@0: mi@0: mi@0: # Output detected segment locations. mi@0: if options.VERBOSE: mi@0: outdir = join(options.OUTPUT, 'detection', ao.name) mi@0: if not isdir(outdir): mi@0: os.mkdir(outdir) mi@0: np.savetxt(join(outdir, 'gammatone.csv'), gammatone_detection) mi@0: np.savetxt(join(outdir, 'timbre.csv'), timbre_detection) mi@0: np.savetxt(join(outdir, 'tempo.csv'), tempo_detection) mi@0: np.savetxt(join(outdir, 'harmonic.csv'), harmonic_detection) mi@0: mi@0: np.savetxt(join(outdir, 'gammatone_timbre_novelty.csv'), gt_tb_detection) mi@0: np.savetxt(join(outdir, 'gammatone_tempo_novelty.csv'), gt_tp_detection) mi@0: np.savetxt(join(outdir, 'gammatone_harmonic_novelty.csv'), gt_hm_detection) mi@0: np.savetxt(join(outdir, 'timbre_tempo_novelty.csv'), tb_tp_detection) mi@0: np.savetxt(join(outdir, 'timbre_harmonic_novelty.csv'), tb_hm_detection) mi@0: np.savetxt(join(outdir, 'tempo_harmonic_novelty.csv'), tp_hm_detection) mi@0: mi@0: np.savetxt(join(outdir, 'gammatone_timbre_tempo_novelty.csv'), gt_tb_tp_detection) mi@0: np.savetxt(join(outdir, 'gammatone_timbre_harmonic_novelty.csv'), gt_tb_hm_detection) mi@0: np.savetxt(join(outdir, 'gammatone_tempo_harmonic_novelty.csv'), gt_tp_hm_detection) mi@0: np.savetxt(join(outdir, 'timbre_tempo_harmonic_novelty.csv'), tb_tp_hm_detection) mi@0: np.savetxt(join(outdir, 'gammatone_timbre_tempo_harmonic_novelty.csv'), gt_tb_tp_hm_detection) mi@0: mi@0: # with open(outfile4, 'a') as f: mi@0: # csvwriter = csv.writer(f, delimiter=',') mi@0: # csvwriter.writerow([ao.name, gt_df_05.TP, gt_df_05.FP, gt_df_05.FN, gt_df_05.P, gt_df_05.R, gt_df_05.F, gt_df_05.AD, gt_df_05.DA, gt_df_3.TP, gt_df_3.FP, gt_df_3.FN, gt_df_3.P, \ mi@0: # gt_df_3.R, gt_df_3.F, gt_df_3.AD, gt_df_3.DA, harmonic_df_05.TP, harmonic_df_05.FP, harmonic_df_05.FN, harmonic_df_05.P, harmonic_df_05.R, harmonic_df_05.F, harmonic_df_05.AD, harmonic_df_05.DA, \ mi@0: # harmonic_df_3.TP, harmonic_df_3.FP, harmonic_df_3.FN, harmonic_df_3.P, harmonic_df_3.R, harmonic_df_3.F, harmonic_df_3.AD, harmonic_df_3.DA, timbre_df_05.TP, timbre_df_05.FP, \ mi@0: # timbre_df_05.FN, timbre_df_05.P, timbre_df_05.R, timbre_df_05.F, timbre_df_05.AD, timbre_df_05.DA, timbre_df_3.TP, timbre_df_3.FP, timbre_df_3.FN, timbre_df_3.P, timbre_df_3.R, timbre_df_3.F, \ mi@0: # timbre_df_3.AD, timbre_df_3.DA, tempo_df_05.TP, tempo_df_05.FP, tempo_df_05.FN, tempo_df_05.P, tempo_df_05.R, tempo_df_05.F, tempo_df_05.AD, tempo_df_05.DA, tempo_df_3.TP, tempo_df_3.FP, \ mi@0: # tempo_df_3.FN, tempo_df_3.P, tempo_df_3.R, tempo_df_3.F, tempo_df_3.AD, tempo_df_3.DA]) mi@0: mi@0: with open(outfile2, 'a') as f: mi@0: csvwriter = csv.writer(f, delimiter=',') mi@0: 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, \ mi@0: 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, \ mi@0: 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, \ mi@0: 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, \ mi@0: 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, \ mi@0: 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]) mi@0: mi@0: mi@0: # Verification of detected boundaries by novelty fusion from the first round mi@0: # ao_featureset = [ao.gammatone_features, ao.harmonic_features, ao.timbre_features, ao.tempo_features] mi@0: # winlen = 1.5 * self.SampleRate / self.stepSize mi@0: # prev_features, post_features = self.getPeakFeatures(gt_tb_tp_hm_novelty_peaks, ao_featureset, winlen=10) mi@0: # dev_list = self.segmentDev(prev_features, post_features) mi@0: # gt_tb_tp_hm_novelty_peaks = gt_tb_tp_hm_novelty_peaks[:len(dev_list)] mi@0: # # print 'len(dev_list)', len(dev_list), len(gt_tb_tp_hm_novelty_peaks) mi@0: # # print gt_tb_tp_hm_novelty_peaks, dev_list mi@0: # dev_mean = [np.mean(x) for x in dev_list] mi@0: # np.savetxt(join(options.OUTPUT, 'dev', ao.name+'.csv'), np.vstack((gt_tb_tp_hm_detection[:len(dev_list)], dev_mean)).T, delimiter=',') mi@0: # peak_verified = self.verifyPeaks(gt_tb_tp_hm_novelty_peaks, dev_list) mi@0: # mi@0: # verified_detection = [ao.ssm_timestamps[int(i)] for i in peak_verified] + [ao.gt[-1]] mi@0: # verified_detection_05 = self.pairwiseF(ao.gt, verified_detection, tolerance=0.5, combine=1.0) mi@0: # verified_detection_3 = self.pairwiseF(ao.gt, verified_detection, tolerance=3, combine=1.0) mi@0: # mi@0: # print gt_tb_tp_hm_res_05.TP, gt_tb_tp_hm_res_05.FP, gt_tb_tp_hm_res_05.FN, gt_tb_tp_hm_res_05.P, gt_tb_tp_hm_res_05.R, gt_tb_tp_hm_res_05.F mi@0: # print gt_tb_tp_hm_res_3.TP, gt_tb_tp_hm_res_3.FP, gt_tb_tp_hm_res_3.FN, gt_tb_tp_hm_res_3.P, gt_tb_tp_hm_res_3.R, gt_tb_tp_hm_res_3.F mi@0: # mi@0: # print verified_detection_05.TP, verified_detection_05.FP, verified_detection_05.FN, verified_detection_05.P, verified_detection_05.R, verified_detection_05.F mi@0: # print verified_detection_3.TP, verified_detection_3.FP, verified_detection_3.FN, verified_detection_3.P, verified_detection_3.R, verified_detection_3.F mi@0: mi@0: # if len(novelty_peaks): mi@0: # ao.gammatone_gmm = self.getGMMs(ao.gammatone_features, novelty_peaks) mi@0: # ao.harmonic_gmm = self.getGMMs(ao.harmonic_features, novelty_peaks) mi@0: # ao.tempo_gmm = self.getGMMs(ao.tempo_features, novelty_peaks) mi@0: # ao.timbre_gmm = self.getGMMs(ao.timbre_features, novelty_peaks) mi@0: # mi@0: # rc = rClustering(eps=1., k=8, rank='max_neighbors') mi@0: # rc.fit(ao.gammatone_gmm) mi@0: # gammatone_clf = rc.classification mi@0: # gammatone_neighborhood_size, gammatone_average_div, gammatone_node_rank = rc.getNodeRank() mi@0: # np.savetxt(join(options.OUTPUT, 'classification', ao.name+'-gammatone.csv'), np.vstack((novelty_detection[:-1], gammatone_clf)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'neighborhood_size', ao.name+'-gammatone.csv'), np.vstack((novelty_detection[:-1], gammatone_neighborhood_size)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'node_rank', ao.name+'-gammatone.csv'), np.vstack((novelty_detection[:-1], gammatone_average_div)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'average_div', ao.name+'-gammatone.csv'), np.vstack((novelty_detection[:-1], gammatone_node_rank)).T, delimiter=',') mi@0: # mi@0: # rc = rClustering(eps=1., k=8, rank='max_neighbors') mi@0: # rc.fit(ao.harmonic_gmm) mi@0: # harmonic_clf = rc.classification mi@0: # harmonic_neighborhood_size, harmonic_average_div, harmonic_node_rank = rc.getNodeRank() mi@0: # np.savetxt(join(options.OUTPUT, 'classification', ao.name+'-harmonic.csv'), np.vstack((novelty_detection[:-1], harmonic_clf)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'neighborhood_size', ao.name+'-harmonic.csv'), np.vstack((novelty_detection[:-1], harmonic_neighborhood_size)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'node_rank', ao.name+'-harmonic.csv'), np.vstack((novelty_detection[:-1], harmonic_average_div)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'average_div', ao.name+'-harmonic.csv'), np.vstack((novelty_detection[:-1], harmonic_node_rank)).T, delimiter=',') mi@0: # mi@0: # rc = rClustering(eps=1., k=8, rank='max_neighbors') mi@0: # rc.fit(ao.tempo_gmm) mi@0: # tempo_clf = rc.classification mi@0: # tempo_neighborhood_size, tempo_average_div, tempo_node_rank = rc.getNodeRank() mi@0: # np.savetxt(join(options.OUTPUT, 'classification', ao.name+'-tempo.csv'), np.vstack((novelty_detection[:-1], tempo_clf)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'neighborhood_size', ao.name+'-tempo.csv'), np.vstack((novelty_detection[:-1], tempo_neighborhood_size)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'node_rank', ao.name+'-tempo.csv'), np.vstack((novelty_detection[:-1], tempo_average_div)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'average_div', ao.name+'-tempo.csv'), np.vstack((novelty_detection[:-1], tempo_node_rank)).T, delimiter=',') mi@0: # mi@0: # rc = rClustering(eps=1., k=8, rank='max_neighbors') mi@0: # rc.fit(ao.timbre_gmm) mi@0: # timbre_clf = rc.classification mi@0: # timbre_neighborhood_size, timbre_average_div, timbre_node_rank = rc.getNodeRank() mi@0: # np.savetxt(join(options.OUTPUT, 'classification', ao.name+'-timbre.csv'), np.vstack((novelty_detection[:-1], timbre_clf)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'neighborhood_size', ao.name+'-timbre.csv'), np.vstack((novelty_detection[:-1], timbre_neighborhood_size)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'node_rank', ao.name+'-timbre.csv'), np.vstack((novelty_detection[:-1], timbre_average_div)).T, delimiter=',') mi@0: # np.savetxt(join(options.OUTPUT, 'average_div', ao.name+'-timbre.csv'), np.vstack((novelty_detection[:-1], timbre_node_rank)).T, delimiter=',') mi@0: mi@0: mi@0: # # Evaluate segmentation results using combined SSMs. mi@0: # outfile3 = join(options.OUTPUT, 'combinedSSMRes.csv') mi@0: # with open(outfile3, 'a') as f: mi@0: # csvwriter = csv.writer(f, delimiter=',') mi@0: # 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',\ mi@0: # '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', \ mi@0: # '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', \ mi@0: # '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', \ mi@0: # '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']) mi@0: # mi@0: # for i,ao in enumerate(audio_list): mi@0: # # Combine SSMs computed from different features mi@0: # gt_hm_ssm = np.multiply(ao.gammatone_ssm, ao.harmonic_ssm) mi@0: # gt_tb_ssm = np.multiply(ao.gammatone_ssm, ao.timbre_ssm) mi@0: # gt_tp_ssm = np.multiply(ao.gammatone_ssm, ao.tempo_ssm) mi@0: # tb_tp_ssm = np.multiply(ao.timbre_ssm, ao.tempo_ssm) mi@0: # tb_hm_ssm = np.multiply(ao.timbre_ssm, ao.harmonic_ssm) mi@0: # tp_hm_ssm = np.multiply(ao.tempo_ssm, ao.harmonic_ssm) mi@0: # mi@0: # gt_hm_tb_ssm = np.multiply(ao.gammatone_ssm, ao.harmonic_ssm, ao.timbre_ssm) mi@0: # gt_hm_tp_ssm = np.multiply(ao.gammatone_ssm, ao.harmonic_ssm, ao.tempo_ssm) mi@0: # gt_tb_tp_ssm = np.multiply(ao.gammatone_ssm, ao.timbre_ssm, ao.tempo_ssm) mi@0: # hm_tb_tp_ssm = np.multiply(ao.harmonic_ssm, ao.timbre_ssm, ao.tempo_ssm) mi@0: # mi@0: # gt_hm_tb_tp_ssm = np.multiply(np.multiply(ao.gammatone_ssm, ao.harmonic_ssm), np.multiply(ao.timbre_ssm, ao.tempo_ssm)) mi@0: # mi@0: # gt_hm_ssm_novelty = self.getNoveltyCurve(gt_hm_ssm, self.kernel_size) mi@0: # gt_hm_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_hm_ssm_novelty] mi@0: # gt_tb_ssm_novelty = self.getNoveltyCurve(gt_tb_ssm, self.kernel_size) mi@0: # gt_tb_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tb_ssm_novelty] mi@0: # gt_tp_ssm_novelty = self.getNoveltyCurve(gt_hm_ssm, self.kernel_size) mi@0: # gt_tp_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tp_ssm_novelty] mi@0: # tb_tp_ssm_novelty = self.getNoveltyCurve(tb_tp_ssm, self.kernel_size) mi@0: # tb_tp_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in tb_tp_ssm_novelty] mi@0: # tb_hm_ssm_novelty = self.getNoveltyCurve(tb_hm_ssm, self.kernel_size) mi@0: # tb_hm_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in tb_hm_ssm_novelty] mi@0: # tp_hm_ssm_novelty = self.getNoveltyCurve(tp_hm_ssm, self.kernel_size) mi@0: # tp_hm_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in tp_hm_ssm_novelty] mi@0: # mi@0: # gt_hm_tb_ssm_novelty = self.getNoveltyCurve(gt_hm_tb_ssm, self.kernel_size) mi@0: # gt_hm_tb_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_hm_tb_ssm_novelty] mi@0: # gt_hm_tp_ssm_novelty = self.getNoveltyCurve(gt_hm_tp_ssm, self.kernel_size) mi@0: # gt_hm_tp_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_hm_tp_ssm_novelty] mi@0: # gt_tb_tp_ssm_novelty = self.getNoveltyCurve(gt_tb_tp_ssm, self.kernel_size) mi@0: # gt_tb_tp_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_tb_tp_ssm_novelty] mi@0: # hm_tb_tp_ssm_novelty = self.getNoveltyCurve(hm_tb_tp_ssm, self.kernel_size) mi@0: # hm_tb_tp_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in hm_tb_tp_ssm_novelty] mi@0: # mi@0: # gt_hm_tb_tp_ssm_novelty = self.getNoveltyCurve(gt_hm_tb_tp_ssm, self.kernel_size) mi@0: # gt_hm_tb_tp_ssm_novelty = [0.0 if (np.isnan(x) or np.isinf(x) or x > 1e+100) else x for x in gt_hm_tb_tp_ssm_novelty] mi@0: # mi@0: # smoothed_gt_hm_ssm_novelty, gt_hm_ssm_novelty_peaks = peak_picker.process(gt_hm_ssm_novelty) mi@0: # gt_hm_ssm_detection = [ao.ssm_timestamps[int(i)] for i in gt_hm_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # smoothed_gt_tb_ssm_novelty, gt_tb_ssm_novelty_peaks = peak_picker.process(gt_tb_ssm_novelty) mi@0: # gt_tb_ssm_detection = [ao.ssm_timestamps[int(i)] for i in gt_tb_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # smoothed_gt_tp_ssm_novelty, gt_tp_ssm_novelty_peaks = peak_picker.process(gt_tp_ssm_novelty) mi@0: # gt_tp_ssm_detection = [ao.ssm_timestamps[int(i)] for i in gt_tp_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # smoothed_tb_tp_ssm_novelty, tb_tp_ssm_novelty_peaks = peak_picker.process(tb_tp_ssm_novelty) mi@0: # tb_tp_ssm_detection = [ao.ssm_timestamps[int(i)] for i in tb_tp_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # smoothed_tb_hm_ssm_novelty, tb_hm_ssm_novelty_peaks = peak_picker.process(tb_hm_ssm_novelty) mi@0: # tb_hm_ssm_detection = [ao.ssm_timestamps[int(i)] for i in tb_hm_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # smoothed_tp_hm_ssm_novelty, tp_hm_ssm_novelty_peaks = peak_picker.process(tp_hm_ssm_novelty) mi@0: # tp_hm_ssm_detection = [ao.ssm_timestamps[int(i)] for i in tp_hm_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # mi@0: # smoothed_gt_hm_tb_ssm_novelty, gt_hm_tb_ssm_novelty_peaks = peak_picker.process(gt_hm_tb_ssm_novelty) mi@0: # gt_hm_tb_ssm_detection = [ao.ssm_timestamps[int(i)] for i in gt_hm_tb_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # smoothed_gt_hm_tp_ssm_novelty, gt_hm_tp_ssm_novelty_peaks = peak_picker.process(gt_hm_tp_ssm_novelty) mi@0: # gt_hm_tp_ssm_detection = [ao.ssm_timestamps[int(i)] for i in gt_hm_tp_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # smoothed_gt_tb_tp_ssm_novelty, gt_tb_tp_ssm_novelty_peaks = peak_picker.process(gt_tb_tp_ssm_novelty) mi@0: # gt_tb_tp_ssm_detection = [ao.ssm_timestamps[int(i)] for i in gt_tb_tp_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # smoothed_hm_tb_tp_ssm_novelty, hm_tb_tp_ssm_novelty_peaks = peak_picker.process(hm_tb_tp_ssm_novelty) mi@0: # hm_tb_tp_ssm_detection = [ao.ssm_timestamps[int(i)] for i in hm_tb_tp_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # mi@0: # smoothed_gt_hm_tb_tp_ssm_novelty, gt_hm_tb_tp_ssm_novelty_peaks = peak_picker.process(gt_hm_tb_tp_ssm_novelty) mi@0: # gt_hm_tb_tp_ssm_detection = [ao.ssm_timestamps[int(i)] for i in gt_hm_tb_tp_ssm_novelty_peaks] + [ao.gt[-1]] mi@0: # mi@0: # # Output detected segment locations. mi@0: # if options.VERBOSE: mi@0: # outdir = join(options.OUTPUT, 'detection', ao.name) mi@0: # if not isdir(outdir): mi@0: # os.mkdir(outdir) mi@0: # mi@0: # np.savetxt(join(outdir, 'gammatone_timbre_ssm.csv'), gt_tb_ssm_detection) mi@0: # np.savetxt(join(outdir, 'gammatone_tempo_ssm.csv'), gt_tp_ssm_detection) mi@0: # np.savetxt(join(outdir, 'gammatone_harmonic_ssm.csv'), gt_hm_ssm_detection) mi@0: # np.savetxt(join(outdir, 'timbre_tempo_ssm.csv'), tb_tp_ssm_detection) mi@0: # np.savetxt(join(outdir, 'timbre_harmonic_ssm.csv'), tb_hm_ssm_detection) mi@0: # np.savetxt(join(outdir, 'tempo_harmonic_ssm.csv'), tp_hm_ssm_detection) mi@0: # mi@0: # np.savetxt(join(outdir, 'gammatone_timbre_tempo_ssm.csv'), gt_tb_tp_ssm_detection) mi@0: # np.savetxt(join(outdir, 'gammatone_timbre_harmonic_ssm.csv'), gt_hm_tb_ssm_detection) mi@0: # np.savetxt(join(outdir, 'gammatone_tempo_harmonic_ssm.csv'), gt_hm_tp_ssm_detection) mi@0: # np.savetxt(join(outdir, 'timbre_tempo_harmonic_ssm.csv'), hm_tb_tp_ssm_detection) mi@0: # np.savetxt(join(outdir, 'gammatone_timbre_tempo_harmonic_ssm.csv'), gt_hm_tb_tp_ssm_detection) mi@0: # mi@0: # gt_hm_ssm_res_05 = self.pairwiseF(ao.gt, gt_hm_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # gt_hm_ssm_res_3 = self.pairwiseF(ao.gt, gt_hm_ssm_detection, tolerance=3, combine=1.0) mi@0: # gt_tb_ssm_res_05 = self.pairwiseF(ao.gt, gt_tb_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # gt_tb_ssm_res_3 = self.pairwiseF(ao.gt, gt_tb_ssm_detection, tolerance=3, combine=1.0) mi@0: # gt_tp_ssm_res_05 = self.pairwiseF(ao.gt, gt_tp_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # gt_tp_ssm_res_3 = self.pairwiseF(ao.gt, gt_tp_ssm_detection, tolerance=3, combine=1.0) mi@0: # tb_tp_ssm_res_05 = self.pairwiseF(ao.gt, tb_tp_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # tb_tp_ssm_res_3 = self.pairwiseF(ao.gt, tb_tp_ssm_detection, tolerance=3, combine=1.0) mi@0: # tb_hm_ssm_res_05 = self.pairwiseF(ao.gt, tb_hm_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # tb_hm_ssm_res_3 = self.pairwiseF(ao.gt, tb_hm_ssm_detection, tolerance=3, combine=1.0) mi@0: # tp_hm_ssm_res_05 = self.pairwiseF(ao.gt, tp_hm_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # tp_hm_ssm_res_3 = self.pairwiseF(ao.gt, tp_hm_ssm_detection, tolerance=3, combine=1.0) mi@0: # mi@0: # gt_hm_tb_ssm_res_05 = self.pairwiseF(ao.gt, gt_hm_tb_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # gt_hm_tb_ssm_res_3 = self.pairwiseF(ao.gt, gt_hm_tb_ssm_detection, tolerance=3, combine=1.0) mi@0: # gt_hm_tp_ssm_res_05 = self.pairwiseF(ao.gt, gt_hm_tp_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # gt_hm_tp_ssm_res_3 = self.pairwiseF(ao.gt, gt_hm_tp_ssm_detection, tolerance=3, combine=1.0) mi@0: # gt_tb_tp_ssm_res_05 = self.pairwiseF(ao.gt, gt_tb_tp_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # gt_tb_tp_ssm_res_3 = self.pairwiseF(ao.gt, gt_tb_tp_ssm_detection, tolerance=3, combine=1.0) mi@0: # hm_tb_tp_ssm_res_05 = self.pairwiseF(ao.gt, hm_tb_tp_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # hm_tb_tp_ssm_res_3 = self.pairwiseF(ao.gt, hm_tb_tp_ssm_detection, tolerance=3, combine=1.0) mi@0: # mi@0: # gt_hm_tb_tp_ssm_res_05 = self.pairwiseF(ao.gt, gt_hm_tb_tp_ssm_detection, tolerance=0.5, combine=1.0) mi@0: # gt_hm_tb_tp_ssm_res_3 = self.pairwiseF(ao.gt, gt_hm_tb_tp_ssm_detection, tolerance=3, combine=1.0) mi@0: # mi@0: # with open(outfile3, 'a') as f: mi@0: # csvwriter = csv.writer(f, delimiter=',') mi@0: # csvwriter.writerow([ao.name, gt_tb_ssm_res_05.P, gt_tb_ssm_res_05.R, gt_tb_ssm_res_05.F, gt_tb_ssm_res_3.P, gt_tb_ssm_res_3.R, gt_tb_ssm_res_3.F, gt_tp_ssm_res_05.P, gt_tp_ssm_res_05.R, gt_tp_ssm_res_05.F, \ mi@0: # gt_tp_ssm_res_3.P, gt_tp_ssm_res_3.R, gt_tp_ssm_res_3.F, gt_hm_ssm_res_05.P, gt_hm_ssm_res_05.R, gt_hm_ssm_res_05.F, gt_hm_ssm_res_3.P, gt_hm_ssm_res_3.R, gt_hm_ssm_res_3.F, \ mi@0: # tb_tp_ssm_res_05.P, tb_tp_ssm_res_05.R, tb_tp_ssm_res_05.F, tb_tp_ssm_res_3.P, tb_tp_ssm_res_3.R, tb_tp_ssm_res_3.F, tb_hm_ssm_res_05.P, tb_hm_ssm_res_05.R, tb_hm_ssm_res_05.F, \ mi@0: # tb_hm_ssm_res_3.P, tb_hm_ssm_res_3.R, tb_hm_ssm_res_3.F, tp_hm_ssm_res_05.P, tp_hm_ssm_res_05.R, tp_hm_ssm_res_05.F, tp_hm_ssm_res_3.P, tp_hm_ssm_res_3.R, tp_hm_ssm_res_3.F, \ mi@0: # gt_tb_tp_ssm_res_05.P, gt_tb_tp_ssm_res_05.R, gt_tb_tp_ssm_res_05.F, gt_tb_tp_ssm_res_3.P, gt_tb_tp_ssm_res_3.R, gt_tb_tp_ssm_res_3.F, gt_hm_tb_ssm_res_05.P, gt_hm_tb_ssm_res_05.R, gt_hm_tb_ssm_res_05.F, \ mi@0: # gt_hm_tb_ssm_res_3.P, gt_hm_tb_ssm_res_3.R, gt_hm_tb_ssm_res_3.F, gt_hm_tp_ssm_res_05.P, gt_hm_tp_ssm_res_05.R, gt_hm_tp_ssm_res_05.F, gt_hm_tp_ssm_res_3.P, gt_hm_tp_ssm_res_3.R, gt_hm_tp_ssm_res_3.F, \ mi@0: # hm_tb_tp_ssm_res_05.P, hm_tb_tp_ssm_res_05.R, hm_tb_tp_ssm_res_05.F, hm_tb_tp_ssm_res_3.P, hm_tb_tp_ssm_res_3.R, hm_tb_tp_ssm_res_3.F, gt_hm_tb_tp_ssm_res_05.P, gt_hm_tb_tp_ssm_res_05.R, gt_hm_tb_tp_ssm_res_05.F, \ mi@0: # gt_hm_tb_tp_ssm_res_3.P, gt_hm_tb_tp_ssm_res_3.R, gt_hm_tb_tp_ssm_res_3.F]) mi@0: mi@0: mi@0: def main(): mi@0: segmenter = SSMseg() mi@0: segmenter.process() mi@0: mi@0: mi@0: if __name__ == '__main__': mi@0: main() mi@0: