File size: 1,882 Bytes
24aaa76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
"""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))