Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,12 @@ contract.
from the first annotated performance onset through the first window that
reaches the final onset. A window's statistic is the median absolute beat
error, and a piece fails when any evaluated window exceeds the modality
threshold — 1.0 beat for audio, 0.5 for MIDI.
threshold — 1.0 musical beat for audio, 0.1 for MIDI. A musical beat groups
three denominator-note units in compound meter (6/8, 9/8, 12/8, 6/4, etc.)
and one elsewhere. The reference score's time signature is looked up at
each annotated onset, including changes within a piece and a window.
- **Precision metric**: beat error (performance → score), pooled over the
pieces that method actually tracked.
pieces that method actually tracked, in denominator-note beats.
- **Secondary precision metric**: ms error (score → performance), same pooling.
- **Aggregation**: precision metrics are event-pooled across tracked pieces.
- **Ranking**: tracking rate first, then median beat error.
Expand Down
21 changes: 19 additions & 2 deletions docs/eval-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,25 @@ the threshold, and the piece counts as **lost** if any evaluated window fails.

| Input | Threshold |
| --- | --- |
| audio | 1.0 beat |
| MIDI | 0.5 beat |
| audio | 1.0 musical beat |
| MIDI | 0.1 musical beat |

A musical beat contains three denominator-note units in compound time
signatures (numerators 6, 9, 12, and larger multiples of three), and one in
other meters. Simple triple meters such as 3/4 and 3/8 are not grouped.
At every reference onset, the absolute position error is divided by the factor
for the time signature at that reference score position **before** computing
the window median. This uses the follower's actual unfolded score, so meter
changes within a performance apply, even inside a single evaluation window.
The factor follows the reference position, not a potentially incorrect estimate.

Thus the native-coordinate tolerance in a compound passage is 3.0
denominator-note beats for audio and 0.3 for MIDI. The output paths, ground
truth, MeanAE, MedAE, standard deviations, and tolerance accuracies use
denominator-note units; only TR uses musical beats. Each run saves a
`meter_<index>.json` alongside its full paths so the criterion can be reproduced.
Scores without a time signature use the parser's 4/4 default, recorded as
`assumed_time_signature` in that file.

Accuracy metrics are reported over tracked pieces only. A piece that crashes or
times out counts as lost.
Expand Down
33 changes: 19 additions & 14 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,11 @@ <h2>Tracked</h2>
<p>
The performance is walked in 30-second windows, one starting at every
annotated onset. A piece counts as tracked unless the median beat error
in any window exceeds the tolerance — 0.5 beats for MIDI, 1.0 for
audio. A follower that loses the performer produces meaningless errors,
in any window exceeds the tolerance — 0.1 musical beat for MIDI, 1.0 for
audio. In compound meter, three denominator-note units form one musical
beat. The reference meter is applied at each onset, including changes
within a piece. Position-error summaries use denominator-note units.
A follower that loses the performer produces meaningless errors,
so accuracy is only reported over the pieces it held onto.
</p>
</section>
Expand Down Expand Up @@ -869,21 +872,23 @@ <h2>Submitting</h2>
const { W, H } = plotSize(width, 6.4, 120, 190);
const PAD = { l: 52, r: 14, t: 14, b: 30 };
const xs = all.map((p) => p[0]);
const top = Math.max(0.5, ...all.map((p) => p[1]));
// tr_tolerance steps at every meter change. Details without a tracking
// criterion are drawn against a flat denominator-note threshold.
const nativeThreshold = detail.input_type === "audio" ? 1.0 : 0.5;
const tolerance = piece.tr_tolerance || (piece.tracking_criterion ? [] :
[[Math.min(...xs), nativeThreshold], [Math.max(...xs), nativeThreshold]]);
const top = Math.max(0.5, ...all.map((p) => p[1]), ...tolerance.map((p) => p[1]));
const { sx, sy, grid, labels } = svgAxes(
W, H, PAD, [Math.min(...xs), Math.max(...xs)], [0, top],
detail.axes.x, "|beat error|", (v) => v.toFixed(v < 1 ? 2 : v < 10 ? 1 : 0)
detail.axes.x, "|error| (denominator-note beats)", (v) => v.toFixed(v < 1 ? 2 : v < 10 ? 1 : 0)
);
// The tracking verdict is decided against this line: 0.5 beats for MIDI,
// 1.0 for audio, as a median over each 30-second segment.
const threshold = detail.input_type === "audio" ? 1.0 : 0.5;
const rule = threshold <= top
? `<line x1="${PAD.l}" y1="${sy(threshold).toFixed(1)}" x2="${W - PAD.r}"
y2="${sy(threshold).toFixed(1)}" stroke="var(--crit)"
stroke-width="1" stroke-dasharray="4 3" stroke-opacity=".7"/>
<text x="${W - PAD.r - 3}" y="${(sy(threshold) - 5).toFixed(1)}"
text-anchor="end" fill="var(--crit)">tracking threshold ${threshold}</text>`
: "";
const tolerancePath = tolerance.map(([t, v], i) => i
? `H${sx(t).toFixed(1)}V${sy(v).toFixed(1)}`
: `M${sx(t).toFixed(1)},${sy(v).toFixed(1)}`).join(" ");
const rule = tolerance.length ? `<path d="${tolerancePath}" fill="none"
stroke="var(--crit)" stroke-width="1" stroke-dasharray="4 3" stroke-opacity=".7"/>
<text x="${W - PAD.r - 3}" y="${PAD.t + 10}" text-anchor="end"
fill="var(--crit)">TR tolerance before window median</text>` : "";
// Without `err` the series is rebuilt from the decimated paths: close, but
// a hold followed by a jump can still show as a spike the metrics never saw.
const approximate = [piece, other].some((p) => p && !(p.err && p.err.length));
Expand Down
19 changes: 17 additions & 2 deletions matchmaker_eval/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
AudioEvalConfig,
save_debug_results,
)
from matchmaker_eval.verify_tracking import check_tracking, plot_tracking
from matchmaker_eval.verify_tracking import (
TRACKING_THRESHOLDS, check_tracking, plot_tracking, musical_beat_factors, score_meter_map,
)

# ---------------------------------------------------------------------------
# Evaluation against ground truth (post-processing of a completed Matchmaker run)
Expand Down Expand Up @@ -313,17 +315,30 @@ def run_score_following(
gt_for_check = np.column_stack(
[perf_annotations[:min_len], score_annots_for_gt[:min_len]]
)
tracking = check_tracking(wp_for_check, gt_for_check)
meter = score_meter_map(mm.score_part)
factors = musical_beat_factors(gt_for_check[:, 1], meter)
threshold = TRACKING_THRESHOLDS[mm.input_type]
tracking = check_tracking(
wp_for_check, gt_for_check, threshold=threshold, beat_factors=factors
)
results["tracked"] = tracking["tracked"]
results["max_deviation"] = tracking["max_deviation"]
results["n_failed_segments"] = tracking["n_failed"]
results["tracking_criterion"] = {
key: tracking[key] for key in ("error_unit", "threshold", "window_duration")
}
if save_dir is not None and run_name:
meter_path = Path(save_dir) / f"meter_{run_name}.json"
meter_path.write_text(json.dumps(meter, indent=2) + "\n")

if save_plots and save_dir is not None and run_name:
plot_tracking(
wp_for_check,
gt_for_check,
title=f"{config.method} #{run_name}",
save_path=Path(save_dir) / f"tracking_{run_name}.png",
threshold=threshold,
beat_factors=factors,
)
except Exception:
pass
Expand Down
15 changes: 14 additions & 1 deletion matchmaker_eval/export_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#: ``data_sha256`` names the bytes a piece was scored with (see provenance.py):
#: provenance, not a measurement. It is published beside the identity fields.
PIECE_IDENTITY = (
"tracking_criterion",
"index",
"piece_id",
"dataset",
Expand Down Expand Up @@ -182,6 +183,8 @@ def export(run_dir: Path, include_paths: bool = True) -> dict:
}
for key in ordered_metrics(piece):
row[key] = piece[key]
if "tracking_criterion" in piece:
row["tracking_criterion"] = piece["tracking_criterion"]
if piece.get("error"):
row["error"] = piece["error"]

Expand All @@ -192,6 +195,16 @@ def export(run_dir: Path, include_paths: bool = True) -> dict:
row["wp"] = decimate(wp)
row["gt"] = decimate(gt)
row["err"] = decimate_peaks(error_series(wp, gt))
meter_path = run_dir / f"meter_{index}.json"
if meter_path.exists() and len(gt) and piece.get("tracking_criterion"):
from matchmaker_eval.verify_tracking import musical_beat_factors
meter = json.loads(meter_path.read_text())
factors = musical_beat_factors(gt[:, 1], meter)
changes = np.flatnonzero(np.r_[True, factors[1:] != factors[:-1]])
keep = np.unique(np.r_[changes, len(gt) - 1])
threshold = piece["tracking_criterion"]["threshold"]
row["tr_tolerance"] = np.column_stack([gt[keep, 0], threshold * factors[keep]]).tolist()
row["meter"] = meter
detail_pieces.append(row)

return {
Expand Down Expand Up @@ -226,7 +239,7 @@ def export(run_dir: Path, include_paths: bool = True) -> dict:


#: Per-piece fields built from the run's wp_/gt_ files rather than its metrics.
PATH_FIELDS = ("wp", "gt", "err")
PATH_FIELDS = ("wp", "gt", "err", "tr_tolerance", "meter")


def has_path_files(run_dir: Path) -> bool:
Expand Down
3 changes: 3 additions & 0 deletions matchmaker_eval/merge_shards.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def merge(root: Path, output: Path) -> dict:
source = shard_dir / f"{prefix}_{index}.tsv"
if source.exists():
shutil.copy2(source, output / source.name)
meter_path = shard_dir / f"meter_{index}.json"
if meter_path.exists():
shutil.copy2(meter_path, output / meter_path.name)
failures.extend(record.get("failures", []))

pieces.sort(key=lambda p: p["index"])
Expand Down
16 changes: 13 additions & 3 deletions matchmaker_eval/run_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

from eval import run_evaluation
from utils import TOLERANCES_IN_BEATS, dataset_summaries, pooled_summaries
from verify_tracking import check_tracking, plot_tracking
from verify_tracking import (
TRACKING_THRESHOLDS, check_tracking, musical_beat_factors, plot_tracking, score_meter_map,
)

from matchmaker import Matchmaker
from matchmaker.base import OnlineAlignment
Expand Down Expand Up @@ -91,7 +93,7 @@
#: Tracking verdict thresholds, per input type. A piece counts as "tracked"
#: unless some 30-second onset-wise window's median beat error exceeds the
#: threshold. MIDI is held to a tighter bound than audio.
TRACKING_THRESHOLD = {"audio": 1.0, "midi": 0.5}
TRACKING_THRESHOLD = TRACKING_THRESHOLDS
SEGMENT_DURATION = 30.0

DEFAULT_RESULTS_DIR = REPO_ROOT / "results" / "submissions"
Expand Down Expand Up @@ -271,15 +273,22 @@ def run_piece(
# alignment_path row 0 is already absolute performance seconds.
wp_sec = np.stack([wp[0].astype(float), wp[1].astype(float)]).T
threshold = TRACKING_THRESHOLD[input_type]
meter = score_meter_map(mm.score_part)
factors = musical_beat_factors(gt[:, 1], meter)
(run_dir / f"meter_{index}.json").write_text(json.dumps(meter, indent=2) + "\n")
tracking = check_tracking(
wp_sec,
gt,
segment_duration=SEGMENT_DURATION,
threshold=threshold,
beat_factors=factors,
)
metrics["tracked"] = bool(tracking["tracked"])
metrics["max_deviation"] = float(tracking["max_deviation"])
metrics["n_failed_segments"] = int(tracking["n_failed"])
metrics["tracking_criterion"] = {
key: tracking[key] for key in ("error_unit", "threshold", "window_duration")
}

if save_plots:
plot_tracking(
Expand All @@ -289,6 +298,7 @@ def run_piece(
save_path=run_dir / f"tracking_{index}.png",
segment_duration=SEGMENT_DURATION,
threshold=threshold,
beat_factors=factors,
)

# Whether this piece actually got a measured tempo. False both when the
Expand Down Expand Up @@ -335,7 +345,7 @@ def fold_file_label(fold) -> str:
#: the rerun would otherwise be scored on the previous run's path — and the
#: progress count in run_references.py would read 146/146 from the first
#: second. metrics.json stays until the run replaces it.
PIECE_OUTPUTS = ("wp_*.tsv", "gt_*.tsv", "tracking_*.png", "[0-9]*.json")
PIECE_OUTPUTS = ("wp_*.tsv", "gt_*.tsv", "meter_*.json", "tracking_*.png", "[0-9]*.json")


def clear_piece_outputs(run_dir: Path) -> int:
Expand Down
14 changes: 12 additions & 2 deletions matchmaker_eval/test_symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
save_config,
save_results_to_csv,
)
from matchmaker_eval.verify_tracking import check_tracking, plot_tracking
from matchmaker_eval.verify_tracking import (
TRACKING_THRESHOLDS, check_tracking, plot_tracking, musical_beat_factors, score_meter_map,
)

from tabulate import tabulate
import wandb
Expand All @@ -51,7 +53,7 @@

sys.setrecursionlimit(10000)

TRACKING_THRESHOLD = 0.5 # beats
TRACKING_THRESHOLD = TRACKING_THRESHOLDS["midi"] # musical beats

WORKING_DIR = Path(__file__).parent.parent
#: Resolved through MATCHMAKER_DATA_DIR rather than a hardcoded home
Expand Down Expand Up @@ -168,11 +170,14 @@ def run_tests_and_eval_by_dataset(
gt = np.column_stack([ps, sb])

wp_T = wp.T if wp.shape[0] == 2 else wp
meter = score_meter_map(mm.score_part)
factors = musical_beat_factors(gt[:, 1], meter)
tracking = check_tracking(
wp_T,
gt,
segment_duration=30,
threshold=TRACKING_THRESHOLD,
beat_factors=factors,
)

nested = run_evaluation(
Expand All @@ -188,11 +193,15 @@ def run_tests_and_eval_by_dataset(
nested["tracked"] = tracking["tracked"]
nested["max_deviation"] = float(tracking["max_deviation"])
nested["n_failed_segments"] = int(tracking["n_failed"])
nested["tracking_criterion"] = {
key: tracking[key] for key in ("error_unit", "threshold", "window_duration")
}

piece_result = nested.copy()

# Save WP/GT — column order: perf_sec, score_beat
if run_dir is not None:
(run_dir / f"meter_{i}.json").write_text(json.dumps(meter, indent=2) + "\n")
np.savetxt(
run_dir / f"wp_{i}.tsv",
wp_T,
Expand All @@ -218,6 +227,7 @@ def run_tests_and_eval_by_dataset(
title=f"{method} #{i}",
save_path=run_dir / f"tracking_{i}.png",
threshold=TRACKING_THRESHOLD,
beat_factors=factors,
)

status = "TRACKED" if tracking["tracked"] else "FAILED"
Expand Down
Loading
Loading