Back to Portfolio

Vehicle Detection with YOLOv11

AI / Computer Vision / Intelligent Transportation2025

A real-time vehicle detection and classification system using YOLOv11 trained on a custom dataset (Cars, Buses, Ambulances, Motorcycles, Trucks). Achieved 87% mAP and 89% precision on test set.

Vehicle Detection with YOLOv11

The Problem

Traffic monitoring and smart transportation systems require accurate and real-time vehicle detection. Traditional methods are often limited by environmental conditions and processing speed. This project aims to build an accurate, efficient, and scalable vehicle detection model using the YOLOv11 architecture for various vehicle types.

Problem illustration

The Solution

A custom YOLOv11 model was trained to detect and classify vehicles such as cars, buses, ambulances, motorcycles, and trucks using the Kaggle Vehicle Detection dataset by Alkan Erturan. The system leverages YOLOv11's anchor-free structure and advanced optimization techniques to achieve high accuracy in real-time inference. Trained for 100 epochs using AdamW optimizer and 640×640 input size, it outperformed YOLOv8n by +4% mAP improvement.

Dataset Collection & Labeling

Used Alkan Erturan's Kaggle dataset containing annotated vehicle images in YOLOv8 format. Adapted dataset for YOLOv11 and structured into train, validation, and test splits.

Model Training

Trained YOLOv11n (nano) for 100 epochs on Google Colab (Tesla T4 GPU) using AdamW optimizer and batch size 16. Implemented OneCycleLR for dynamic learning rate adjustment.

Performance Evaluation

Compared YOLOv11n vs YOLOv8n models. YOLOv11 achieved 87% mAP50, 89% precision, and 85% recall. Results validated via confusion matrices and performance curves.

Architecture

YOLOv11-based vehicle detection system trained on 5 vehicle classes with enhanced accuracy and generalization using PyTorch and Ultralytics.

  • YOLOv11n model (nano) with CSPDarkNet backbone
  • Anchor-free detection and decoupled head for multi-class recognition
  • Loss: Objectness + Classification + Bounding Box regression
  • Optimizer: AdamW with OneCycleLR scheduler
  • Input size: 640×640 pixels

Dataset

Source: Kaggle – Vehicle Detection Dataset by Alkan Erturan

  • Train set: annotated vehicle images (Cars, Buses, Ambulances, Motorcycles, Trucks)
  • Validation set for performance evaluation
  • Test set includes both images and a traffic video clip

Total: ~10,000+ annotated images + 1 evaluation video

Split: 70% training / 20% validation / 10% testing

Image Size: 640×640 pixels

Training Details

  • epochs: 100
  • batchSize: 16
  • optimizer: AdamW
  • learningRate: Dynamic (OneCycleLR)
  • lossFunction: Objectness + Classification + Box regression
  • framework: PyTorch (Ultralytics YOLOv11)
  • hardware: Google Colab (Tesla T4 GPU)

Results & Analysis

Metrics:

  • YOLOv8n: mAP50: 83% | Precision: 86% | Recall: 81%
  • YOLOv11n: mAP50: 87% | Precision: 89% | Recall: 85%

Observations:

  • YOLOv11n achieved +4% mAP improvement over YOLOv8n.
  • Excellent precision and recall balance suitable for traffic monitoring.
  • Model performed reliably across varying lighting and vehicle types.
  • Visualization outputs confirm accurate bounding box placement.

Future Improvements

  • Fine-tune larger YOLOv11 models (yolo11s.pt, yolo11m.pt).
  • Expand dataset to include nighttime and weather variations.
  • Deploy model on embedded systems like Jetson Nano and Coral TPU.
  • Integrate object tracking (DeepSORT, ByteTrack) for vehicle movement analysis.
  • Develop a real-time traffic analysis dashboard using OpenCV.

Technologies Used

Python 3.11PyTorchUltralytics YOLOv11MatplotlibSeabornOpenCVGoogle Colab
Vehicle Detection with YOLOv11 | Abdulrahman Hamdi