--- language: - id - en license: agpl-3.0 library_name: ultralytics pipeline_tag: object-detection tags: - object-detection - yolo - yolov8 - ultralytics - pytorch - license-plate-detection - computer-vision - anpr - alpr - smart-city metrics: - mAP50: 0.981 - precision: 0.978 --- # 🚗 OpenPathAI - Vehicle License Plate Detector (YOLOv8n) **OpenPathAI/YOLO-detection-vehcile-plate-2287 License Plate Detection** adalah model Computer Vision ringan berbasis **YOLOv8 Nano** yang di-fine-tune khusus untuk mendeteksi posisi plat nomor kendaraan secara presisi dan cepat (*real-time*). Model ini dirancang untuk diintegrasikan ke dalam sistem **ANPR (Automatic Number Plate Recognition)**, pemantauan lalu lintas CCTV, sistem parkir otomatis, maupun perangkat *edge* berspesifikasi rendah seperti Raspberry Pi atau server VPS berbasis CPU. --- ## 📊 Performa Model (Evaluation Metrics) 1. Grafik utama yang menampilkan penurunan Loss dan peningkatan nilai mAP50 dan Precision ![Grafik Performa Pelatihan](results.png) 2. Menunjukkan seberapa akurat model membedakan antara area plat nomor (license-plate) dan latar belakang (background). ![Akurasi Model](confusion_matrix.png) 3. Grafik kurva keseimbangan antara Precision dan Recall. ![Grafik Kurva](BoxPR_curve.png) ![Grafik Kurva](BoxF1_curve.png) 4. Contoh foto pengujian ![Visualisasi Prediksi Validasi](val_batch0_pred.jpg) --- ## 🚀 Cara Penggunaan (Usage) ### 1. Instalasi Dependency Pastikan Anda sudah menginstal pustaka `ultralytics` dan `huggingface_hub`: ```bash pip install ultralytics huggingface_hub opencv-python ``` --- ### 2. Contoh script Tempel script ini ke terminal anda, dan jalankan, secara otomatis akan mendownload dan menjalankan backend. ```bash from fastapi import FastAPI, File, UploadFile, HTTPException from fastapi.middleware.cors import CORSMiddleware from ultralytics import YOLO from huggingface_hub import hf_hub_download from PIL import Image import io import base64 app = FastAPI(title="OpenPath - License Plate Detection API") # Allow CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Load Model OpenPath print("Loading OpenPath Model from Hugging Face...") MODEL_PATH = hf_hub_download( repo_id="OpenPathAI/YOLO-detection-vehcile-plate-2287", filename="weights/best.pt" ) model = YOLO(MODEL_PATH) print("✅ Model OpenPath Ready!") @app.get("/") def root(): return {"status": "online", "message": "OpenPath License Plate Detection Server Ready"} @app.post("/detect") async def detect_license_plate(file: UploadFile = File(...)): if not file.content_type.startswith("image/"): raise HTTPException(status_code=400, detail="File harus berupa gambar") contents = await file.read() image = Image.open(io.BytesIO(contents)).convert("RGB") results = model(image, conf=0.4) detections = [] for result in results: for box in result.boxes: x1, y1, x2, y2 = map(int, box.xyxy[0].tolist()) confidence = float(box.conf[0]) cropped_plate = image.crop((x1, y1, x2, y2)) buffered = io.BytesIO() cropped_plate.save(buffered, format="JPEG") crop_base64 = base64.b64encode(buffered.getvalue()).decode("utf-8") detections.append({ "confidence": round(confidence, 2), "box": {"x1": x1, "y1": y1, "x2": x2, "y2": y2}, "crop_base64": f"data:image/jpeg;base64,{crop_base64}" }) return { "success": True, "total_plates_found": len(detections), "detections": detections } ```