fix(eval): correct UltraStar tick duration, word boundary WER, and pitch metrics
This commit is contained in:
@ -18,6 +18,37 @@ def normalize_text_for_wer(text: str) -> str:
|
|||||||
return text.strip().lower()
|
return text.strip().lower()
|
||||||
|
|
||||||
|
|
||||||
|
def extract_text_from_reference(reference: UltraStarSong) -> str:
|
||||||
|
"""Extract reconstructed text from UltraStar lines, respecting word boundaries."""
|
||||||
|
line_texts = []
|
||||||
|
for line in reference.lines:
|
||||||
|
line_str = "".join(note.text for note in line).strip()
|
||||||
|
if line_str:
|
||||||
|
line_texts.append(line_str)
|
||||||
|
return " ".join(line_texts)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_text_from_vocals(predicted: VocalsDocument) -> str:
|
||||||
|
"""Extract reconstructed text from VocalsDocument, respecting word boundaries."""
|
||||||
|
line_texts = []
|
||||||
|
for line in predicted.lines:
|
||||||
|
words = []
|
||||||
|
cur_word = ""
|
||||||
|
for syl in line.syllables:
|
||||||
|
txt = syl.text
|
||||||
|
cur_word += txt
|
||||||
|
# Word boundary is marked by word_end=True or trailing whitespace
|
||||||
|
if getattr(syl, "word_end", False) or txt.endswith(" "):
|
||||||
|
words.append(cur_word.strip())
|
||||||
|
cur_word = ""
|
||||||
|
if cur_word:
|
||||||
|
words.append(cur_word.strip())
|
||||||
|
line_str = " ".join(w for w in words if w)
|
||||||
|
if line_str:
|
||||||
|
line_texts.append(line_str)
|
||||||
|
return " ".join(line_texts)
|
||||||
|
|
||||||
|
|
||||||
def evaluate_vocals(
|
def evaluate_vocals(
|
||||||
predicted: VocalsDocument,
|
predicted: VocalsDocument,
|
||||||
reference: UltraStarSong,
|
reference: UltraStarSong,
|
||||||
@ -28,7 +59,6 @@ def evaluate_vocals(
|
|||||||
ref_notes = []
|
ref_notes = []
|
||||||
for line in reference.lines:
|
for line in reference.lines:
|
||||||
for note in line:
|
for note in line:
|
||||||
# Skip empty whitespace notes
|
|
||||||
if note.text.strip():
|
if note.text.strip():
|
||||||
ref_notes.append(note)
|
ref_notes.append(note)
|
||||||
|
|
||||||
@ -39,22 +69,37 @@ def evaluate_vocals(
|
|||||||
if syl.text.strip():
|
if syl.text.strip():
|
||||||
pred_syllables.append(syl)
|
pred_syllables.append(syl)
|
||||||
|
|
||||||
|
num_ref_lines = len([line_item for line_item in reference.lines if any(n.text.strip() for n in line_item)])
|
||||||
|
num_pred_lines = len(
|
||||||
|
[line_item for line_item in predicted.lines if any(s.text.strip() for s in line_item.syllables)]
|
||||||
|
)
|
||||||
|
|
||||||
if not ref_notes or not pred_syllables:
|
if not ref_notes or not pred_syllables:
|
||||||
return {
|
return {
|
||||||
"num_ref_syllables": len(ref_notes),
|
"num_ref_syllables": len(ref_notes),
|
||||||
"num_pred_syllables": len(pred_syllables),
|
"num_pred_syllables": len(pred_syllables),
|
||||||
|
"num_ref_lines": num_ref_lines,
|
||||||
|
"num_pred_lines": num_pred_lines,
|
||||||
"mae_timing_ms": 0.0,
|
"mae_timing_ms": 0.0,
|
||||||
"median_timing_ms": 0.0,
|
"median_timing_ms": 0.0,
|
||||||
|
"fraction_within_50ms": 0.0,
|
||||||
"fraction_within_100ms": 0.0,
|
"fraction_within_100ms": 0.0,
|
||||||
|
"fraction_within_200ms": 0.0,
|
||||||
|
"duration_mae_ms": 0.0,
|
||||||
"strict_pitch_accuracy": 0.0,
|
"strict_pitch_accuracy": 0.0,
|
||||||
|
"pitch_class_accuracy": 0.0,
|
||||||
"octave_equiv_pitch_accuracy": 0.0,
|
"octave_equiv_pitch_accuracy": 0.0,
|
||||||
|
"median_octave_offset": 0.0,
|
||||||
|
"line_start_mae_ms": 0.0,
|
||||||
|
"line_end_mae_ms": 0.0,
|
||||||
"wer": 1.0 if not pred_syllables and ref_notes else 0.0,
|
"wer": 1.0 if not pred_syllables and ref_notes else 0.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Match each reference syllable to nearest predicted syllable within max_match_distance_sec
|
# Match each reference syllable to nearest predicted syllable within max_match_distance_sec
|
||||||
timing_errors_ms = []
|
timing_errors_ms = []
|
||||||
strict_pitch_correct = []
|
strict_pitch_correct = []
|
||||||
octave_pitch_correct = []
|
pitch_class_correct = []
|
||||||
|
matched_pairs = []
|
||||||
|
|
||||||
matched_pred_indices = set()
|
matched_pred_indices = set()
|
||||||
for ref in ref_notes:
|
for ref in ref_notes:
|
||||||
@ -70,40 +115,89 @@ def evaluate_vocals(
|
|||||||
if best_idx is not None:
|
if best_idx is not None:
|
||||||
matched_pred_indices.add(best_idx)
|
matched_pred_indices.add(best_idx)
|
||||||
pred = pred_syllables[best_idx]
|
pred = pred_syllables[best_idx]
|
||||||
|
matched_pairs.append((ref, pred))
|
||||||
timing_errors_ms.append(best_diff * 1000.0)
|
timing_errors_ms.append(best_diff * 1000.0)
|
||||||
|
|
||||||
# Pitch check
|
# Pitch check (rounded to nearest halftone)
|
||||||
pitch_diff = abs(pred.midi - ref.midi)
|
ref_m = int(round(ref.midi))
|
||||||
is_strict = pitch_diff <= 0.5
|
pred_m = int(round(pred.midi)) if pred.midi is not None else -999
|
||||||
|
|
||||||
|
is_strict = pred_m == ref_m
|
||||||
strict_pitch_correct.append(1.0 if is_strict else 0.0)
|
strict_pitch_correct.append(1.0 if is_strict else 0.0)
|
||||||
|
|
||||||
# Octave equivalent pitch check (mod 12)
|
# Pitch class check (chroma equality: mod 12)
|
||||||
mod_diff = pitch_diff % 12.0
|
is_class = (pred_m % 12) == (ref_m % 12)
|
||||||
octave_diff = min(mod_diff, 12.0 - mod_diff)
|
pitch_class_correct.append(1.0 if is_class else 0.0)
|
||||||
is_octave = octave_diff <= 0.5
|
|
||||||
octave_pitch_correct.append(1.0 if is_octave else 0.0)
|
|
||||||
else:
|
else:
|
||||||
# Unmatched reference note -> penalty
|
# Unmatched reference note -> penalty
|
||||||
timing_errors_ms.append(max_match_distance_sec * 1000.0)
|
timing_errors_ms.append(max_match_distance_sec * 1000.0)
|
||||||
strict_pitch_correct.append(0.0)
|
strict_pitch_correct.append(0.0)
|
||||||
octave_pitch_correct.append(0.0)
|
pitch_class_correct.append(0.0)
|
||||||
|
|
||||||
# 1. Timing metrics
|
# 1. Timing metrics
|
||||||
mae_timing_ms = float(np.mean(timing_errors_ms)) if timing_errors_ms else 0.0
|
mae_timing_ms = float(np.mean(timing_errors_ms)) if timing_errors_ms else 0.0
|
||||||
median_timing_ms = float(np.median(timing_errors_ms)) if timing_errors_ms else 0.0
|
median_timing_ms = float(np.median(timing_errors_ms)) if timing_errors_ms else 0.0
|
||||||
|
fraction_within_50ms = (
|
||||||
|
float(np.mean([1.0 if err <= 50.0 else 0.0 for err in timing_errors_ms])) if timing_errors_ms else 0.0
|
||||||
|
)
|
||||||
fraction_within_100ms = (
|
fraction_within_100ms = (
|
||||||
float(np.mean([1.0 if err <= 100.0 else 0.0 for err in timing_errors_ms])) if timing_errors_ms else 0.0
|
float(np.mean([1.0 if err <= 100.0 else 0.0 for err in timing_errors_ms])) if timing_errors_ms else 0.0
|
||||||
)
|
)
|
||||||
|
fraction_within_200ms = (
|
||||||
|
float(np.mean([1.0 if err <= 200.0 else 0.0 for err in timing_errors_ms])) if timing_errors_ms else 0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
# Note duration MAE on matched notes
|
||||||
|
if matched_pairs:
|
||||||
|
dur_diffs = [abs((p.end - p.start) - (r.end_sec - r.start_sec)) * 1000.0 for r, p in matched_pairs]
|
||||||
|
duration_mae_ms = float(np.mean(dur_diffs))
|
||||||
|
else:
|
||||||
|
duration_mae_ms = 0.0
|
||||||
|
|
||||||
# 2. Pitch metrics
|
# 2. Pitch metrics
|
||||||
strict_pitch_acc = float(np.mean(strict_pitch_correct)) if strict_pitch_correct else 0.0
|
strict_pitch_acc = float(np.mean(strict_pitch_correct)) if strict_pitch_correct else 0.0
|
||||||
octave_pitch_acc = float(np.mean(octave_pitch_correct)) if octave_pitch_correct else 0.0
|
pitch_class_acc = float(np.mean(pitch_class_correct)) if pitch_class_correct else 0.0
|
||||||
|
|
||||||
# 3. WER metric
|
# Octave offset median
|
||||||
ref_words_raw = "".join(r.text for r in ref_notes)
|
if matched_pairs:
|
||||||
pred_words_raw = "".join(p.text for p in pred_syllables)
|
octave_offsets = [round((p.midi - r.midi) / 12.0) for r, p in matched_pairs if p.midi is not None]
|
||||||
norm_ref = normalize_text_for_wer(ref_words_raw)
|
median_octave_offset = float(np.median(octave_offsets)) if octave_offsets else 0.0
|
||||||
norm_pred = normalize_text_for_wer(pred_words_raw)
|
else:
|
||||||
|
median_octave_offset = 0.0
|
||||||
|
|
||||||
|
# 3. Line metrics
|
||||||
|
ref_lines_valid = [r_line for r_line in reference.lines if any(n.text.strip() for n in r_line)]
|
||||||
|
pred_lines_valid = [p_line for p_line in predicted.lines if any(s.text.strip() for s in p_line.syllables)]
|
||||||
|
|
||||||
|
line_start_diffs_ms = []
|
||||||
|
line_end_diffs_ms = []
|
||||||
|
for r_line in ref_lines_valid:
|
||||||
|
r_start = r_line[0].start_sec
|
||||||
|
r_end = r_line[-1].end_sec
|
||||||
|
best_diff = float("inf")
|
||||||
|
best_p_line = None
|
||||||
|
for p_line in pred_lines_valid:
|
||||||
|
p_start = p_line.syllables[0].start
|
||||||
|
diff = abs(p_start - r_start)
|
||||||
|
if diff < best_diff:
|
||||||
|
best_diff = diff
|
||||||
|
best_p_line = p_line
|
||||||
|
if best_p_line is not None and best_diff <= 2.0:
|
||||||
|
line_start_diffs_ms.append(best_diff * 1000.0)
|
||||||
|
p_end = best_p_line.syllables[-1].end
|
||||||
|
line_end_diffs_ms.append(abs(p_end - r_end) * 1000.0)
|
||||||
|
else:
|
||||||
|
line_start_diffs_ms.append(2000.0)
|
||||||
|
line_end_diffs_ms.append(2000.0)
|
||||||
|
|
||||||
|
line_start_mae_ms = float(np.mean(line_start_diffs_ms)) if line_start_diffs_ms else 0.0
|
||||||
|
line_end_mae_ms = float(np.mean(line_end_diffs_ms)) if line_end_diffs_ms else 0.0
|
||||||
|
|
||||||
|
# 4. WER metric with proper word boundaries
|
||||||
|
raw_ref = extract_text_from_reference(reference)
|
||||||
|
raw_pred = extract_text_from_vocals(predicted)
|
||||||
|
norm_ref = normalize_text_for_wer(raw_ref)
|
||||||
|
norm_pred = normalize_text_for_wer(raw_pred)
|
||||||
|
|
||||||
if norm_ref:
|
if norm_ref:
|
||||||
wer_score = float(jiwer.wer(norm_ref, norm_pred))
|
wer_score = float(jiwer.wer(norm_ref, norm_pred))
|
||||||
@ -113,10 +207,19 @@ def evaluate_vocals(
|
|||||||
return {
|
return {
|
||||||
"num_ref_syllables": len(ref_notes),
|
"num_ref_syllables": len(ref_notes),
|
||||||
"num_pred_syllables": len(pred_syllables),
|
"num_pred_syllables": len(pred_syllables),
|
||||||
|
"num_ref_lines": num_ref_lines,
|
||||||
|
"num_pred_lines": num_pred_lines,
|
||||||
"mae_timing_ms": mae_timing_ms,
|
"mae_timing_ms": mae_timing_ms,
|
||||||
"median_timing_ms": median_timing_ms,
|
"median_timing_ms": median_timing_ms,
|
||||||
|
"fraction_within_50ms": fraction_within_50ms,
|
||||||
"fraction_within_100ms": fraction_within_100ms,
|
"fraction_within_100ms": fraction_within_100ms,
|
||||||
|
"fraction_within_200ms": fraction_within_200ms,
|
||||||
|
"duration_mae_ms": duration_mae_ms,
|
||||||
"strict_pitch_accuracy": strict_pitch_acc,
|
"strict_pitch_accuracy": strict_pitch_acc,
|
||||||
"octave_equiv_pitch_accuracy": octave_pitch_acc,
|
"pitch_class_accuracy": pitch_class_acc,
|
||||||
|
"octave_equiv_pitch_accuracy": pitch_class_acc,
|
||||||
|
"median_octave_offset": median_octave_offset,
|
||||||
|
"line_start_mae_ms": line_start_mae_ms,
|
||||||
|
"line_end_mae_ms": line_end_mae_ms,
|
||||||
"wer": wer_score,
|
"wer": wer_score,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,20 +73,27 @@ def run_evaluation(testset_config: Path, output_report_dir: Path | None = None)
|
|||||||
f"Konfiguration: `{testset_config.name}`",
|
f"Konfiguration: `{testset_config.name}`",
|
||||||
f"Getestete Songs: {len(results)}",
|
f"Getestete Songs: {len(results)}",
|
||||||
"",
|
"",
|
||||||
"| Song | Status | Timing MAE (ms) | Timing <= 100ms | Noten (strikt) | Noten (+-Oktav) | WER | Laufzeit (s) |",
|
"| Song | Status | Timing MAE (ms) | <= 50ms | <= 100ms | Noten (strikt) | Tonklasse | Oktav-Median | Dauer MAE | WER | Zeilen (P/R) | Laufzeit (s) |",
|
||||||
"|---|---|---|---|---|---|---|---|",
|
"|---|---|---|---|---|---|---|---|---|---|---|---|",
|
||||||
]
|
]
|
||||||
|
|
||||||
for r in results:
|
for r in results:
|
||||||
if r.get("status") == "success":
|
if r.get("status") == "success":
|
||||||
md_lines.append(
|
md_lines.append(
|
||||||
f"| {r['name']} | OK | {r['mae_timing_ms']:.1f} | "
|
f"| {r['name']} | OK | {r['mae_timing_ms']:.1f} | "
|
||||||
f"{r['fraction_within_100ms'] * 100:.1f}% | {r['strict_pitch_accuracy'] * 100:.1f}% | "
|
f"{r.get('fraction_within_50ms', 0.0) * 100:.1f}% | "
|
||||||
f"{r['octave_equiv_pitch_accuracy'] * 100:.1f}% | {r['wer']:.2f} | {r['elapsed_sec']:.1f}s |"
|
f"{r['fraction_within_100ms'] * 100:.1f}% | "
|
||||||
|
f"{r['strict_pitch_accuracy'] * 100:.1f}% | "
|
||||||
|
f"{r.get('pitch_class_accuracy', 0.0) * 100:.1f}% | "
|
||||||
|
f"{r.get('median_octave_offset', 0.0):+.0f} | "
|
||||||
|
f"{r.get('duration_mae_ms', 0.0):.1f} ms | "
|
||||||
|
f"{r['wer']:.2f} | "
|
||||||
|
f"{r.get('num_pred_lines', 0)}/{r.get('num_ref_lines', 0)} | "
|
||||||
|
f"{r['elapsed_sec']:.1f}s |"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
md_lines.append(
|
md_lines.append(
|
||||||
f"| {r.get('name', 'Song')} | FEHLER ({r.get('error')}) | - | - | - | - | - | {r.get('elapsed_sec', 0.0):.1f}s |"
|
f"| {r.get('name', 'Song')} | FEHLER ({r.get('error')}) | - | - | - | - | - | - | - | - | - | {r.get('elapsed_sec', 0.0):.1f}s |"
|
||||||
)
|
)
|
||||||
|
|
||||||
report_md_path = report_dir / "eval_report.md"
|
report_md_path = report_dir / "eval_report.md"
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
"""Unit tests for evaluation metrics (timing, pitch, WER)."""
|
"""Unit tests for evaluation metrics (timing, pitch, pitch class, octave offset, WER)."""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from unmix.eval.metrics import evaluate_vocals, normalize_text_for_wer
|
from unmix.eval.metrics import (
|
||||||
|
evaluate_vocals,
|
||||||
|
extract_text_from_reference,
|
||||||
|
extract_text_from_vocals,
|
||||||
|
normalize_text_for_wer,
|
||||||
|
)
|
||||||
from unmix.export.ultrastar import UltraStarNote, UltraStarSong
|
from unmix.export.ultrastar import UltraStarNote, UltraStarSong
|
||||||
from unmix.schema.vocals import VocalLine, VocalsDocument, VocalSyllable
|
from unmix.schema.vocals import VocalLine, VocalsDocument, VocalSyllable
|
||||||
|
|
||||||
@ -13,13 +18,49 @@ def test_normalize_text_for_wer():
|
|||||||
assert norm == "hallo welt wie gehts"
|
assert norm == "hallo welt wie gehts"
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_words_and_wer_computation():
|
||||||
|
# UltraStar notes format: word boundaries are marked by space after word
|
||||||
|
ref_song = UltraStarSong(
|
||||||
|
headers={"BPM": "120", "GAP": "1000"},
|
||||||
|
lines=[
|
||||||
|
[
|
||||||
|
UltraStarNote(":", 0, 4, 0, "We ", start_sec=1.0, end_sec=1.5, midi=60.0),
|
||||||
|
UltraStarNote(":", 4, 4, 2, "need ", start_sec=1.5, end_sec=2.0, midi=62.0),
|
||||||
|
UltraStarNote(":", 8, 4, 4, "love", start_sec=2.0, end_sec=2.5, midi=64.0),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
pred_doc = VocalsDocument(
|
||||||
|
lines=[
|
||||||
|
VocalLine(
|
||||||
|
start=1.0,
|
||||||
|
end=2.5,
|
||||||
|
syllables=[
|
||||||
|
VocalSyllable(text="We", start=1.0, end=1.5, midi=60.0, word_end=True),
|
||||||
|
VocalSyllable(text="need", start=1.5, end=2.0, midi=62.0, word_end=True),
|
||||||
|
VocalSyllable(text="love", start=2.0, end=2.5, midi=64.0, word_end=True),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
ref_text = extract_text_from_reference(ref_song)
|
||||||
|
pred_text = extract_text_from_vocals(pred_doc)
|
||||||
|
assert ref_text == "We need love"
|
||||||
|
assert pred_text == "We need love"
|
||||||
|
|
||||||
|
metrics = evaluate_vocals(pred_doc, ref_song)
|
||||||
|
assert metrics["wer"] == 0.0
|
||||||
|
|
||||||
|
|
||||||
def test_evaluate_vocals_perfect_match():
|
def test_evaluate_vocals_perfect_match():
|
||||||
# Ground truth: 2 syllables
|
# Ground truth: 2 syllables
|
||||||
ref_song = UltraStarSong(
|
ref_song = UltraStarSong(
|
||||||
headers={"BPM": "480", "GAP": "1000"},
|
headers={"BPM": "120", "GAP": "1000"},
|
||||||
lines=[
|
lines=[
|
||||||
[
|
[
|
||||||
UltraStarNote(":", 0, 4, 0, "Hal", start_sec=1.0, end_sec=1.5, midi=60.0),
|
UltraStarNote(":", 0, 4, 0, "Hal-", start_sec=1.0, end_sec=1.5, midi=60.0),
|
||||||
UltraStarNote(":", 4, 4, 2, "lo ", start_sec=1.5, end_sec=2.0, midi=62.0),
|
UltraStarNote(":", 4, 4, 2, "lo ", start_sec=1.5, end_sec=2.0, midi=62.0),
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@ -31,8 +72,8 @@ def test_evaluate_vocals_perfect_match():
|
|||||||
start=1.0,
|
start=1.0,
|
||||||
end=2.0,
|
end=2.0,
|
||||||
syllables=[
|
syllables=[
|
||||||
VocalSyllable(text="Hal", start=1.0, end=1.5, midi=60.0),
|
VocalSyllable(text="Hal-", start=1.0, end=1.5, midi=60.0),
|
||||||
VocalSyllable(text="lo", start=1.5, end=2.0, midi=62.0),
|
VocalSyllable(text="lo ", start=1.5, end=2.0, midi=62.0, word_end=True),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@ -41,41 +82,55 @@ def test_evaluate_vocals_perfect_match():
|
|||||||
metrics = evaluate_vocals(pred_doc, ref_song)
|
metrics = evaluate_vocals(pred_doc, ref_song)
|
||||||
assert metrics["mae_timing_ms"] == pytest.approx(0.0)
|
assert metrics["mae_timing_ms"] == pytest.approx(0.0)
|
||||||
assert metrics["median_timing_ms"] == pytest.approx(0.0)
|
assert metrics["median_timing_ms"] == pytest.approx(0.0)
|
||||||
|
assert metrics["fraction_within_50ms"] == pytest.approx(1.0)
|
||||||
assert metrics["fraction_within_100ms"] == pytest.approx(1.0)
|
assert metrics["fraction_within_100ms"] == pytest.approx(1.0)
|
||||||
|
assert metrics["fraction_within_200ms"] == pytest.approx(1.0)
|
||||||
|
assert metrics["duration_mae_ms"] == pytest.approx(0.0)
|
||||||
assert metrics["strict_pitch_accuracy"] == pytest.approx(1.0)
|
assert metrics["strict_pitch_accuracy"] == pytest.approx(1.0)
|
||||||
|
assert metrics["pitch_class_accuracy"] == pytest.approx(1.0)
|
||||||
assert metrics["octave_equiv_pitch_accuracy"] == pytest.approx(1.0)
|
assert metrics["octave_equiv_pitch_accuracy"] == pytest.approx(1.0)
|
||||||
|
assert metrics["median_octave_offset"] == pytest.approx(0.0)
|
||||||
|
assert metrics["line_start_mae_ms"] == pytest.approx(0.0)
|
||||||
|
assert metrics["line_end_mae_ms"] == pytest.approx(0.0)
|
||||||
assert metrics["wer"] == pytest.approx(0.0)
|
assert metrics["wer"] == pytest.approx(0.0)
|
||||||
|
|
||||||
|
|
||||||
def test_evaluate_vocals_octave_error_and_timing_offset():
|
def test_evaluate_vocals_octave_error_and_timing_offset():
|
||||||
ref_song = UltraStarSong(
|
ref_song = UltraStarSong(
|
||||||
headers={"BPM": "480", "GAP": "1000"},
|
headers={"BPM": "120", "GAP": "1000"},
|
||||||
lines=[
|
lines=[
|
||||||
[
|
[
|
||||||
# Note at 60.0, start 1.0
|
# Note at 60.0 (C4), start 1.0, duration 0.5s
|
||||||
UltraStarNote(":", 0, 4, 0, "Test", start_sec=1.0, end_sec=1.5, midi=60.0),
|
UltraStarNote(":", 0, 4, 0, "Test", start_sec=1.0, end_sec=1.5, midi=60.0),
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Prediction is offset by 50ms and has octave error (72.0 vs 60.0)
|
# Prediction is offset by 70ms, has octave error (-1 octave: 48.2 vs 60.0), duration 0.6s
|
||||||
pred_doc = VocalsDocument(
|
pred_doc = VocalsDocument(
|
||||||
lines=[
|
lines=[
|
||||||
VocalLine(
|
VocalLine(
|
||||||
start=1.05,
|
start=1.07,
|
||||||
end=1.55,
|
end=1.67,
|
||||||
syllables=[
|
syllables=[
|
||||||
VocalSyllable(text="Test", start=1.05, end=1.55, midi=72.0),
|
VocalSyllable(text="Test", start=1.07, end=1.67, midi=48.2, word_end=True),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
metrics = evaluate_vocals(pred_doc, ref_song)
|
metrics = evaluate_vocals(pred_doc, ref_song)
|
||||||
assert metrics["mae_timing_ms"] == pytest.approx(50.0, abs=1.0)
|
assert metrics["mae_timing_ms"] == pytest.approx(70.0, abs=1.0)
|
||||||
|
assert metrics["fraction_within_50ms"] == pytest.approx(0.0)
|
||||||
assert metrics["fraction_within_100ms"] == pytest.approx(1.0)
|
assert metrics["fraction_within_100ms"] == pytest.approx(1.0)
|
||||||
# Strict pitch should fail (72 != 60)
|
assert metrics["fraction_within_200ms"] == pytest.approx(1.0)
|
||||||
|
assert metrics["duration_mae_ms"] == pytest.approx(100.0, abs=1.0)
|
||||||
|
|
||||||
|
# Strict pitch should fail (48 != 60)
|
||||||
assert metrics["strict_pitch_accuracy"] == pytest.approx(0.0)
|
assert metrics["strict_pitch_accuracy"] == pytest.approx(0.0)
|
||||||
# Octave equivalent pitch should succeed (72 % 12 == 60 % 12)
|
# Pitch class should succeed (48 % 12 == 60 % 12 == 0)
|
||||||
|
assert metrics["pitch_class_accuracy"] == pytest.approx(1.0)
|
||||||
assert metrics["octave_equiv_pitch_accuracy"] == pytest.approx(1.0)
|
assert metrics["octave_equiv_pitch_accuracy"] == pytest.approx(1.0)
|
||||||
|
# Median octave offset should be -1.0
|
||||||
|
assert metrics["median_octave_offset"] == pytest.approx(-1.0)
|
||||||
assert metrics["wer"] == pytest.approx(0.0)
|
assert metrics["wer"] == pytest.approx(0.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user