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|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: mixed-per-row
|
| 4 |
+
license_link: LICENSE
|
| 5 |
+
pretty_name: LPR crops (multi-country license plates)
|
| 6 |
+
task_categories:
|
| 7 |
+
- image-to-text
|
| 8 |
+
tags:
|
| 9 |
+
- ocr
|
| 10 |
+
- license-plate
|
| 11 |
+
- lpr
|
| 12 |
+
- arrow
|
| 13 |
+
size_categories:
|
| 14 |
+
- 1M<n<10M
|
| 15 |
+
configs:
|
| 16 |
+
- config_name: default
|
| 17 |
+
data_files: "country=*/*.arrow"
|
| 18 |
---
|
| 19 |
+
|
| 20 |
+
# LPR crops: multi-country license plate crops
|
| 21 |
+
|
| 22 |
+
Cropped license plate images with plate text, from 91 countries, stored as Arrow IPC shards with one folder per country.
|
| 23 |
+
|
| 24 |
+
| | |
|
| 25 |
+
|---|---|
|
| 26 |
+
| Rows | 1,754,235 (1,683,308 after the recommended filters, see below) |
|
| 27 |
+
| Countries | 91 (ISO-2, from the `country=XX/` folder name) |
|
| 28 |
+
| Files | 303 Arrow shards, about 36 GB |
|
| 29 |
+
| Splits (after filters) | train 1,141,747 · val 212,755 · test 328,806, given in the `split` column |
|
| 30 |
+
| Largest countries | CN 733k · BY 178k · AE 54k · KG 39k · AM 28k · KZ 28k · BR 25k |
|
| 31 |
+
|
| 32 |
+
## Layout
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
country=AD/autoria_eu-part-0.arrow
|
| 36 |
+
country=BY/platesmania-BY-part-0.arrow
|
| 37 |
+
...
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
The country is **not** stored as a column. Take it from the folder name.
|
| 41 |
+
|
| 42 |
+
## Main columns
|
| 43 |
+
|
| 44 |
+
| Column | Type | Notes |
|
| 45 |
+
|---|---|---|
|
| 46 |
+
| `crop_bytes` | binary | Plate crop, JPEG (`crop_format`) |
|
| 47 |
+
| `render_bytes` | binary | Optional rectified rendering, PNG (`render_format`) |
|
| 48 |
+
| `plate_text` | string | Label |
|
| 49 |
+
| `original_text` | string | Label before normalisation |
|
| 50 |
+
| `layout` | string | `one_line` / `two_line` / null |
|
| 51 |
+
| `split` | string | `train` / `val` / `test` |
|
| 52 |
+
| `source_dataset`, `license` | string | Where the row came from and its license (see Licensing) |
|
| 53 |
+
| `label_pairing` | string | `bound` / `unverified` / `ambiguous` |
|
| 54 |
+
| `exclusion`, `crop_missing` | string | Non-null means the row should be dropped |
|
| 55 |
+
| `several_plates` | bool | The frame contains more than one plate |
|
| 56 |
+
| `plate_quad`, `char_boxes`, `crop_xyxy`, `frame_size`, `tilt_deg`, … | | Geometry metadata |
|
| 57 |
+
|
| 58 |
+
**Recommended filters:** non-empty `plate_text`; `exclusion` is null; `crop_missing` is null; `several_plates` is not true.
|
| 59 |
+
|
| 60 |
+
## Download
|
| 61 |
+
|
| 62 |
+
```bash
|
| 63 |
+
pip install -U huggingface_hub
|
| 64 |
+
# all countries
|
| 65 |
+
hf download quangduc/lpr --repo-type dataset --local-dir data/crops
|
| 66 |
+
# selected countries
|
| 67 |
+
hf download quangduc/lpr --repo-type dataset --local-dir data/crops --include "country=BY/*" "country=AD/*"
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### Download script
|
| 71 |
+
|
| 72 |
+
Save as `download_lpr.py`:
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
#!/usr/bin/env python
|
| 76 |
+
"""Download quangduc/lpr (Arrow shards, one folder per country).
|
| 77 |
+
|
| 78 |
+
python download_lpr.py --list # countries and sizes
|
| 79 |
+
python download_lpr.py --out data/crops --countries BY AD # subset
|
| 80 |
+
python download_lpr.py --out data/crops # everything (~36 GB)
|
| 81 |
+
"""
|
| 82 |
+
import argparse
|
| 83 |
+
import re
|
| 84 |
+
from collections import defaultdict
|
| 85 |
+
|
| 86 |
+
from huggingface_hub import HfApi, snapshot_download
|
| 87 |
+
|
| 88 |
+
REPO_ID = "quangduc/lpr"
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def list_countries(repo, revision):
|
| 92 |
+
sizes, counts = defaultdict(int), defaultdict(int)
|
| 93 |
+
for f in HfApi().list_repo_tree(repo, repo_type="dataset", revision=revision, recursive=True):
|
| 94 |
+
m = re.match(r"country=([A-Z]{2})/.+\.arrow$", f.path)
|
| 95 |
+
if m and getattr(f, "size", None) is not None:
|
| 96 |
+
sizes[m.group(1)] += f.size
|
| 97 |
+
counts[m.group(1)] += 1
|
| 98 |
+
for c in sorted(sizes, key=lambda k: -sizes[k]):
|
| 99 |
+
print(f"{c} {counts[c]:3d} files {sizes[c] / 2**30:7.2f} GiB")
|
| 100 |
+
print(f"total: {len(sizes)} countries, {sum(counts.values())} files, "
|
| 101 |
+
f"{sum(sizes.values()) / 2**30:.2f} GiB")
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def main():
|
| 105 |
+
p = argparse.ArgumentParser()
|
| 106 |
+
p.add_argument("--repo", default=REPO_ID)
|
| 107 |
+
p.add_argument("--revision", default="main")
|
| 108 |
+
p.add_argument("--out", default="data/crops", help="Local folder; keeps the country=XX/ layout.")
|
| 109 |
+
p.add_argument("--countries", nargs="*", default=None, help="ISO-2 codes, e.g. BY AD CN (default: all).")
|
| 110 |
+
p.add_argument("--workers", type=int, default=8)
|
| 111 |
+
p.add_argument("--list", action="store_true", help="List countries and sizes, then exit.")
|
| 112 |
+
args = p.parse_args()
|
| 113 |
+
|
| 114 |
+
if args.list:
|
| 115 |
+
list_countries(args.repo, args.revision)
|
| 116 |
+
return
|
| 117 |
+
patterns = ([f"country={c.upper()}/*.arrow" for c in args.countries]
|
| 118 |
+
if args.countries else ["country=*/*.arrow"])
|
| 119 |
+
path = snapshot_download(repo_id=args.repo, repo_type="dataset", revision=args.revision,
|
| 120 |
+
local_dir=args.out, allow_patterns=patterns, max_workers=args.workers)
|
| 121 |
+
print(f"downloaded to {path}")
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
if __name__ == "__main__":
|
| 125 |
+
main()
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
Requires `pip install -U huggingface_hub`. If the repo is private, run `hf auth login` first or set `HF_TOKEN`.
|
| 129 |
+
|
| 130 |
+
## Load
|
| 131 |
+
|
| 132 |
+
```python
|
| 133 |
+
import io, glob, re
|
| 134 |
+
import pyarrow as pa
|
| 135 |
+
from PIL import Image
|
| 136 |
+
|
| 137 |
+
for path in sorted(glob.glob("data/crops/country=*/*.arrow")):
|
| 138 |
+
country = re.search(r"country=([A-Z]{2})", path).group(1)
|
| 139 |
+
table = pa.ipc.open_file(pa.memory_map(path)).read_all()
|
| 140 |
+
row = table.slice(0, 1).to_pylist()[0]
|
| 141 |
+
img = Image.open(io.BytesIO(row["crop_bytes"])).convert("RGB")
|
| 142 |
+
print(country, row["plate_text"], row["split"], img.size)
|
| 143 |
+
break
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
With 🤗 Datasets (streaming avoids downloading everything first):
|
| 147 |
+
|
| 148 |
+
```python
|
| 149 |
+
from datasets import load_dataset
|
| 150 |
+
ds = load_dataset("quangduc/lpr", split="train", streaming=True) # the HF "train" split here = all rows; filter on the `split` column
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## Licensing
|
| 154 |
+
|
| 155 |
+
Rows come from several sources with **different licenses**, given per row in the `license` column:
|
| 156 |
+
|
| 157 |
+
| `license` | Example sources |
|
| 158 |
+
|---|---|
|
| 159 |
+
| MIT | ccpd |
|
| 160 |
+
| CC-BY-4.0 | autoria_* |
|
| 161 |
+
| platesmania-attribution | platesmania |
|
| 162 |
+
| proprietary-viettel | viettel_combvt |
|
| 163 |
+
|
| 164 |
+
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.
|