Download src/linedet/mix_selftest.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/src/linedet/mix_selftest.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/src/linedet/mix_selftest.py
-
curl -L -o mix_selftest.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/src/linedet/mix_selftest.py
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)) | |