Download scripts/r5_ref/test_pass_commands.sh from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 5.91 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_ref/test_pass_commands.sh
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/r5_ref/test_pass_commands.sh
-
curl -L -o test_pass_commands.sh https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_ref/test_pass_commands.sh
5.91 kB
| # R5 REF: test-set predictions of the reference runs, to be run on a compute node ONLY in the scoring pass. | |
| # 24 Nov 2026 (J8): each run is independent (a failed run is logged and the script goes on; the exit code is non-zero if any run failed), | |
| # and the order is ours, then rand, then mix. Nothing else changed: same gate file, same device logic, same commands and outputs. | |
| # | |
| # Order of use: | |
| # 1. write records/R5/RULE/test_pass_started.txt (as always) and copy it to the cluster: | |
| # /usr/bin/scp <records>/R5/RULE/test_pass_started.txt CLUSTER:/path/to/TURKIC_OCR_DATA/outputs/r5/ref/test_pass_started.txt | |
| # The prediction scripts REFUSE every locked set (evalsets.json locked=true, or a test manifest) while that file does not exist. | |
| # 2. run this script inside a job, GPU or CPU, for example: | |
| # sbatch --partition=ZEN4 --qos=nu-zen4 --gres=none --cpus-per-task=16 --mem=48G --time=02:00:00 \ | |
| # --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out --job-name=r5_ref_testpass \ | |
| # --wrap "REF_DEVICE=cpu bash /path/to/TURKIC_OCR_CODE/scripts/r5_ref/test_pass_commands.sh" | |
| # (REF_DEVICE=gpu runs on a GPU node; the default is gpu.) | |
| # | |
| # What it writes (shared prediction format, DATA/outputs/r5/preds/<arm>/<checkpoint>/<set>.tsv + meta.json), in this order: | |
| # 1. R1/ours, R1/ours_paperdec HTR-Flor trained on KOHTD train forms (i): kohtd_test, kohtd_test_p2, kohtd_test_p2b | |
| # R2/ours PaddleOCR PP-OCRv3 recogniser (i): kohtd_test, kohtd_test_p2, kohtd_test_p2b | |
| # 2. R1/rand, R1/rand_paperdec HTR-Flor trained on the replication split (ii): kohtd_rand_test | |
| # R2/rand PaddleOCR PP-OCRv3 recogniser (ii): kohtd_rand_test | |
| # 3. R1/mix, R1/mix_paperdec HTR-Flor trained on mix_v1 to 150,016 samples (iii): kohtd_test, kohtd_test_p2, kohtd_test_p2b | |
| # R2/mix PaddleOCR PP-OCRv3 recogniser trained on mix_v1 (iii): kohtd_test, kohtd_test_p2, kohtd_test_p2b | |
| # and the published papers' own metrics (HTR-Flor style, Bimurat style, PaddleOCR style) in DATA/outputs/r5/ref/metrics_test/*.json, each group's metrics | |
| # right after its predictions (so a stop during a later group keeps the earlier groups' metrics). | |
| # The "rand" checkpoints are never run on kohtd_test (their training forms overlap it); the "ours" checkpoints are never run on kohtd_rand_test. | |
| # no `set -e`: every run is independent. A failed run is logged ("=== FAILED ...") and counted; the script exits 1 at the end if any run failed. | |
| set -u | |
| unset HF_TOKEN HUGGING_FACE_HUB_TOKEN | |
| C=/path/to/TURKIC_OCR_CODE | |
| D=/path/to/TURKIC_OCR_DATA | |
| S=$C/scripts/r5_ref | |
| M=$D/data/processed/r5/manifests | |
| TFPY=$C/.venv_ref_tf/bin/python | |
| PDPY=$C/.venv_ref_paddle/bin/python | |
| if [ ! -f $D/outputs/r5/ref/test_pass_started.txt ]; then | |
| # the gate is enforced by every prediction script itself (they refuse a locked set before any image is read); this script does not stop here, so that | |
| # every run reports its own refusal and the script reaches its end | |
| echo "NOTICE: $D/outputs/r5/ref/test_pass_started.txt does not exist (the scoring pass has not started): every run below will REFUSE" | |
| fi | |
| CPU="" | |
| if [ "${REF_DEVICE:-gpu}" = "cpu" ]; then CPU="--cpu"; fi | |
| mkdir -p $D/outputs/r5/ref/metrics_test | |
| OURS_SETS="kohtd_test=$M/kohtd_test.tsv,kohtd_test_p2=$M/kohtd_test_p2.tsv,kohtd_test_p2b=$M/kohtd_test_p2b.tsv" | |
| RAND_SETS="kohtd_rand_test=$M/kohtd_rand_test.tsv" | |
| export TF_FORCE_GPU_ALLOW_GROWTH=true TF_CPP_MIN_LOG_LEVEL=2 | |
| export FLAGS_allocator_strategy=auto_growth | |
| FAILED=0 | |
| FAILED_LIST="" | |
| # run <name> <command...>: runs the command, logs OK or FAILED with its exit code, never stops the script | |
| run() { | |
| local name=$1 | |
| shift | |
| echo "=== RUN $name $(date -u +%Y-%m-%dT%H:%M:%SZ)" | |
| "$@" | |
| local rc=$? | |
| if [ $rc -ne 0 ]; then | |
| echo "=== FAILED $name rc=$rc $(date -u +%Y-%m-%dT%H:%M:%SZ)" | |
| FAILED=$((FAILED + 1)) | |
| FAILED_LIST="$FAILED_LIST [$name]" | |
| else | |
| echo "=== OK $name $(date -u +%Y-%m-%dT%H:%M:%SZ)" | |
| fi | |
| } | |
| P=$D/outputs/r5/preds | |
| # metrics <arm/checkpoint folder> <set>: the papers' own metrics on one prediction file | |
| metrics() { | |
| run "metrics $1 $2" $TFPY -I $S/ref_paper_metrics.py $P/$1/$2.tsv $D/outputs/r5/ref/metrics_test/$(echo $1 | tr / _)_$2.json | |
| } | |
| # 1. ours (i): R1 writes ours and ours_paperdec; R2 writes ours | |
| run "R1 ours (i)" $TFPY -I $S/ref_flor_predict.py --run i --sets "$OURS_SETS" $CPU | |
| run "R2 ours (i)" $PDPY -I $S/ref_ppocr_predict.py --run i --sets "$OURS_SETS" --weights $D/checkpoints/r5/ref/R2_i/model/latest $CPU | |
| for f in R1/ours R1/ours_paperdec R2/ours; do | |
| for s in kohtd_test kohtd_test_p2 kohtd_test_p2b; do metrics $f $s; done | |
| done | |
| # 2. rand (ii): R1 writes rand and rand_paperdec; R2 writes rand | |
| run "R1 rand (ii)" $TFPY -I $S/ref_flor_predict.py --run ii --sets "$RAND_SETS" $CPU | |
| run "R2 rand (ii)" $PDPY -I $S/ref_ppocr_predict.py --run ii --sets "$RAND_SETS" --weights $D/checkpoints/r5/ref/R2_ii/model/latest $CPU | |
| # R2 (i) and (ii): --weights <train_dir>/model/latest = the last epoch saved; the wrapper's best_accuracy file does not exist because these runs never reached the | |
| # 2000-iteration evaluation (found 22 Nov 2026). Epoch and sample counts in the prediction metadata now come from progress.json. | |
| for f in R1/rand R1/rand_paperdec R2/rand; do metrics $f kohtd_rand_test; done | |
| # 3. mix (iii), trained on mix_v1 (clarification H5): same test sets as (i) | |
| run "R1 mix (iii)" $TFPY -I $S/ref_flor_predict.py --run iii --sets "$OURS_SETS" $CPU | |
| run "R2 mix (iii)" $PDPY -I $S/ref_ppocr_predict.py --run iii --sets "$OURS_SETS" $CPU | |
| for f in R1/mix R1/mix_paperdec R2/mix; do | |
| for s in kohtd_test kohtd_test_p2 kohtd_test_p2b; do metrics $f $s; done | |
| done | |
| if [ $FAILED -ne 0 ]; then | |
| echo "reference-arm test pass ended: $FAILED step(s) failed:$FAILED_LIST" | |
| exit 1 | |
| fi | |
| echo "reference-arm test predictions and metrics written" | |