mir_eval: Music Information Retrieval Evaluation
mir_eval is a Python library providing a transparent, standardized, and straightforward way to evaluate Music Information Retrieval (MIR) systems. It includes common metrics for tasks such as beat detection, chord estimation, melody extraction, and onset detection. The library is actively maintained, with the current version being 0.8.2, and sees regular updates to ensure compatibility and introduce minor enhancements.
Warnings
- breaking Older versions of `mir_eval` (pre-0.8.0) used deprecated NumPy type aliases like `np.int` and `np.float`. These aliases were deprecated in NumPy 1.20 and removed entirely in NumPy 1.24+ and NumPy 2.0+.
- gotcha NumPy 2.0 introduced significant changes to its numeric promotion rules, which can affect the precision of results when combining scalars of different types (e.g., `float32` with Python `float`). This could lead to unexpected lower precision or integer overflows in some edge cases.
- gotcha The `mir_eval.display` submodule, used for plotting, has had compatibility updates (e.g., in version 0.5, it updated to use Matplotlib 2). Using older `mir_eval` versions with newer Matplotlib or vice versa might lead to plotting errors or unexpected visual outputs.
Install
-
pip install mir-eval
Imports
- mir_eval
import mir_eval
- mir_eval.beat
import mir_eval.beat
- mir_eval.onset.evaluate
from mir_eval import onset scores = onset.evaluate(reference_onsets, estimated_onsets)
Quickstart
import numpy as np
import mir_eval.beat
# Reference beat times (ground truth)
reference_beats = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.0])
# Estimated beat times from an algorithm
estimated_beats = np.array([0.51, 1.02, 1.48, 2.03, 2.55, 3.01])
# Calculate F-measure for beat tracking
f_measure = mir_eval.beat.f_measure(reference_beats, estimated_beats)
# Calculate other beat metrics
alternate_accuracy = mir_eval.beat.alternate_period_accuracy(reference_beats, estimated_beats)
cml_t = mir_eval.beat.cemgil_metric(reference_beats, estimated_beats)
print(f"Beat F-measure: {f_measure:.4f}")
print(f"Alternate Period Accuracy: {alternate_accuracy:.4f}")
print(f"Cemgil Metric (T): {cml_t:.4f}")