turkic-ocr-code / scripts /r5_vlma /make_smoke_seq.py
treoa's picture
Release 1
24aaa76
Raw History Blame Contribute Delete
1.06 kB
"""R5 VLMA smoke sequence: a fixed shuffle (seed 20261121) of KOHTD TRAIN crops only (K1 split v1), in the sequence
format used by train_vlm.py (row, id, image, text, unit, kind, lang, source). Used only for the 20-step smoke tests.
usage: make_smoke_seq.py K1_TRAIN_TSV IMG_DIR OUT_TSV [N]
"""
import random
import sys
import unicodedata
src, img_dir, out = sys.argv[1:4]
n = int(sys.argv[4]) if len(sys.argv) > 4 else 2000
rows = []
with open(src, encoding="utf-8") as f:
hdr = f.readline().rstrip("\n").split("\t")
assert hdr[:3] == ["crop_file", "form_id", "label"], hdr
for line in f:
p = line.rstrip("\n").split("\t")
rows.append((p[0], unicodedata.normalize("NFC", p[2])))
rng = random.Random(20261121)
rng.shuffle(rows)
with open(out, "w", encoding="utf-8") as f:
f.write("row\tid\timage\ttext\tunit\tkind\tlang\tsource\n")
for i, (c, t) in enumerate(rows[:n]):
f.write(f"{i}\tkohtd_train:{c}\t{img_dir}/{c}\t{t}\tword\thand_real\tkk\tkohtd_train\n")
print("rows", min(n, len(rows)), "of", len(rows))