shithub: aubio

ref: 917d4c152a2c365b7e42d63dd04177514e5451f2
dir: /python.old/tests_demo_bench/onset/bench-onset/

View raw version
#! /usr/bin/python

from aubio.task import *

from aubio.bench.onset import mmean, stdev, benchonset

class mybenchonset(benchonset):

	def run_bench(self,modes=['dual'],thresholds=[0.5]):
		from os.path import dirname,basename
		self.thresholds = thresholds
		self.pretty_titles()
		d,e,f,g = [],[],[],[]
		for mode in modes:
			self.vlist = []
			self.params.onsetmode = mode
			#self.params.localmin = True

			for threshold in self.thresholds:
				self.params.threshold = threshold
				self.dir_eval_print()
				self.vlist.append(self.v)
			self.plotroc(d)
			self.plotfmeas(e)
			self.plotpr(f)
			#self.plothistcat(g)



		#self.plotplotroc(d)
		#self.plotplotfmeas(e)
		#self.plotplotpr(f)
		outplot = basename(self.datadir)
		for ext in ("png","svg","ps"):
			self.plotplotroc(d,outplot=outplot,extension=ext)
			self.plotplotfmeas(e,outplot=outplot,extension=ext)
			self.plotplotpr(f,outplot=outplot,extension=ext)
			#self.plotplothistcat(g,outplot=outplot,extension=ext)

if __name__ == "__main__":
	import sys
	if len(sys.argv) > 1: datapath = sys.argv[1]
	else: print "ERR: a path is required"; sys.exit(1)
	modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual']
	thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2]
	#modes = [ 'hfc' ]
	#thresholds = [0.5]

	#datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
	respath = '/var/tmp/DB-testings'

	benchonset = mybenchonset(datapath,respath,checkres=True,checkanno=True)
	benchonset.params = taskparams()
	benchonset.params.dcthreshold = -1.
	benchonset.params.silence = -100.
	benchonset.params.delay = 5. 
	benchonset.params.bufsize = 1024 
	benchonset.params.hopsize = 256 
	benchonset.params.step = float(benchonset.params.hopsize)/float(benchonset.params.samplerate)
	benchonset.params.mintol = 4.1 
	benchonset.task = taskonset
	benchonset.valuesdict = {}

	try:
		#benchonset.auto_learn2(modes=modes)
		benchonset.run_bench(modes=modes,thresholds=thresholds)
	except KeyboardInterrupt:
		sys.exit(1)