<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 &larr; Back to Index
Evaluation Example
Step1:  Detect Beats
Estimate the beats using beat_track
Step2:  Load a fictional reference annotation.
Step3:  Plot the estimated and reference beats together.
Step4:  Evaluate
Evaluate using mir_eval.beat.evaluate
Step5:  Example
Step6:  Hidden benefits
Input validation! Many errors can be traced back to ill-formatted data.
Standardized behavior, full test coverage.
More than metrics
mir_eval has tools for display and sonification.
Step7:  Common plots
Step8:  Example
<ASSISTANT_TASK:>
Python Code:
y, sr = librosa.load('audio/prelude_cmaj.wav')
ipd.Audio(y, rate=sr)
Explanation: &larr; Back to Index
Evaluation Example: Beat Tracking
Documentation: mir_eval.beat
Evaluation method: compute the error between the estimated beat times and some reference list of beat locations. Many metrics additionally compare the beat sequences at different metric levels in order to deal with the ambiguity of tempo.
Let's evaluate a beat detector on the following audio:
End of explanation
est_tempo, est_beats = librosa.beat.beat_track(y=y, sr=sr, bpm=120)
est_beats = librosa.frames_to_time(est_beats, sr=sr)
est_beats
Explanation: Detect Beats
Estimate the beats using beat_track:
End of explanation
ref_beats = numpy.array([0, 0.50, 1.02, 1.53, 1.99, 2.48, 2.97,
       3.43, 3.90, 4.41, 4.89, 5.38,
       5.85, 6.33, 6.82, 7.29, 7.70])
Explanation: Load a fictional reference annotation.
End of explanation
D = librosa.stft(y)
S = abs(D)
S_db = librosa.amplitude_to_db(S)
librosa.display.specshow(S_db, sr=sr, x_axis='time', y_axis='log')
plt.ylim(0, 8192)
plt.vlines(est_beats, 0, 8192, color='#00ff00')
plt.scatter(ref_beats, 5000*numpy.ones_like(ref_beats), color='k', s=100)
Explanation: Plot the estimated and reference beats together.
End of explanation
mir_eval.beat.evaluate(ref_beats, est_beats)
Explanation: Evaluate
Evaluate using mir_eval.beat.evaluate:
End of explanation
mir_eval.chord.evaluate()
Explanation: Example: Chord Estimation
End of explanation
import librosa.display
import mir_eval.display
Explanation: Hidden benefits
Input validation! Many errors can be traced back to ill-formatted data.
Standardized behavior, full test coverage.
More than metrics
mir_eval has tools for display and sonification.
End of explanation
librosa.display.specshow(S, x_axis='time', y_axis='mel')
mir_eval.display.events(ref_beats, color='w', alpha=0.8, linewidth=3)
mir_eval.display.events(est_beats, color='c', alpha=0.8, linewidth=3, linestyle='--')
Explanation: Common plots: events, labeled_intervals
pitch, multipitch, piano_roll
segments, hierarchy,
separation
Example: Events
End of explanation
y_harm, y_perc = librosa.effects.hpss(y, margin=8)
plt.figure(figsize=(12, 4))
mir_eval.display.separation([y_perc, y_harm], sr, labels=['percussive', 'harmonic'])
plt.legend()
Audio(data=numpy.vstack([
mir_eval.sonify.chords()
Explanation: Example: Labeled Intervals
Example: Source Separation
End of explanation
<END_TASK>