Download scripts/r5_loopguard/lg_basechk.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_loopguard/lg_basechk.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/r5_loopguard/lg_basechk.py
-
curl -L -o lg_basechk.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_loopguard/lg_basechk.py
1.88 kB
| """LOOPGUARD-1 check: the om_baseline.py copy (pipeline reader) run on CPU on a few VALIDATION pages equals the stored | |
| ONEMODEL CPU baseline rows (outputs/r6_onemodel/baseline/cpu/<set>_c*.jsonl, same reader path, same stored det_eval boxes). | |
| Compares boxes and readings per page; prints counts only. | |
| usage: lg_basechk.py --mine gen_val=JSONL,school_val=JSONL --out JSON | |
| """ | |
| import argparse | |
| import glob | |
| import json | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--mine", required=True) | |
| ap.add_argument("--out", required=True) | |
| a = ap.parse_args() | |
| D = "/path/to/TURKIC_OCR_DATA" | |
| def read(paths): | |
| out = {} | |
| for p in paths: | |
| with open(p, encoding="utf-8") as f: | |
| for line in f: | |
| try: | |
| r = json.loads(line) | |
| except ValueError: | |
| continue | |
| out[r["id"]] = r | |
| return out | |
| rep, ok = {"sets": {}}, True | |
| for kv in a.mine.split(","): | |
| s, p = kv.split("=", 1) | |
| M = read([p]) | |
| S = read(sorted(glob.glob(D + "/outputs/r6_onemodel/baseline/cpu/%s_c*.jsonl" % s))) | |
| pages = [] | |
| for i, r in M.items(): | |
| t = S.get(i) | |
| if t is None: | |
| pages.append({"id": i, "stored": False}) | |
| ok = False | |
| continue | |
| same_boxes = r["boxes"] == t["boxes"] | |
| diff = sum(1 for x, y in zip(r["readings"], t["readings"]) if x != y) | |
| pages.append({"id": i, "boxes_equal": same_boxes, "n_boxes": r["n_boxes"], "n_read": r["n_read"], | |
| "readings_differing": diff + abs(len(r["readings"]) - len(t["readings"]))}) | |
| ok &= same_boxes and r["n_read"] == t["n_read"] | |
| rep["sets"][s] = pages | |
| rep["runs_and_boxes_equal"] = bool(ok) | |
| rep["readings_differing_total"] = sum(p.get("readings_differing", 0) for v in rep["sets"].values() for p in v) | |
| json.dump(rep, open(a.out, "w"), indent=1) | |
| print(json.dumps(rep)) | |