quangduc commited on
Commit
427879d
·
verified ·
1 Parent(s): 2e42a59

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +239 -0
README.md ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ### Retry / keep in sync (`rerun.sh`)
131
+
132
+ 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).
133
+
134
+ ```bash
135
+ chmod +x rerun.sh
136
+ # retry every 5 min on failure, re-sync every hour after success; give all three numbers before `--`
137
+ nohup ./rerun.sh download_lpr.py 3600 300 0 -- --out data/crops > rerun.log 2>&1 &
138
+ # one country: 3 runs total, 5 min apart (later runs only fetch what's missing or new)
139
+ ./rerun.sh download_lpr.py 300 300 3 -- --out data/crops --countries BY
140
+ ```
141
+
142
+ Save as `rerun.sh`:
143
+
144
+ ```bash
145
+ #!/usr/bin/env bash
146
+ # Re-run a Python script forever: wait SUCCESS_WAIT after success, FAIL_WAIT after failure.
147
+ # Usage: ./rerun.sh script.py [success_wait_sec] [fail_wait_sec] [max_runs] [-- script args...]
148
+ # ./rerun.sh /home/jovyan/test.py 3600 300
149
+ # ./rerun.sh test.py 3600 300 0 -- --country VN # max_runs 0 = unlimited
150
+ # nohup ./rerun.sh test.py 3600 300 > rerun.log 2>&1 &
151
+
152
+ set -u
153
+ SCRIPT="${1:?usage: $0 script.py [success_wait] [fail_wait] [max_runs] [-- args]}"
154
+ SUCCESS_WAIT="${2:-3600}"
155
+ FAIL_WAIT="${3:-300}"
156
+ MAX_RUNS="${4:-0}"
157
+ shift $(( $# < 4 ? $# : 4 ))
158
+ [ "${1:-}" = "--" ] && shift
159
+ ARGS=("$@")
160
+
161
+ PYTHON="${PYTHON:-python}"
162
+ trap 'echo "$(date "+%F %T") stopped"; exit 0' INT TERM
163
+
164
+ run=0
165
+ while true; do
166
+ run=$((run + 1))
167
+ echo "$(date '+%F %T') run #$run: $PYTHON $SCRIPT ${ARGS[*]:-}"
168
+ "$PYTHON" "$SCRIPT" "${ARGS[@]}"
169
+ code=$?
170
+ if [ "$code" -eq 0 ]; then wait_s=$SUCCESS_WAIT; status=OK; else wait_s=$FAIL_WAIT; status="FAILED(exit $code)"; fi
171
+ echo "$(date '+%F %T') run #$run $status; next run in ${wait_s}s"
172
+ if [ "$MAX_RUNS" -gt 0 ] && [ "$run" -ge "$MAX_RUNS" ]; then echo "reached max_runs=$MAX_RUNS"; exit "$code"; fi
173
+ sleep "$wait_s" &
174
+ wait $!
175
+ done
176
+ ```
177
+
178
+ ## Load
179
+
180
+ ```python
181
+ import io, glob, re
182
+ import pyarrow as pa
183
+ from PIL import Image
184
+
185
+ for path in sorted(glob.glob("data/crops/country=*/*.arrow")):
186
+ country = re.search(r"country=([A-Z]{2})", path).group(1)
187
+ table = pa.ipc.open_file(pa.memory_map(path)).read_all()
188
+ row = table.slice(0, 1).to_pylist()[0]
189
+ img = Image.open(io.BytesIO(row["crop_bytes"])).convert("RGB")
190
+ print(country, row["plate_text"], row["split"], img.size)
191
+ break
192
+ ```
193
+
194
+ With 🤗 Datasets (streaming avoids downloading everything first):
195
+
196
+ ```python
197
+ from datasets import load_dataset
198
+ ds = load_dataset("quangduc/lpr", split="train", streaming=True) # the HF "train" split here = all rows; filter on the `split` column
199
+ ```
200
+
201
+ ## Licensing
202
+
203
+ Rows come from several sources with **different licenses**, given per row in the `license` column:
204
+
205
+ | `license` | Example sources |
206
+ |---|---|
207
+ | MIT | ccpd |
208
+ | CC-BY-4.0 | autoria_* |
209
+ | platesmania-attribution | platesmania |
210
+ | proprietary-viettel | viettel_combvt |
211
+
212
+ 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.
213
+
214
+
215
+
216
+ set -u
217
+ SCRIPT="${1:?usage: $0 script.py [success_wait] [fail_wait] [max_runs] [-- args]}"
218
+ SUCCESS_WAIT="${2:-3600}"
219
+ FAIL_WAIT="${3:-300}"
220
+ MAX_RUNS="${4:-0}"
221
+ shift $(( $# < 4 ? $# : 4 ))
222
+ [ "${1:-}" = "--" ] && shift
223
+ ARGS=("$@")
224
+
225
+ PYTHON="${PYTHON:-python}"
226
+ trap 'echo "$(date "+%F %T") stopped"; exit 0' INT TERM
227
+
228
+ run=0
229
+ while true; do
230
+ run=$((run + 1))
231
+ echo "$(date '+%F %T') run #$run: $PYTHON $SCRIPT ${ARGS[*]:-}"
232
+ "$PYTHON" "$SCRIPT" "${ARGS[@]}"
233
+ code=$?
234
+ if [ "$code" -eq 0 ]; then wait_s=$SUCCESS_WAIT; status=OK; else wait_s=$FAIL_WAIT; status="FAILED(exit $code)"; fi
235
+ echo "$(date '+%F %T') run #$run $status; next run in ${wait_s}s"
236
+ if [ "$MAX_RUNS" -gt 0 ] && [ "$run" -ge "$MAX_RUNS" ]; then echo "reached max_runs=$MAX_RUNS"; exit "$code"; fi
237
+ sleep "$wait_s" &
238
+ wait $!
239
+ done