Image Classification
ONNX
onnxruntime
document-orientation
deskew
ocr
image-preprocessing
cpu
File size: 2,350 Bytes
0b8437d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Join frozen visual judgments to both native-page methods."""
import argparse
import csv
import hashlib
import json
from collections import Counter
from pathlib import Path


def records(path):
    return [json.loads(line) for line in path.read_text().splitlines()]


def by_page(rows):
    result = {(r["identifier"], r["page"]): r for r in rows}
    assert len(result) == len(rows)
    return result


def outcome(angle):
    if angle is None:
        return "inconclusive"
    return "original" if angle == 0 else "warning"


def main(root, ink, contrast):
    reviews = []
    for group in ("transfer", "catalogue"):
        labels = root / f"{group}-labels.tsv"
        digest = (root / f"{group}-labels.sha256").read_text().split()[0]
        assert hashlib.sha256(labels.read_bytes()).hexdigest() == digest
        with labels.open() as f:
            judgments = {r["blind"]: r for r in csv.DictReader(f, delimiter="\t")}
        for page in records(root / f"{group}-key.jsonl"):
            reviews.append(dict(**page, **{k:v for k,v in judgments.pop(page["blind"]).items() if k != "blind"}))
        assert not judgments
    reviews.extend(dict(**p, blind=None, placement="unavailable", evidence="No usable invisible alphanumeric boxes.")
                   for p in records(root / "catalogue-no-boxes.jsonl"))
    joined = by_page(reviews)
    for method, path in (("ink", ink), ("contrast", contrast)):
        scores = by_page(records(path))
        assert joined.keys() == scores.keys() and len(scores)==48
        for key, r in scores.items():
            native = r["native"]
            joined[key][method+"_cw"] = native["placement_cw"]
            joined[key]["sampled"] = native["sampled"]
            assert bool(native["sampled"]) == (joined[key]["placement"] != "unavailable")
        print(method, sorted(Counter((r["placement"],outcome(r[method+"_cw"])) for r in joined.values()).items()))
    (root / "native-joined.jsonl").write_text("".join(json.dumps(joined[k])+"\n" for k in sorted(joined)))
    for r in joined.values():
        if r["placement"] in ("mixed","uncertain") or r["ink_cw"]:
            print(r)


if __name__=="__main__":
    parser=argparse.ArgumentParser(description=__doc__)
    for name in ("root","ink","contrast"):
        parser.add_argument(name,type=Path)
    main(**vars(parser.parse_args()))