Exemple #1
0
    def eval(self, inputdata, ftru, mode="roc", vmode=""):
        from aubio.txtfile import read_datafile
        from aubio.onsetcompare import onset_roc, onset_diffs, onset_rocloc

        ltru = read_datafile(ftru, depth=0)
        lres = []
        for i in range(len(inputdata)):
            lres.append(inputdata[i][0] * self.params.step)
        if vmode == "verbose":
            print "Running with mode %s" % self.params.onsetmode,
            print " and threshold %f" % self.params.threshold,
            print " on file", self.input
            # print ltru; print lres
        if mode == "local":
            l = onset_diffs(ltru, lres, self.params.tol)
            mean = 0
            for i in l:
                mean += i
            if len(l):
                mean = "%.3f" % (mean / len(l))
            else:
                mean = "?0"
            return l, mean
        elif mode == "roc":
            self.orig, self.missed, self.merged, self.expc, self.bad, self.doubled = onset_roc(
                ltru, lres, self.params.tol
            )
        elif mode == "rocloc":
            self.v = {}
            self.v["orig"], self.v["missed"], self.v["Tm"], self.v["expc"], self.v["bad"], self.v["Td"], self.v[
                "l"
            ], self.v["labs"] = onset_rocloc(ltru, lres, self.params.tol)
Exemple #2
0
	def eval(self,inputdata,ftru,mode='roc',vmode=''):
		from aubio.txtfile import read_datafile 
		from aubio.onsetcompare import onset_roc, onset_diffs, onset_rocloc
		ltru = read_datafile(ftru,depth=0)
		lres = []
		for i in range(len(inputdata)): lres.append(inputdata[i][0]*self.params.step)
		if vmode=='verbose':
			print "Running with mode %s" % self.params.onsetmode, 
			print " and threshold %f" % self.params.threshold, 
			print " on file", self.input
		#print ltru; print lres
		if mode == 'local':
			l = onset_diffs(ltru,lres,self.params.tol)
			mean = 0
			for i in l: mean += i
			if len(l): mean = "%.3f" % (mean/len(l))
			else: mean = "?0"
			return l, mean
		elif mode == 'roc':
			self.orig, self.missed, self.merged, \
				self.expc, self.bad, self.doubled = \
				onset_roc(ltru,lres,self.params.tol)
		elif mode == 'rocloc':
			self.v = {}
			self.v['orig'], self.v['missed'], self.v['Tm'], \
				self.v['expc'], self.v['bad'], self.v['Td'], \
				self.v['l'], self.v['labs'] = \
				onset_rocloc(ltru,lres,self.params.tol)
Exemple #3
0
    def plot(self, onsets, ofunc, wplot, oplots, nplot=False):
        import Gnuplot, Gnuplot.funcutils
        import aubio.txtfile
        import os.path
        from numpy import arange, array, ones
        from aubio.onsetcompare import onset_roc

        x1, y1, y1p = [], [], []
        oplot = []
        if self.params.onsetmode in ('mkl', 'kl'): ofunc[0:10] = [0] * 10

        self.lenofunc = len(ofunc)
        self.maxofunc = max(ofunc)
        # onset detection function
        downtime = arange(len(ofunc)) * self.params.step
        oplot.append(
            Gnuplot.Data(downtime,
                         ofunc,
                         with_='lines',
                         title=self.params.onsetmode))

        # detected onsets
        if not nplot:
            for i in onsets:
                x1.append(i[0] * self.params.step)
                y1.append(self.maxofunc)
                y1p.append(-self.maxofunc)
            #x1 = array(onsets)*self.params.step
            #y1 = self.maxofunc*ones(len(onsets))
            if x1:
                oplot.append(Gnuplot.Data(x1, y1, with_='impulses'))
                wplot.append(Gnuplot.Data(x1, y1p, with_='impulses'))

        oplots.append((oplot, self.params.onsetmode, self.maxofunc))

        # check if ground truth datafile exists
        datafile = self.input.replace('.wav', '.txt')
        if datafile == self.input: datafile = ""
        if not os.path.isfile(datafile):
            self.title = ""  #"(no ground truth)"
        else:
            t_onsets = aubio.txtfile.read_datafile(datafile)
            x2 = array(t_onsets).resize(len(t_onsets))
            y2 = self.maxofunc * ones(len(t_onsets))
            wplot.append(Gnuplot.Data(x2, y2, with_='impulses'))

            tol = 0.050

            orig, missed, merged, expc, bad, doubled = \
             onset_roc(x2,x1,tol)
            self.title = "GD %2.3f%% FP %2.3f%%" % \
             ((100*float(orig-missed-merged)/(orig)),
              (100*float(bad+doubled)/(orig)))
Exemple #4
0
    def plot(self, onsets, ofunc, wplot, oplots, nplot=False):
        import Gnuplot, Gnuplot.funcutils
        import aubio.txtfile
        import os.path
        from numpy import arange, array, ones
        from aubio.onsetcompare import onset_roc

        x1, y1, y1p = [], [], []
        oplot = []
        if self.params.onsetmode in ("mkl", "kl"):
            ofunc[0:10] = [0] * 10

        self.lenofunc = len(ofunc)
        self.maxofunc = max(ofunc)
        # onset detection function
        downtime = arange(len(ofunc)) * self.params.step
        oplot.append(Gnuplot.Data(downtime, ofunc, with_="lines", title=self.params.onsetmode))

        # detected onsets
        if not nplot:
            for i in onsets:
                x1.append(i[0] * self.params.step)
                y1.append(self.maxofunc)
                y1p.append(-self.maxofunc)
                # x1 = array(onsets)*self.params.step
                # y1 = self.maxofunc*ones(len(onsets))
            if x1:
                oplot.append(Gnuplot.Data(x1, y1, with_="impulses"))
                wplot.append(Gnuplot.Data(x1, y1p, with_="impulses"))

        oplots.append((oplot, self.params.onsetmode, self.maxofunc))

        # check if ground truth datafile exists
        datafile = self.input.replace(".wav", ".txt")
        if datafile == self.input:
            datafile = ""
        if not os.path.isfile(datafile):
            self.title = ""  # "(no ground truth)"
        else:
            t_onsets = aubio.txtfile.read_datafile(datafile)
            x2 = array(t_onsets).resize(len(t_onsets))
            y2 = self.maxofunc * ones(len(t_onsets))
            wplot.append(Gnuplot.Data(x2, y2, with_="impulses"))

            tol = 0.050

            orig, missed, merged, expc, bad, doubled = onset_roc(x2, x1, tol)
            self.title = "GD %2.3f%% FP %2.3f%%" % (
                (100 * float(orig - missed - merged) / (orig)),
                (100 * float(bad + doubled) / (orig)),
            )
Exemple #5
0
		# check if ground truth datafile exists
		datafile = self.input.replace('.wav','.txt')
		if datafile == self.input: datafile = ""
		if not os.path.isfile(datafile):
			self.title = "" #"(no ground truth)"
		else:
			t_onsets = aubio.txtfile.read_datafile(datafile)
			x2 = numarray.array(t_onsets).resize(len(t_onsets))
			y2 = self.maxofunc*numarray.ones(len(t_onsets))
			wplot.append(Gnuplot.Data(x2,y2,with='impulses'))
			
			tol = 0.050 

			orig, missed, merged, expc, bad, doubled = \
				onset_roc(x2,x1,tol)
			self.title = "GD %2.3f%% FP %2.3f%%" % \
				((100*float(orig-missed-merged)/(orig)),
				 (100*float(bad+doubled)/(orig)))


	def plotplot(self,wplot,oplots,outplot=None,extension=None,xsize=1.,ysize=1.,spectro=False):
		from aubio.gnuplot import gnuplot_create, audio_to_array, make_audio_plot, audio_to_spec
		import re
		# prepare the plot
		g = gnuplot_create(outplot=outplot, extension=extension)
		g('set title \'%s\'' % (re.sub('.*/','',self.input)))
		if spectro:
			g('set size %f,%f' % (xsize,1.3*ysize) )
		else:
			g('set size %f,%f' % (xsize,ysize) )