🚗 Iranian License Plate & Character Detection (YOLO26)
This repository provides two high-accuracy YOLO26 models trained to detect Iranian vehicle license plates and read their characters:
- Plate Detector (
yolo26n): Detects vehicle license plates in traffic / street scene images. - Character Detector (
yolo26s): Fine-grained character recognition model for cropped plates supporting 30 classes (digits and Persian letters).
Both PyTorch (.pt) and ONNX (.onnx) weights are available in this repository:
plate_detector/best.pt&plate_detector/best.onnxplate_char_reader/best.pt&plate_char_reader/best.onnx
📊 Benchmark Metrics
Evaluated on test sets:
| Model | Architecture | Epochs | Image Size | Precision | Recall | mAP@50 | mAP@50-95 |
|---|---|---|---|---|---|---|---|
| Plate Detector | yolo26n | 144 | 800×800 | 99.52% | 99.65% | 99.50% | 75.28% |
| Character Detector | yolo26s | 94 | 416×416 | 98.26% | 98.37% | 99.02% | 77.58% |
🔤 Supported Character Classes (30 Total)
The character recognition model distinguishes 30 fine-grained classes:
1. Digits (10 Classes)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (Persian digits ۰ تا ۹)
2. Persian Letter Codes (20 Classes)
| Class Label | Persian Letter | Typical Use Case |
|---|---|---|
AA | الف (Alef) | Governmental / Official |
AW | ع (Ayn / Ein) | Public transport (Taxi / Van) |
BB | ب (Be) | Private vehicles |
DD | د (Dal) | Private vehicles |
GH | ق (Ghaf) | Private vehicles |
HH | ه (He) | Private vehicles |
JJ | ج (Jim) | Military / Police / Private |
LL | ل (Lam) | Transit / Private |
MM | م (Mim) | Private vehicles |
NN | ن (Nun) | Private vehicles |
PD | پ (Pe - Diplo) | Diplomatic / Service |
PP | پ (Pe - Police) | Iranian Police (NAJA) |
SD | ص (Sad) | Private vehicles |
SH | ش (Shin) | Military (Army) |
SS | س (Sin) | Private vehicles |
TA | ط (Ta) | Private vehicles |
TT | ت (Te) | Taxi |
VV | و (Vav) | Private vehicles |
YY | ی (Ye) | Private vehicles |
ZZ | ژ (Zhe) | Accessible / Disabled vehicles |
📦 Datasets
The models were trained on datasets sourced from Roboflow Universe:
-
Plate Detector Dataset:
- Workspace:
zahra-bubwt - Project:
drhoseinpur(Version 1)
- Workspace:
-
Character Detector Dataset:
- Workspace:
dummy-ws - Project:
iranian-plate-character-finder(Version 3) - License: CC BY 4.0
- Workspace:
🚀 How to Use
1. Installation
pip install ultralytics huggingface_hub opencv-python numpy
2. Standalone Plate Detection
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
# Download weights from Hugging Face
model_path = hf_hub_download(
repo_id="nimazerobit/iranian-license-plate-yolo26",
filename="plate_detector/best.pt"
)
# Load model and run inference
plate_detector = YOLO(model_path)
results = plate_detector("car.jpg", conf=0.25)
# Show or save detections
for r in results:
r.show() # Display annotated image
3. Standalone Character Detection (on a Cropped Plate)
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
# Download character detector weights
model_path = hf_hub_download(
repo_id="nimazerobit/iranian-license-plate-yolo26",
filename="plate_char_reader/best.pt"
)
char_detector = YOLO(model_path)
results = char_detector("plate_crop.jpg", conf=0.25)
# Sort detected characters from left to right by their X-coordinate
detections = []
for box in results[0].boxes:
x1, y1, x2, y2 = box.xyxy[0].tolist()
cls_id = int(box.cls[0])
char_name = results[0].names[cls_id]
detections.append((x1, char_name))
# Sort left-to-right
detections.sort(key=lambda item: item[0])
plate_text = "".join([d[1] for d in detections])
print(f"Recognized Plate: {plate_text}")
4. Complete End-to-End Pipeline (Car Image ➔ Plate Text)
import cv2
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
REPO_ID = "nimazerobit/iranian-license-plate-yolo26"
# 1. Download both models
plate_model_file = hf_hub_download(repo_id=REPO_ID, filename="plate_detector/best.pt")
char_model_file = hf_hub_download(repo_id=REPO_ID, filename="plate_char_reader/best.pt")
plate_model = YOLO(plate_model_file)
char_model = YOLO(char_model_file)
# 2. Read input vehicle image
image_path = "vehicle.jpg"
image = cv2.imread(image_path)
# 3. Detect plates
plate_results = plate_model(image_path, conf=0.3)[0]
for idx, box in enumerate(plate_results.boxes):
x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
plate_crop = image[y1:y2, x1:x2]
if plate_crop.size == 0:
continue
# 4. Detect characters in the plate crop
char_results = char_model(plate_crop, conf=0.25)[0]
# Collect and sort characters left-to-right
chars = []
for c_box in char_results.boxes:
cx1, _, _, _ = c_box.xyxy[0].tolist()
class_name = char_results.names[int(c_box.cls[0])]
chars.append((cx1, class_name))
chars.sort(key=lambda x: x[0])
plate_string = "".join([c[1] for c in chars])
print(f"Detected Plate #{idx + 1}: {plate_string}")
5. Using the ONNX Weights
You can also run inference with onnxruntime without needing PyTorch:
import onnxruntime as ort
from huggingface_hub import hf_hub_download
onnx_path = hf_hub_download(
repo_id="nimazerobit/iranian-license-plate-yolo26",
filename="plate_detector/best.onnx"
)
session = ort.InferenceSession(onnx_path, providers=["CPUExecutionProvider"])
# Run inference with session.run(...)
📜 Citation & License
- License: CC BY 4.0
- If you use these models or datasets in your research or application, please attribute the Roboflow dataset authors and repository maintainers.