-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ3.py
66 lines (52 loc) · 1.85 KB
/
Q3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
# -*- coding:utf-8 -*-
from glob import glob
import madmom
import utils
# Compute local onset autocorrelation
DB = 'Ballroom'
GENRE = [g.split('/')[2] for g in glob(DB + '/wav/*')]
# %% Q3
genres_p, genres_ALOTC = list(), list()
for g in GENRE:
print('GENRE:', g)
FILES = glob(DB + '/wav/' + g + '/*.wav')
label, pred_t1, pred_t2, p_score, ALOTC_score = list(), list(), list(), list(), list()
for f in FILES:
f = f.replace('\\', '/')
print('FILE:', f)
# Read the labeled tempo
bpm = float(utils.read_tempofile(DB, f))
print('ground-truth tempo: ', bpm)
label.append(bpm)
# madmom estimate tempo
proc = madmom.features.tempo.TempoEstimationProcessor(fps=100)
act = madmom.features.beats.RNNBeatProcessor()(f)
tempo1 = (proc(act)).astype(float)[0][0].item()
tempo2 = (proc(act)).astype(float)[1][0].item()
print(tempo1, tempo2)
# p score
s1 = tempo1 / (tempo1 + tempo2)
s2 = 1.0 - s1
print(s1, s2)
p = s1 * utils.P_score(tempo1, bpm) + s2 * utils.P_score(tempo2, bpm)
p_score.append(p)
# ALOTC score
ALOTC = utils.ALOTC(tempo1, tempo2, bpm)
ALOTC_score.append(ALOTC)
print(p, ALOTC)
p_avg = sum(p_score) / len(p_score)
ALOTC_avg = sum(ALOTC_score) / len(ALOTC_score)
genres_p.append(p_avg)
genres_ALOTC.append(ALOTC_avg)
print('----------')
print(genres_p)
print(genres_ALOTC)
print()
print("***** Q3 *****")
print("Genre \tP-score \tALOTC score")
for g in range(len(GENRE)):
print("{:13s}\t{:8.2f}\t{:8.2f}".format(GENRE[g], genres_p[g], genres_ALOTC[g]))
print('----------')
print("Overall P-score:\t{:.2f}".format(sum(genres_p) / len(genres_p)))
print("Overall ALOTC score:\t{:.2f}".format(sum(genres_ALOTC) / len(genres_ALOTC)))