File size: 1,390 Bytes
5b65ff7 | 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 | """Compare two gigaam_bench runs (--out/--dump prefixes): transcripts and tensors."""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
import numpy as np
sys.path.insert(0, str(Path(__file__).resolve().parent))
from compare_backends import numeric_report, word_error_rate # noqa: E402
SHAPES = {"mel": 64, "encoded": 768}
def compare(reference, candidate, heads=("e2e", "raw")):
ok = True
for head in heads:
expected = Path(f"{reference}.{head}.txt").read_text()
actual = Path(f"{candidate}.{head}.txt").read_text()
wer = word_error_rate(expected, actual)
ok &= expected == actual
print(f"[{head}] WER {100 * wer:.2f}%{' identical' if expected == actual else ''}")
for name, width in SHAPES.items():
paths = [Path(f"{prefix}.{name}.f32") for prefix in (reference, candidate)]
if all(path.exists() for path in paths):
a, b = (np.fromfile(path, dtype=np.float32).reshape(-1, width) for path in paths)
print(numeric_report(name, a, b))
return ok
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("reference")
parser.add_argument("candidate")
args = parser.parse_args(argv)
raise SystemExit(0 if compare(args.reference, args.candidate) else 1)
if __name__ == "__main__":
main()
|