Download scripts/k1_labels_all.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 932 Bytes
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/k1_labels_all.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/k1_labels_all.py
-
curl -L -o k1_labels_all.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/k1_labels_all.py
932 Bytes
| # K1 (runs on the cluster, ZEN4): read every KOHTD ann file (JSON with the label) and write one TSV: file stem, label. | |
| # Text only; no image is read. usage: python k1_labels_all.py <HK_dataset/ann dir> <out_tsv> | |
| import json | |
| import os | |
| import sys | |
| from concurrent.futures import ThreadPoolExecutor | |
| ann, out = sys.argv[1], sys.argv[2] | |
| names = sorted(e.name for e in os.scandir(ann) if e.name.endswith(".json")) | |
| print("ann files:", len(names), flush=True) | |
| def read(n): | |
| with open(os.path.join(ann, n), encoding="utf-8") as f: | |
| d = json.load(f) | |
| return n[:-5], str(d.get("description", "")).replace("\t", " ").replace("\n", " ") | |
| with ThreadPoolExecutor(32) as ex, open(out, "w", encoding="utf-8") as f: | |
| f.write("stem\tlabel\n") | |
| for i, (stem, lab) in enumerate(ex.map(read, names, chunksize=64)): | |
| f.write(stem + "\t" + lab + "\n") | |
| if i % 20000 == 0: | |
| print(i, flush=True) | |
| print("done") | |