"""Where does a trained model disagree with the labels? python confusions.py [onnx file] [threshold]""" import sys, json, runpy from collections import Counter from pathlib import Path sys.argv = ["evaluate.py", "onnx:" + sys.argv[1], *(sys.argv[2:3] or ["model_qint8.onnx"])] + sys.argv[3:] threshold = float(sys.argv[3]) if len(sys.argv) > 3 else 0.4 src = Path("evaluate.py").read_text().split("spec = sys.argv[1]")[0] ns: dict = {"__file__": str(Path("evaluate.py").resolve()), "__name__": "x"} exec(src, ns) predict = ns["head_predictor"]("onnx", sys.argv[1].split(":", 1)[1]) for name in ("val", "test"): rows = ns["load"](name) preds = predict(rows) errors = Counter() by_target = Counter() for row, (move, p) in zip(rows, preds): got = move if move != "none" and p >= threshold else "none" if got not in row["ok"]: errors[(row["kind"], row["best"], got)] += 1 by_target[(row.get("target") or row.get("source") or "?")] += 1 print(f"== {name}: {sum(errors.values())} errors of {len(rows)}") print(" (kind, label, predicted):", errors.most_common(18)) print(" by request target/source:", by_target.most_common(14))