Download scripts/r5_vlmb/smoke_seq.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_vlmb/smoke_seq.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/r5_vlmb/smoke_seq.py
-
curl -L -o smoke_seq.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_vlmb/smoke_seq.py
1.09 kB
| """Smoke-test sample list from KOHTD train only (kohtd_split_v1/train.tsv): N crops, seeded shuffle. | |
| usage: smoke_seq.py TRAIN_TSV IMG_DIR OUT_TSV N SEED | |
| """ | |
| import os | |
| import random | |
| import sys | |
| import unicodedata | |
| train_tsv, img_dir, out_tsv, n, seed = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4]), int(sys.argv[5]) | |
| assert os.path.basename(train_tsv) == "train.tsv" | |
| rows = [] | |
| with open(train_tsv, 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") | |
| if p[2].strip(): | |
| rows.append(p) | |
| random.Random(seed).shuffle(rows) | |
| with open(out_tsv, "w", encoding="utf-8") as fo: | |
| fo.write("id\timage\ttext\tlang\tscript\tkind\tsource\tsplit\tgroup\tunit\n") | |
| for p in rows[:n]: | |
| fo.write("\t".join([p[0], os.path.join(img_dir, p[0]), unicodedata.normalize("NFC", p[2]), "kk", "Cyrl", | |
| "hand_real", "kohtd", "train", p[1], "word"]) + "\n") | |
| print("wrote", min(n, len(rows)), "of", len(rows)) | |