source: python/aubiocompare-onset @ 2afdb0f

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 2afdb0f was 220dcfc, checked in by Paul Brossier <piem@altern.org>, 19 years ago

more berbosity

  • Property mode set to 100755
File size: 3.5 KB
RevLine 
[96fb8ad]1#! /usr/bin/python
2
3"""Copyright (C) 2004 Paul Brossier <piem@altern.org>
4
5print aubio.__LICENSE__ for the terms of use
6
[296c33a]7or see LICENSE.txt in the aubio installation directory.
[96fb8ad]8"""
9__LICENSE__ = """\
10         Copyright (C) 2004 Paul Brossier <piem@altern.org>
11
12         This program is free software; you can redistribute it and/or modify
13         it under the terms of the GNU General Public License as published by
14         the Free Software Foundation; either version 2 of the License, or
15         (at your option) any later version.
16
17         This program is distributed in the hope that it will be useful,
18         but WITHOUT ANY WARRANTY; without even the implied warranty of
19         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20         GNU General Public License for more details.
21
22         You should have received a copy of the GNU General Public License
23         along with this program; if not, write to the Free Software
24         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25"""           
26
27
28__HELP__ = """\
29# required arguments
30 -c targetfilename
31 -o detectfilename
32(both must be text files with 1 time a line expressed in seconds)
33
34# optional arguments
35 -D <delay>     delay in seconds
36 -v             verbose mode
37 -d             debug mode
38
39# output
40results:number of correct detections
41        number of incorrect detections
42        number of doubled detections
43        number of total detections
44        number of total targets
45
46# example:
47$ aubioonset-comp -c checked-onsets.txt -o handlab-onsets.txt -v
48( gd fp dd ) tot / real
49( 5 4 0 ) 9 / 9
5055.5555555556 %GD       44.4444444444 %FP       0.0 %OD
51
52# bugs
53does not scale to very long lists
54"""
55
56import sys
[a9d9c5c]57from aubio.onsetcompare import onset_roc, onset_diffs
[96fb8ad]58from aubio.txtfile import read_datafile
59
60# default values
61fileo=None;filec=None;vmode=None;dmode=None;delay=0.
62# default tolerance is 50 ms
[7445aea]63#tol = 0.050
64tol = 0.048
[a9d9c5c]65# default mode is onset
66mode = 'onset'
[96fb8ad]67
68while len(sys.argv) >=2:
69    option = sys.argv[1]; del sys.argv[1]
70    if option == '-h': print __HELP__; sys.exit()
71    if option == '-o': fileo = sys.argv[1]; del sys.argv[1]
72    if option == '-c': filec = sys.argv[1]; del sys.argv[1]
73    if option == '-v': vmode = 'verbose'
74    if option == '-d': dmode = 'debug'
75    if option == '-D': delay = float(sys.argv[1]); del sys.argv[1]
[7445aea]76    if option == '-tol': tol = float(sys.argv[1]); del sys.argv[1]
[a9d9c5c]77    if option == '-l': mode = 'localisation'
[96fb8ad]78
79# arguments required
80if (not fileo) or (not filec):
81    print 'wrong set of arguments. use \'-h\' for help'
82    sys.exit('error: needs at least \'-c targets.txt -o detected.txt\'')
83
84# load files
85ltru, lres = read_datafile(fileo,depth=0),read_datafile(filec,depth=0)
86
87# delay onsets as required with -D
[7445aea]88if delay:
89    for i in range(len(lres)):
90        lres[i] = lres[i] + delay
[96fb8ad]91# compute errors types
[a9d9c5c]92if mode == 'localisation':
93        l = onset_diffs(ltru,lres,tol)
[b16c017]94        for i in l: print "%.3f" % i
[96fb8ad]95else:
[a9d9c5c]96        orig, missed, merged, expc, bad, doubled = onset_roc(ltru,lres,tol)
97       
98        # print results
99        #print "orig, missed, merged, expc, bad, doubled:"
100        if vmode=='verbose':
[220dcfc]101            print "orig", orig
102            print "expc", expc
103            print "missed",missed
104            print "merged", merged
105            print "bad", bad
106            print "doubled", doubled
107            print "correct", orig-missed-merged
[a9d9c5c]108            print "GD %2.8f\t"        % (100*float(orig-missed-merged)/(orig)),
109            print "FP %2.8f\t"        % (100*float(bad+doubled)/(orig))       ,
110            print "GD-merged %2.8f\t" % (100*float(orig-missed)/(orig))       ,
111            print "FP-pruned %2.8f\t" % (100*float(bad)/(orig))               
112        else:
113            print  orig, missed, merged, expc, bad, doubled
Note: See TracBrowser for help on using the repository browser.