File size: 8,500 Bytes
427879d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | ---
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<n<10M
configs:
- config_name: default
data_files: "country=*/*.arrow"
---
# LPR crops: multi-country license plate crops
Cropped license plate images with plate text, from 91 countries, stored as Arrow IPC shards with one folder per country.
| | |
|---|---|
| Rows | 1,754,235 (1,683,308 after the recommended filters, see below) |
| Countries | 91 (ISO-2, from the `country=XX/` folder name) |
| Files | 303 Arrow shards, about 36 GB |
| Splits (after filters) | train 1,141,747 · val 212,755 · test 328,806, given in the `split` column |
| Largest countries | CN 733k · BY 178k · AE 54k · KG 39k · AM 28k · KZ 28k · BR 25k |
## Layout
```
country=AD/autoria_eu-part-0.arrow
country=BY/platesmania-BY-part-0.arrow
...
```
The country is **not** stored as a column. Take it from the folder name.
## Main columns
| Column | Type | Notes |
|---|---|---|
| `crop_bytes` | binary | Plate crop, JPEG (`crop_format`) |
| `render_bytes` | binary | Optional rectified rendering, PNG (`render_format`) |
| `plate_text` | string | Label |
| `original_text` | string | Label before normalisation |
| `layout` | string | `one_line` / `two_line` / null |
| `split` | string | `train` / `val` / `test` |
| `source_dataset`, `license` | string | Where the row came from and its license (see Licensing) |
| `label_pairing` | string | `bound` / `unverified` / `ambiguous` |
| `exclusion`, `crop_missing` | string | Non-null means the row should be dropped |
| `several_plates` | bool | The frame contains more than one plate |
| `plate_quad`, `char_boxes`, `crop_xyxy`, `frame_size`, `tilt_deg`, … | | Geometry metadata |
**Recommended filters:** non-empty `plate_text`; `exclusion` is null; `crop_missing` is null; `several_plates` is not true.
## Download
```bash
pip install -U huggingface_hub
# all countries
hf download quangduc/lpr --repo-type dataset --local-dir data/crops
# selected countries
hf download quangduc/lpr --repo-type dataset --local-dir data/crops --include "country=BY/*" "country=AD/*"
```
### Download script
Save as `download_lpr.py`:
```python
#!/usr/bin/env python
"""Download quangduc/lpr (Arrow shards, one folder per country).
python download_lpr.py --list # countries and sizes
python download_lpr.py --out data/crops --countries BY AD # subset
python download_lpr.py --out data/crops # everything (~36 GB)
"""
import argparse
import re
from collections import defaultdict
from huggingface_hub import HfApi, snapshot_download
REPO_ID = "quangduc/lpr"
def list_countries(repo, revision):
sizes, counts = defaultdict(int), defaultdict(int)
for f in HfApi().list_repo_tree(repo, repo_type="dataset", revision=revision, recursive=True):
m = re.match(r"country=([A-Z]{2})/.+\.arrow$", f.path)
if m and getattr(f, "size", None) is not None:
sizes[m.group(1)] += f.size
counts[m.group(1)] += 1
for c in sorted(sizes, key=lambda k: -sizes[k]):
print(f"{c} {counts[c]:3d} files {sizes[c] / 2**30:7.2f} GiB")
print(f"total: {len(sizes)} countries, {sum(counts.values())} files, "
f"{sum(sizes.values()) / 2**30:.2f} GiB")
def main():
p = argparse.ArgumentParser()
p.add_argument("--repo", default=REPO_ID)
p.add_argument("--revision", default="main")
p.add_argument("--out", default="data/crops", help="Local folder; keeps the country=XX/ layout.")
p.add_argument("--countries", nargs="*", default=None, help="ISO-2 codes, e.g. BY AD CN (default: all).")
p.add_argument("--workers", type=int, default=8)
p.add_argument("--list", action="store_true", help="List countries and sizes, then exit.")
args = p.parse_args()
if args.list:
list_countries(args.repo, args.revision)
return
patterns = ([f"country={c.upper()}/*.arrow" for c in args.countries]
if args.countries else ["country=*/*.arrow"])
path = snapshot_download(repo_id=args.repo, repo_type="dataset", revision=args.revision,
local_dir=args.out, allow_patterns=patterns, max_workers=args.workers)
print(f"downloaded to {path}")
if __name__ == "__main__":
main()
```
Requires `pip install -U huggingface_hub`. If the repo is private, run `hf auth login` first or set `HF_TOKEN`.
### Retry / keep in sync (`rerun.sh`)
Long downloads can fail on network errors. `snapshot_download` resumes and skips files that are already complete, so re-running the script is safe. `rerun.sh` runs a Python script in a loop: it waits `success_wait` seconds after a success and `fail_wait` seconds after a failure, and stops after `max_runs` runs (0 = never stop).
```bash
chmod +x rerun.sh
# retry every 5 min on failure, re-sync every hour after success; give all three numbers before `--`
nohup ./rerun.sh download_lpr.py 3600 300 0 -- --out data/crops > 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
|