Deep-Learning-for-Explainable-Traffic-Anomaly-Detection-in-Dhaka

Deep Learning for Explainable Traffic Anomaly Detection in Dhaka

Overview

This repository contains my research and development work on Deep Learning for Explainable Traffic Anomaly Detection in Dhaka. The project introduces a Multi-Stage Traffic Anomaly Analysis Framework for identifying and analyzing urban traffic congestion, particularly in Dhaka. Originally utilizing Faster R-CNN and DBSCAN, it has been upgraded to state-of-the-art YOLOv9e and YOLOv10l models for enhanced accuracy and efficiency. By integrating object detection, congestion analysis, and explainable AI techniques, TCRD provides actionable insights to improve urban traffic management and planning.

Key Contributions


Project Structure

Implementation Environment

Kaggle is recommended for its GPU support and storage capabilities. The training and detection notebooks are designed for seamless execution in Kaggle.

Models and Datasets

Trained Models

  1. Faster-R-CNN:
    • Original Dataset: Bangladesh Traffic Flow Dataset (DOI: 10.17632/h8bfgtdp2r.2)
    • COCO Formatted Dataset
    • Implementation: dhaka-vehicle-detection-faster-r-cnn.ipynb
      • Model Initialization: Initialize a Faster R-CNN model with pre-trained weights.
      • Output: The model with the lowest average loss (0.3135 from the 17th epoch) is selected for further congestion detection.
    • Weights: Download from Kaggle and place them in the Kaggle input.
    • Training Parameters:
      • Backbone: ResNet-50
      • Optimizer: ADAM
      • Learning Rate: 0.0001
      • Batch Size: 4
      • Epochs: 20
      • Scheduler: StepLR (step size=3, gamma=0.1)
  2. YOLOv9e:
  3. YOLOv10l:

Object Classes

The datasets focus on a congested urban environment with the following object classes:


Previous Congestion Region Detection

Clustering methods were used with the Faster R-CNN model to test if congestion could be detected thoroughly.

Congested Region Detection using DBSCAN

  1. Image Analysis: Used the trained Faster R-CNN model to detect vehicles and people in images.
  2. Information Extraction: Extracted relevant information such as the count of vehicles and people, and potential congested regions.
  3. DBSCAN Clustering: Applied DBSCAN clustering to identify congested regions based on the density of detected objects.
  4. Visualization: Visualized the images with marked congested regions.

DBSCAN Parameters:

Example Output:

{
    "vehicle_count": 23,
    "people_count": 4,
    "congested_regions": [[175.94656, 123.34937, 375.40375, 415.21686]],
    "congestion_count": 1,
    "people_in_congested_areas": 0
}

Congested Region Output

Limitations of the DBSCAN Clustering Method for Congestion Detection

As a matter of fact, congestion region detection was not thorough enough with the DBSCAN clustering method alone, as we can see in the output image. Therefore, new detection methods were needed for accuracy and clearer visualization.


Final Project Workflow

The project workflow is outlined in the following diagram: Methodology

Framework Implementation

Main File

The core implementation of the TCRD framework is in the file: final-tcrd-framework.ipynb. This file integrates the trained YOLOv10l model for:

  1. Object detection.
  2. Region congestion analysis.
  3. Visualization of results.

TCRD Framework Workflow Diagram

Framework Workflow

Sample Results

  1. Object Detection:

    Object Detection

    • Detected: 5 Bikes, 4 Buses, 42 Cars, 14 CNGs, 2 Mini-Trucks
    • Processing Time: 2750.6ms
  2. Blue Bounding Boxes:

    Blue Fill Objects

  3. Masked Local Regions:

    Masked Regions

    • Total Regions: 15
    • Congestion Levels:
      • Region 2: Heavy Congestion with 43 boxes
      • Region 12: Light Congestion with 7 boxes
  4. Explainability with Eigen-CAM:

    Eigen-CAM

    • Detected: 6 Bikes, 4 Buses, 46 Cars, 14 CNGs, 5 Mini-Trucks, 2 People
    • Processing Time: 2450.0ms

Now the Congestion Regions are more accurate and can be differentiated more clearly. They are even classified with detailed analysis and visualization.


How to Use

  1. Set up YOLOv10 Weights:
    • Download best.pt from Google Drive.
    • Place the file locally by creating a new directory yolov10-models/weights/.
    • Zip the folder and upload it to Kaggle as the tcd-yolov10-models dataset.
  2. Run the Framework:
    • Upload final-tcrd-framework.ipynb to your Kaggle workspace.
    • Execute the notebook to process test images and analyze results.

Contribution

Contributions to this repository are welcome! Potential improvements include:


Future Impact

The TCRD framework aims to:

This work seeks to contribute to smarter, more sustainable cities.