turkic-ocr-code / src /linedet /mix_selftest.py
treoa's picture
Release 1
24aaa76
Raw History Blame Contribute Delete
1.22 kB
"""Self-test of data.load_mix on three plausible layouts of mix_v1.yaml (written to DATA/tmp). Prints the flattened shares."""
import os
import sys
from . import data as D
from .common import DATA
TMP = DATA + "/tmp/mix_selftest"
os.makedirs(TMP, exist_ok=True)
A = """components:
- name: kohtd
manifest: /x/kohtd_train.tsv
share: 0.35
- name: other_cyr
share: 0.15
members:
- {manifest: /x/hkr_train.tsv}
- {manifest: /x/chd_train.tsv}
- {manifest: /x/school_train.tsv}
- name: hand_synth
share: 0.35
manifests: [/x/s1.tsv, /x/s2.tsv]
- name: typed
manifest: /x/typed.tsv
share: 0.12
filter: {kind: typed_synth}
- name: clutter
manifest: /x/clutter.tsv
share: 0.03
"""
B = """sources:
kohtd: {path: /x/kohtd_train.tsv, weight: 35}
hkr: {path: /x/hkr_train.tsv, weight: 15}
"""
C = """- manifest: /x/a.tsv
share: 0.5
- manifest: /x/b.tsv
share: 0.5
"""
for nm, txt in (("A", A), ("B", B), ("C", C)):
p = "%s/mix_%s.yaml" % (TMP, nm)
open(p, "w").write(txt)
r = D.load_mix(p)
print(nm, [(c["name"], os.path.basename(c["manifest"]), round(c["share"], 4), c["filter"]) for c in r], "sum", round(sum(c["share"] for c in r), 6))