File size: 4,648 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""ERRAN (R5) inventory: which prediction files exist, row counts, registry entries of the validation sets used, and the
distinct values of the generator side-file columns. Validation sets only; locked (test) entries are listed by name only and never opened."""
import collections
import json
import os
import sys

D = "/path/to/TURKIC_OCR_DATA"
PREDS = D + "/outputs/r5/preds"
REG = D + "/data/processed/r5/evalsets.json"
SETS = ["V1", "hkr_val_s2000", "chd_val_s2000", "school_val_s2000", "synth_hand_val", "synth_typed_val", "print_real_val",
        "synth_clutter_val", "curve_v1"]


def nrows(p):
    with open(p, encoding="utf-8") as f:
        return sum(1 for _ in f) - 1


def main():
    reg = json.load(open(REG, encoding="utf-8"))
    sets = reg["sets"] if isinstance(reg, dict) else reg
    print("REGISTRY entries (validation ones in full, locked ones name only):")
    for s in sets:
        locked = bool(s.get("locked")) or str(s.get("split", "")).lower() == "test"
        if locked:
            print("  LOCKED", s.get("name"))
        else:
            print("  ", json.dumps({k: s.get(k) for k in ("name", "manifest", "split", "purpose")}, ensure_ascii=False)[:400])
    print("\nPRED FILES (arm/ckpt/set rows):")
    for arm in sorted(os.listdir(PREDS)):
        for ck in sorted(os.listdir(os.path.join(PREDS, arm))):
            dd = os.path.join(PREDS, arm, ck)
            if not os.path.isdir(dd):
                continue
            row = []
            for s in SETS:
                p = os.path.join(dd, s + ".tsv")
                if os.path.exists(p):
                    row.append("%s=%d" % (s, nrows(p)))
            hdr = ""
            p = os.path.join(dd, "V1.tsv")
            if os.path.exists(p):
                hdr = open(p, encoding="utf-8").readline().strip().replace("\t", ",")
            print("  %s/%s: %s  [V1 header: %s]" % (arm, ck, " ".join(row), hdr))
    side_dir = D + "/data/processed/r5/frozen_eval_v1"
    for nm in ("synth_hand_val", "synth_typed_val", "synth_clutter_val"):
        p = os.path.join(side_dir, nm + ".meta.tsv")
        with open(p, encoding="utf-8") as f:
            hdr = f.readline().rstrip("\n").split("\t")
            cnt = {c: collections.Counter() for c in hdr}
            eff = collections.Counter()
            effa = collections.Counter()
            n = 0
            for line in f:
                parts = line.rstrip("\n").split("\t")
                if len(parts) != len(hdr):
                    continue
                n += 1
                r = dict(zip(hdr, parts))
                for c in ("lang", "script", "kind", "page_type", "strength", "geo_mode", "paper_kind", "region_class", "font_id",
                          "font_group", "heldout_font", "ink", "crop_mode", "licence_class", "font_licence_class", "mixed", "overlaps",
                          "source_doc_confidence", "unit"):
                    if c in r:
                        cnt[c][r[c]] += 1
                for t in r.get("effects", "").split("|"):
                    if t:
                        eff[t] += 1
                for t in r.get("effects_all", "").split("|"):
                    if t:
                        effa[t] += 1
                groups = cnt.setdefault("_groups", collections.Counter())
                groups[r.get("group", "")] += 1
        print("\nSIDECAR", nm, "rows", n, "distinct groups", len(cnt["_groups"]))
        for c, k in cnt.items():
            if c == "_groups" or not k:
                continue
            print("  ", c, dict(k.most_common(30)))
        print("   effects:", dict(eff.most_common(60)))
        print("   effects_all:", dict(effa.most_common(120)))
    for nm in ("kohtd_screen_v1", "hkr_val_s2000", "chd_val_s2000", "school_val_s2000", "print_real_val", "curve_v1"):
        p = D + "/data/processed/r5/manifests/" + nm + ".tsv"
        if not os.path.exists(p):
            print("missing", p)
            continue
        with open(p, encoding="utf-8") as f:
            hdr = f.readline().rstrip("\n").split("\t")
            c = collections.Counter()
            g = set()
            k = collections.Counter()
            u = collections.Counter()
            n = 0
            for line in f:
                r = dict(zip(hdr, line.rstrip("\n").split("\t")))
                n += 1
                c[r.get("lang")] += 1
                g.add(r.get("group"))
                k[r.get("kind")] += 1
                u[r.get("unit")] += 1
        print("\nMANIFEST", nm, "rows", n, "groups", len(g), "lang", dict(c), "kind", dict(k), "unit", dict(u), "cols", hdr)


if __name__ == "__main__":
    sys.exit(main())