-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
27 lines (22 loc) · 699 Bytes
/
Copy pathutils.py
File metadata and controls
27 lines (22 loc) · 699 Bytes
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
import numpy as np
from scipy.io import loadmat
def read_bach10_F0s(F0):
f = np.round(loadmat(F0)['GTF0s'] - 21).astype(int)
index = np.where(f >= 0)
pianoroll = np.zeros((88, f.shape[1]))
for i, frame in zip(index[0], index[1]):
pianoroll[f[i, frame], frame] = 1
return pianoroll
def multipitch_evaluation(estimation, truth, raw_value=False):
TP = np.count_nonzero(truth)
diff = truth - estimation
FN = np.where(diff == 1)[0].shape[0]
FP = np.where(diff < 0)[0].shape[0]
TP -= FN
if raw_value:
return TP, FP, FN
else:
p = TP / (TP + FP)
r = TP / (TP + FN)
f1 = 2 * p * r / (p + r)
return p, r, f1