1
+ import matplotlib .pyplot as plt
2
+ import seaborn as sns
3
+ import scipy .io as sio
4
+ import numpy as np
5
+ import librosa
6
+ import mir_eval
7
+ import jams
8
+ import glob
9
+ import os
10
+ from multiprocessing import Pool as PPool
11
+
12
+ """
13
+ SALAMI NOTES
14
+ *1359 tracks total, 884 have two distinct annotators
15
+ """
16
+
17
+ #https://jams.readthedocs.io/en/stable/jams_structure.html
18
+ #https://craffel.github.io/mir_eval/#mir_eval.hierarchy.lmeasure
19
+
20
+ JAMS_DIR = 'salami-data-public-jams-multi'
21
+ AUDIO_DIR = 'salami-data-public-audio'
22
+ #mir_eval.hierarchy.lmeasure
23
+
24
+ def jam_annos_to_lists (coarse , fine ):
25
+ """
26
+ Given a list of annotations from a jam file, convert it into
27
+ a format to pass to mir_eval
28
+ Parameters
29
+ ----------
30
+ coarse: Annotation object
31
+ An annotation object at the coarse level
32
+ fine: Annotation object
33
+ An annotation object at the fine level
34
+ Returns
35
+ -------
36
+ intervals_hier: 2-element list of ndarray (N, 2)
37
+ List of intervals (in seconds) of annotations
38
+ labels_hier: 2-element list of N-length lists of strings
39
+ Corresponding segment labels for annotations
40
+ """
41
+ intervals_hier = [[], []]
42
+ labels_hier = [[], []]
43
+ for i , anno in enumerate ([coarse , fine ]):
44
+ for val in anno .data :
45
+ intervals_hier [i ].append (np .array ([val .time , val .time + val .duration ]))
46
+ labels_hier [i ].append (val .value )
47
+ intervals_hier [i ] = np .array (intervals_hier [i ])
48
+ return intervals_hier , labels_hier
49
+
50
+ def get_inter_anno_agreement_par (filename ):
51
+ print (filename )
52
+ jam = jams .load (filename )
53
+ if len (jam .annotations ) < 8 :
54
+ return np .array ([- 1 , - 1 , - 1 ])
55
+ intervals_hier1 , labels_hier1 = jam_annos_to_lists (jam .annotations [1 ], jam .annotations [2 ])
56
+ intervals_hier2 , labels_hier2 = jam_annos_to_lists (jam .annotations [4 ], jam .annotations [5 ])
57
+ l_precision , l_recall , l_measure = mir_eval .hierarchy .lmeasure (intervals_hier1 , labels_hier1 , intervals_hier2 , labels_hier2 )
58
+ return np .array ([l_precision , l_recall , l_measure ])
59
+
60
+
61
+ def get_inter_anno_agreement (NThreads = 12 ):
62
+ """
63
+ Trying to replicate figure 11 in the Frontiers paper
64
+ """
65
+ if not os .path .exists ("interanno.mat" ):
66
+ parpool = PPool (NThreads )
67
+ filenames = glob .glob ("%s/*.jams" % JAMS_DIR )
68
+ res = parpool .map (get_inter_anno_agreement_par , (filenames ))
69
+ sio .savemat ("interanno.mat" , {"res" :res })
70
+ res = sio .loadmat ("interanno.mat" )["res" ]
71
+ res = res [res [:, 0 ] > - 1 , :]
72
+ sns .kdeplot (res [:, - 1 ], shade = True )
73
+ plt .xlim ([0 , 1 ])
74
+ plt .title ("L-Measure Inter-Annotator Agreement" )
75
+ plt .xlabel ("L-Measure" )
76
+ plt .ylabel ("Probability Density" )
77
+ plt .show ()
78
+
79
+ if __name__ == '__main__' :
80
+ get_inter_anno_agreement ()
0 commit comments