-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdataset-eval.py
86 lines (72 loc) · 3.73 KB
/
dataset-eval.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import mir_eval
from pathlib import Path
import pretty_midi as pm
import numpy as np
import pandas as pd
def evaluate(midi_path='*.crepe_notes.mid',
midi_replace_str='.crepe_notes.mid',
midi_replace_with='.mid',
output_label='crepe_notes'):
results = []
merge_tracks = True
paths = sorted(Path('./').rglob(midi_path))
for path in paths:
print(f"{output_label}: {path}")
est_path = str(path)
ref_path = str(path).replace(midi_replace_str, midi_replace_with)
ref = pm.PrettyMIDI(ref_path)
est = pm.PrettyMIDI(est_path)
ref_times = np.array([[n.start, n.end]
for n in ref.instruments[0].notes])
ref_pitches = np.array(
[pm.note_number_to_hz(n.pitch) for n in ref.instruments[0].notes])
if merge_tracks:
est_times = np.array(
[[n.start, n.end]
for inst_notes in map(lambda i: i.notes, est.instruments)
for n in inst_notes])
est_pitches = np.array([
pm.note_number_to_hz(n.pitch)
for inst_notes in map(lambda i: i.notes, est.instruments)
for n in inst_notes
])
else:
est_times = np.array([[n.start, n.end]
for n in est.instruments[0].notes])
est_pitches = np.array([
pm.note_number_to_hz(n.pitch) for n in est.instruments[0].notes
])
first_ref_note = np.min(ref_times)
last_ref_note = np.max(ref_times)
est_times_valid_idxs = np.unique(
np.where((est_times > first_ref_note)
& (est_times < last_ref_note))[0])
est_times = est_times[est_times_valid_idxs]
est_pitches = est_pitches[est_times_valid_idxs]
eval_result = mir_eval.transcription.evaluate(ref_times, ref_pitches,
est_times, est_pitches,
onset_tolerance=0.05)
eval_result['file'] = str(path)
results.append(eval_result)
df = pd.DataFrame(results)
df.to_pickle(f'{output_label}_eval.pkl')
pd.set_option('display.max_colwidth', None)
print(df.describe()[['Precision_no_offset', 'Recall_no_offset', 'F-measure_no_offset', 'Average_Overlap_Ratio_no_offset']])
# evaluate('Sax.mt3.mid', '.mt3.mid', 'mt3')
# evaluate('Sax.crepe_notes_amp_trimming.mid', '.crepe_notes_amp_trimming.mid', 'crepe_notes_amp_trimming')
# evaluate('Sax_vamp_pyin_pyin_notes.mid', '_vamp_pyin_pyin_notes.mid', 'pyin_notes')
# evaluate('Sax.crepe_notes_with_onsets.mid', '.crepe_notes_with_onsets.mid', 'crepe_notes_with_onsets')
# evaluate('*_basic_pitch.mid', '_basic_pitch.mid', 'basic_pitch')
# evaluate('*.mt3.mid', '.mt3.mid', 'mt3')
# evaluate('*.cn_25ms_min.mid', '.cn_25ms_min.mid', 'crepe_notes-min-dur-25ms')
# evaluate('*.crepe_notes-min-dur-11ms.mid', '.crepe_notes-min-dur-11ms.mid', 'crepe_notes-min-dur-11ms')
# evaluate('*.crepe_notes-min-dur-11ms-no-tuning.mid',
# evaluate('*.crepe_notes-min-dur-25ms-no-tuning.mid',
# '.crepe_notes-min-dur-25ms-no-tuning.mid',
# 'crepe_notes-min-dur-25ms-no-tuning')
# evaluate('*_vamp_pyin_pyin_notes.mid', '_vamp_pyin_pyin_notes.mid', 'pyin_notes')
# evaluate('*.cn_transition_a.mid', '.cn_transition_a.mid', 'crepe_notes-transitions-a')
# evaluate('bass.transcription.mid', '.transcription.mid', '-fine-aligned.mid', 'filobass_cn_sens_2_min_50ms')
evaluate('md-bass.mid', 'md-bass.mid', 'bass-fine-aligned.mid', 'melodyne_melodic')
# evaluate('bass_basic_pitch.mid', '_basic_pitch.mid', '-fine-aligned.mid', 'filobass_bp')
# evaluate('bass_basic_pitch.mid', '_basic_pitch.mid', 'filobass_cn')