1from huggingface_hub import hf_hub_download
2
3# Download model weights
4model_path = hf_hub_download(
5 repo_id="Rattatammanoon/hurricaneod-thai-plate-detector",
6 filename="HurricaneOD_beta.pt"
7)
8
9print(f"Model downloaded to: {model_path}")
1from ultralytics import YOLO
2from PIL import Image
3
4# Load model
5model = YOLO(model_path)
6
7# Detect license plates in image
8results = model.predict(
9 "car_image.jpg",
10 conf=0.25, # Confidence threshold
11 iou=0.45, # IoU threshold for NMS
12 verbose=False
13)
14
15# Process results
16for result in results:
17 boxes = result.boxes
18 for box in boxes:
19 # Get bounding box coordinates
20 coords = box.xyxy[0].tolist()
21 x1, y1, x2, y2 = coords
22 confidence = box.conf[0].item()
23 class_id = box.cls[0].item()
24
25 print(f"Detected plate: [{x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f}] (conf: {confidence:.2f})")
26
27 # Crop license plate region
28 img = Image.open("car_image.jpg")
29 plate_crop = img.crop((x1, y1, x2, y2))
30 plate_crop.save("detected_plate.jpg")
Combine with
Hurricane OCR for complete plate reading:
1from ultralytics import YOLO
2from transformers import AutoProcessor, AutoModelForVision2Seq
3from peft import PeftModel
4from PIL import Image
5import torch
6
7# 1. Load plate detector (HurricaneOD)
8detector = YOLO(model_path)
9
10# 2. Load OCR model (Hurricane OCR)
11ocr_processor = AutoProcessor.from_pretrained("scb10x/typhoon-ocr1.5-2b")
12ocr_base = AutoModelForVision2Seq.from_pretrained(
13 "scb10x/typhoon-ocr1.5-2b",
14 torch_dtype=torch.float16,
15 device_map="auto"
16)
17ocr_model = PeftModel.from_pretrained(ocr_base, "Rattatammanoon/hurricane-ocr-v1")
18ocr_model.eval()
19
20# 3. Complete pipeline: Detection → OCR
21img = Image.open("car_image.jpg")
22
23# Detect plate
24results = detector.predict(img, conf=0.25)
25if results and len(results[0].boxes) > 0:
26 box = results[0].boxes[0]
27 coords = box.xyxy[0].tolist()
28 x1, y1, x2, y2 = coords
29
30 # Crop plate
31 plate_crop = img.crop((x1, y1, x2, y2))
32
33 # Run OCR
34 pixel_values = ocr_processor(images=plate_crop, return_tensors="pt").pixel_values
35 with torch.no_grad():
36 generated_ids = ocr_model.generate(pixel_values, max_length=512)
37 text = ocr_processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
38
39 print(f"📍 Detected plate at: ({x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f})")
40 print(f"📝 OCR Result:\n{text}")
1# Process multiple images efficiently
2images = ["car1.jpg", "car2.jpg", "car3.jpg"]
3results = model.predict(images, conf=0.25, batch=8)
4
5for i, result in enumerate(results):
6 print(f"Image {i+1}: {len(result.boxes)} plates detected")
1# Process video stream
2results = model.predict(
3 source="traffic_video.mp4",
4 conf=0.25,
5 stream=True, # Stream results for memory efficiency
6 save=True # Save annotated video
7)
8
9for result in results:
10 # Process each frame
11 boxes = result.boxes
12 print(f"Frame: {len(boxes)} plates detected")
1# Adjust confidence for your use case
2results = model.predict(
3 "image.jpg",
4 conf=0.5, # Higher = fewer false positives
5 iou=0.45, # NMS threshold
6 max_det=10 # Maximum detections per image
7)
1# Export to ONNX for deployment
2model.export(format="onnx")
3
4# Export to TensorRT for NVIDIA GPUs
5model.export(format="engine")
6
7# Export to CoreML for iOS
8model.export(format="coreml")
9
10# Export to TFLite for mobile
11model.export(format="tflite")
1from ultralytics import YOLO
2
3# Load pretrained model
4model = YOLO("Rattatammanoon/hurricaneod-thai-plate-detector")
5
6# Fine-tune on your dataset
7results = model.train(
8 data="your_data.yaml",
9 epochs=100,
10 imgsz=640,
11 batch=16,
12 device=0 # GPU ID
13)
This model is licensed under
Apache 2.0. See
LICENSE for details.
1@misc{hurricaneod-beta-2025,
2 author = {HurricaneOD Team},
3 title = {HurricaneOD - Thai License Plate Detector},
4 year = {2025},
5 publisher = {Hugging Face},
6 journal = {Hugging Face Model Hub},
7 howpublished = {\url{https://huggingface.co/Rattatammanoon/hurricaneod-thai-plate-detector}}
8}