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