DibaAi commited on
Commit
4f5a43e
·
1 Parent(s): e296535

Add production ALPR models (YOLO detector + CRNN reader + CNN fallback) and model card

Browse files
Files changed (6) hide show
  1. README.md +117 -0
  2. ocr_cnn.labels.json +30 -0
  3. ocr_cnn.onnx +3 -0
  4. ocr_crnn.labels.json +1 -0
  5. ocr_crnn.onnx +3 -0
  6. plate_yolo.onnx +3 -0
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - fa
5
+ library_name: onnxruntime
6
+ pipeline_tag: image-to-text
7
+ tags:
8
+ - alpr
9
+ - license-plate-recognition
10
+ - ocr
11
+ - persian
12
+ - farsi
13
+ - iranian-license-plate
14
+ - crnn
15
+ - ctc
16
+ - yolo
17
+ - onnx
18
+ - object-detection
19
+ ---
20
+
21
+ # ocr-persian — Iranian License-Plate Recognition Models
22
+
23
+ Production ONNX models for detecting and reading **Iranian vehicle license
24
+ plates**, powering the [**Platrix**](https://github.com/AliAkrami1375/Platrix)
25
+ real-time, self-hosted plate-surveillance system.
26
+
27
+ The pipeline is **two-stage**: a YOLO **detector** locates the plate in the
28
+ frame, then a segmentation-free **CRNN + CTC reader** reads the whole plate at
29
+ once and returns the standard Iranian layout `DD L DDD DD`
30
+ (two digits · letter · three digits · two-digit region), e.g. `۸۱ و ۶۳۸ ۱۳`.
31
+
32
+ All models run with **ONNX Runtime** — no PyTorch or TensorFlow needed at
33
+ inference time.
34
+
35
+ ---
36
+
37
+ ## Files
38
+
39
+ | File | Role | Input | Output |
40
+ |------|------|-------|--------|
41
+ | `plate_yolo.onnx` | **Plate detector** (YOLOv8) | `1×3×H×W` RGB, letterboxed, `/255` | `1×5×N` → `cx,cy,w,h,conf` |
42
+ | `ocr_crnn.onnx` | **Whole-plate reader** (CRNN+CTC) — *recommended* | `1×1×32×128` grayscale, `/255` | `1×T×(C+1)` logits (CTC, blank = last) |
43
+ | `ocr_crnn.labels.json` | Class list for the CRNN (index → character) | — | 32 classes |
44
+ | `ocr_cnn.onnx` | Per-character classifier (lightweight fallback) | `1×1×32×32` grayscale | class logits |
45
+ | `ocr_cnn.labels.json` | Class list for the per-char classifier | — | — |
46
+
47
+ **Character set (32 classes):** digits `0–9` and the Persian plate letters
48
+ `ا ب ت ث ج ح د ز س ش ص ط ع ق ل م ن ه و پ ژ ی`.
49
+
50
+ ---
51
+
52
+ ## Why a segmentation-free reader?
53
+
54
+ Splitting a plate into individual characters is fragile on real photos
55
+ (shadows, motion blur, tilt, dirt). The CRNN reads the **entire plate in one
56
+ pass** with a CTC head, which is far more robust. It is trained on **real
57
+ Iranian plate-character shapes**, so look-alike glyphs (e.g. the digit `۴` vs
58
+ `۶`) are read correctly.
59
+
60
+ A key detail: the **same image-enhancement** (upscale → denoise → CLAHE
61
+ contrast → unsharp) is applied both during training and at serving time, so
62
+ there is no train/serve mismatch — the enhancement genuinely helps accuracy
63
+ instead of shifting the input distribution.
64
+
65
+ ---
66
+
67
+ ## Quick usage
68
+
69
+ ```bash
70
+ pip install onnxruntime opencv-python-headless numpy
71
+ huggingface-cli download Dibachain/ocr-persian \
72
+ plate_yolo.onnx ocr_crnn.onnx ocr_crnn.labels.json --local-dir models/
73
+ ```
74
+
75
+ ```python
76
+ import json, cv2, numpy as np, onnxruntime as ort
77
+
78
+ # --- Reader (CRNN + CTC) ---
79
+ labels = json.load(open("models/ocr_crnn.labels.json", encoding="utf-8"))
80
+ blank = len(labels) # CTC blank is the last index
81
+ crnn = ort.InferenceSession("models/ocr_crnn.onnx", providers=["CPUExecutionProvider"])
82
+
83
+ def read_plate(plate_bgr):
84
+ g = cv2.cvtColor(plate_bgr, cv2.COLOR_BGR2GRAY)
85
+ g = cv2.resize(g, (128, 32)).astype(np.float32) / 255.0 # 1x1x32x128
86
+ logits = crnn.run(None, {"input": g[None, None]})[0][0] # T x (C+1)
87
+ ids, out, prev = logits.argmax(1), [], -1
88
+ for i in ids: # greedy CTC decode
89
+ if i != blank and i != prev:
90
+ out.append(labels[i])
91
+ prev = i
92
+ return "".join(out)
93
+ ```
94
+
95
+ Run `plate_yolo.onnx` first to crop the plate from a full frame (standard
96
+ YOLOv8 letterbox pre-process + confidence/NMS post-process), then pass the crop
97
+ to `read_plate`. The full, batteries-included pipeline — detection, enhancement,
98
+ grammar-constrained decoding, multi-camera streaming, watchlists and a web
99
+ dashboard — lives in the [Platrix repository](https://github.com/AliAkrami1375/Platrix).
100
+
101
+ ---
102
+
103
+ ## Intended use & limitations
104
+
105
+ - **Intended for** lawful applications such as parking management, access
106
+ control, gate automation and traffic analytics.
107
+ - **Optimised for** standard private Iranian plates. Very low-resolution,
108
+ heavily occluded, or non-standard plates may reduce accuracy.
109
+ - You are responsible for complying with the privacy and surveillance laws that
110
+ apply to your deployment.
111
+
112
+ ---
113
+
114
+ ## Links
115
+
116
+ - **Project & full pipeline:** https://github.com/AliAkrami1375/Platrix
117
+ - **License:** MIT
ocr_cnn.labels.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ "0",
3
+ "1",
4
+ "2",
5
+ "3",
6
+ "4",
7
+ "5",
8
+ "6",
9
+ "7",
10
+ "8",
11
+ "9",
12
+ "ا",
13
+ "ب",
14
+ "ت",
15
+ "ج",
16
+ "د",
17
+ "س",
18
+ "ص",
19
+ "ط",
20
+ "ع",
21
+ "ق",
22
+ "ل",
23
+ "م",
24
+ "ن",
25
+ "ه",
26
+ "و",
27
+ "پ",
28
+ "ژ",
29
+ "ی"
30
+ ]
ocr_cnn.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d573c51cc855a8e080f1f88597477f4fb5a2b9cafa1bb125bd6038e441f5bca
3
+ size 2226402
ocr_crnn.labels.json ADDED
@@ -0,0 +1 @@
 
 
1
+ ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "ا", "ب", "ت", "ث", "ج", "ح", "د", "ز", "س", "ش", "ص", "ط", "ع", "ق", "ل", "م", "ن", "ه", "و", "پ", "ژ", "ی"]
ocr_crnn.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45f8c45f29eb1ee91f6274cb8d9c328da1a2050ea7d8596bae61f4a6b9f9fb1e
3
+ size 10452525
plate_yolo.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a54e475c402e6036bb5c70f1a6ff75179e76098a5c8039bb5d148c0b6421f5c6
3
+ size 12608775