--- license: other license_name: mixed-per-row license_link: LICENSE pretty_name: LPR crops (multi-country license plates) task_categories: - image-to-text tags: - ocr - license-plate - lpr - arrow size_categories: - 1M rerun.log 2>&1 & # one country: 3 runs total, 5 min apart (later runs only fetch what's missing or new) ./rerun.sh download_lpr.py 300 300 3 -- --out data/crops --countries BY ``` Save as `rerun.sh`: ```bash #!/usr/bin/env bash # Re-run a Python script forever: wait SUCCESS_WAIT after success, FAIL_WAIT after failure. # Usage: ./rerun.sh script.py [success_wait_sec] [fail_wait_sec] [max_runs] [-- script args...] # ./rerun.sh /home/jovyan/test.py 3600 300 # ./rerun.sh test.py 3600 300 0 -- --country VN # max_runs 0 = unlimited # nohup ./rerun.sh test.py 3600 300 > rerun.log 2>&1 & set -u SCRIPT="${1:?usage: $0 script.py [success_wait] [fail_wait] [max_runs] [-- args]}" SUCCESS_WAIT="${2:-3600}" FAIL_WAIT="${3:-300}" MAX_RUNS="${4:-0}" shift $(( $# < 4 ? $# : 4 )) [ "${1:-}" = "--" ] && shift ARGS=("$@") PYTHON="${PYTHON:-python}" trap 'echo "$(date "+%F %T") stopped"; exit 0' INT TERM run=0 while true; do run=$((run + 1)) echo "$(date '+%F %T') run #$run: $PYTHON $SCRIPT ${ARGS[*]:-}" "$PYTHON" "$SCRIPT" "${ARGS[@]}" code=$? if [ "$code" -eq 0 ]; then wait_s=$SUCCESS_WAIT; status=OK; else wait_s=$FAIL_WAIT; status="FAILED(exit $code)"; fi echo "$(date '+%F %T') run #$run $status; next run in ${wait_s}s" if [ "$MAX_RUNS" -gt 0 ] && [ "$run" -ge "$MAX_RUNS" ]; then echo "reached max_runs=$MAX_RUNS"; exit "$code"; fi sleep "$wait_s" & wait $! done ``` ## Load ```python import io, glob, re import pyarrow as pa from PIL import Image for path in sorted(glob.glob("data/crops/country=*/*.arrow")): country = re.search(r"country=([A-Z]{2})", path).group(1) table = pa.ipc.open_file(pa.memory_map(path)).read_all() row = table.slice(0, 1).to_pylist()[0] img = Image.open(io.BytesIO(row["crop_bytes"])).convert("RGB") print(country, row["plate_text"], row["split"], img.size) break ``` With 🤗 Datasets (streaming avoids downloading everything first): ```python from datasets import load_dataset ds = load_dataset("quangduc/lpr", split="train", streaming=True) # the HF "train" split here = all rows; filter on the `split` column ``` ## Licensing Rows come from several sources with **different licenses**, given per row in the `license` column: | `license` | Example sources | |---|---| | MIT | ccpd | | CC-BY-4.0 | autoria_* | | platesmania-attribution | platesmania | | proprietary-viettel | viettel_combvt | Check the license of each row's source before using or redistributing it. Rows marked `proprietary-viettel` are not licensed for public redistribution unless you hold rights to them. set -u SCRIPT="${1:?usage: $0 script.py [success_wait] [fail_wait] [max_runs] [-- args]}" SUCCESS_WAIT="${2:-3600}" FAIL_WAIT="${3:-300}" MAX_RUNS="${4:-0}" shift $(( $# < 4 ? $# : 4 )) [ "${1:-}" = "--" ] && shift ARGS=("$@") PYTHON="${PYTHON:-python}" trap 'echo "$(date "+%F %T") stopped"; exit 0' INT TERM run=0 while true; do run=$((run + 1)) echo "$(date '+%F %T') run #$run: $PYTHON $SCRIPT ${ARGS[*]:-}" "$PYTHON" "$SCRIPT" "${ARGS[@]}" code=$? if [ "$code" -eq 0 ]; then wait_s=$SUCCESS_WAIT; status=OK; else wait_s=$FAIL_WAIT; status="FAILED(exit $code)"; fi echo "$(date '+%F %T') run #$run $status; next run in ${wait_s}s" if [ "$MAX_RUNS" -gt 0 ] && [ "$run" -ge "$MAX_RUNS" ]; then echo "reached max_runs=$MAX_RUNS"; exit "$code"; fi sleep "$wait_s" & wait $! done