"""Test pass 2 scoring driver: the R5 scorer (CODE/scripts/r5eval/score.py, unchanged) once per prediction root DATA/outputs/r5/testpass2/preds/, output DATA/outputs/r5/testpass2/scores/, with --test-pass and the test pass 2 gate file; page predictions are not read by score.py (--page-preds points to an empty folder). Then the page scorer for the TurkishOCR-Bench pages and the results table. usage: tp2_score_all.py --root DATA/outputs/r5/testpass2 --gate GATE [--parallel 2] """ import argparse import concurrent.futures import glob import os import subprocess import sys CODE = "/path/to/TURKIC_OCR_CODE" PY = CODE + "/.venv_kraken/bin/python" HERE = os.path.dirname(os.path.abspath(__file__)) DATA = "/path/to/TURKIC_OCR_DATA" ap = argparse.ArgumentParser() ap.add_argument("--root", required=True) ap.add_argument("--gate", required=True) ap.add_argument("--parallel", type=int, default=2) a = ap.parse_args() if not os.path.exists(a.gate): print("REFUSED: gate file missing") sys.exit(3) empty = os.path.join(a.root, "no_page_preds") os.makedirs(empty, exist_ok=True) roots = sorted(d for d in glob.glob(os.path.join(a.root, "preds", "*")) if os.path.isdir(d)) def run(root): task = os.path.basename(root) out = os.path.join(a.root, "scores", task) cmd = [PY, "-I", CODE + "/scripts/r5eval/score.py", "--preds", root, "--registry", DATA + "/data/processed/r5/evalsets.json", "--out", out, "--workers", "2", "--test-pass", "--gate-file", a.gate, "--page-preds", empty] p = subprocess.run(cmd, capture_output=True, text=True) return task, p.returncode, (p.stdout[-1500:] + p.stderr[-1500:]) with concurrent.futures.ThreadPoolExecutor(max_workers=a.parallel) as ex: for task, rc, log in ex.map(run, roots): print("=== score", task, "exit", rc, flush=True) print(log, flush=True) P = os.path.join(a.root, "tob") S = os.path.join(a.root, "pages") os.makedirs(S, exist_ok=True) jobs = [("tob_hand", P + "/pages_hand.tsv", [S + "/read_hand.jsonl"]), ("tob_print", P + "/pages_print.tsv", sorted(glob.glob(S + "/read_print_c*.jsonl")))] for label, pages, preds in jobs: preds = [p for p in preds if os.path.exists(p)] if not preds: print("=== pages", label, "no prediction file; not scored", flush=True) continue cmd = [PY, "-I", HERE + "/tp2_page_score.py", "--pages", pages, "--label", label, "--gate-file", a.gate, "--out", os.path.join(S, "page_score_%s.json" % label)] for p in preds: cmd += ["--pred", p] p = subprocess.run(cmd, capture_output=True, text=True) print("=== pages", label, "exit", p.returncode, flush=True) print((p.stdout[-800:] + p.stderr[-1500:]), flush=True) p = subprocess.run([PY, "-I", HERE + "/tp2_results.py", "--root", a.root, "--out", os.path.join(a.root, "results_cluster.json")], capture_output=True, text=True) print("=== results exit", p.returncode, p.stdout[-500:], p.stderr[-1500:], flush=True)