Skip to content

grootisgroot29/EmobilityHackathon

Repository files navigation

Vehicle Detection, Class Wise Counting System, Tracking and Prediction using YOLO v7

This project focuses on detecting and counting vehicles from CCTV footage across various regions in Bengaluru. The objective is to classify vehicles by type (e.g. Bicycle, Bus, Cars, Two-wheelers, Three-wheelers, LCV, Person, Truck) and predict vehicle counts for the next 30 minutes based on historical data.

Step-by-Step Instructions to create the Docker File

Our docker file link : https://hub.docker.com/repository/docker/megmary/emobility/general

Please do not give an output file as a parameter when you run the docker image, there will be an automatic output_files. Json created in your local file path after the code runs

Prerequisites

Ensure Docker is installed on your machine. You can follow the Docker installation guide for your operating system.

Building the Docker Image

  1. Cloning the repository

git clone https://github.com/NehaJimmy/EmobilityHackathon.git cd EmobilityHackathon

  1. Build the docker image

docker build -t emobility

Running the Docker Container

docker run -it -v (local host path) python3 hac.py input.json

Working with Docker

WhatsApp Image 2024-08-27 at 22 05 03_2a40d903

Find and navigate to container- files

  1. Mount latest.pt

  2. Run git clone and wget

  3. Find path of latest.pt from cloned repository

  4. Copy paste hardcodedct2 into run.py

Names and descriptions of the various notebooks used

1. Traffic_Titans_Training_Notebook.ipynb

The training data file referenced in the code is used to train the YOLOv7 model for vehicle detection and counting. It contains labeled images of vehicles done with the help of Roboflow, which the model uses to learn how to identify and count various vehicle classes in new images or video streams, optimizing for real-time traffic analysis.

2. Traffic_Titans_Evaluation_Notebook.ipynb

The notebook contains code that detects and tracks vehicles in video streams using YOLOv7 and a Centroid Tracker. It counts the vehicles by class, tracks their movement across defined margins, and predicts future vehicle counts using the Prophet model. The results are saved in a CSV file for tracking data and a JSON file for predictions.

3. data.yaml

The data.yaml file you provided seems to describe a dataset used for a machine learning project, likely for object detection or classification. Here's a short description:

  • names: This list defines the categories or classes for the dataset. They include various types of vehicles (Bicycle, Bus, Car, LCV, Three Wheeler, Truck, TwoWheeler) and a general category for individuals (Person).

  • nc: The number of classes in the dataset, which is 10. This includes the 7 vehicle types and the 'Person' class.

  • test: The path to the directory containing test images, located at /content/custom_dataset/test/images.

  • train: The path to the directory containing training images, located at /content/custom_dataset/train/images.

  • val: The path to the directory containing validation images, located at /content/custom_dataset/val/images.

This setup is typically used for organizing data into different sets for training, validating, and testing a model.

4. latest.pt

The latest.pt file generated by YOLOv7 after implementing the specified data.yaml file contains the trained model weights and configuration. This file represents the model’s parameters learned during training on the dataset specified in the data.yaml. The dataset consists of images categorized into 7 classes, including various vehicle types and a 'Person' class. The model was trained using images from the designated training set, validated with the validation set, and evaluated with the test set.

5. .gitattributes

The .gitattributes file configuration you provided specifies how certain file types are handled by Git. Here's a short explanation:

  • pt filter=lfs diff=lfs merge=lfs -text: This line configures Git to use Git LFS (Large File Storage) for files with the .pt extension. filter=lfs tells Git to use LFS to manage these files, diff=lfs and merge=lfs specify that diffs and merges for these files should also use LFS, and -text indicates that Git should not perform any text-related processing (like line-ending conversions) on these files.

  • .mp4 filter=lfs diff=lfs merge=lfs -text: Similar to the .pt configuration, this line sets up Git to use LFS for files with the .mp4 extension. It handles these files with LFS for storage and management, and excludes text processing.

6. README.md

This is the placeholder for the README file that usually contains detailed instructions on how to set up, run, and contribute to the project.

7. hac.py

This script detects, tracks, and predicts vehicle counts using YOLOv7 and a Centroid Tracker. It processes video streams, tracks vehicles, and forecasts future counts with the Prophet model. The results are saved as cumulative counts and predictions in a JSON file.

Requirements.txt

A requirements.txt file includes the necessary libraries for vehicle detection and counting using YOLOv7, Roboflow, centroid tracking, time series prediction with Prophet, and data storage using CSV or JSON files. It also covers dependencies for Docker.

image image

  • matplotlib: A plotting library used to create static, animated, and interactive visualizations in Python.

  • numpy: A fundamental package for numerical computations in Python, particularly with arrays and matrices.

  • opencv-python: A library that provides tools for real-time computer vision, image processing, and machine learning.

  • Pillow: A Python Imaging Library (PIL) fork, used for opening, manipulating, and saving various image file formats.

  • PyYAML: A YAML parser and emitter for Python, used to handle configuration files written in YAML format.

  • requests: A simple HTTP library for making requests and handling responses from web services.

  • scipy: A scientific computing library that builds on numpy, providing tools for optimization, integration, and statistics.

  • torch: A deep learning framework that provides a wide range of tools for building and training neural networks.

  • torchvision: A package containing popular datasets, model architectures, and image transformations for computer vision.

  • tqdm: A library for adding progress bars to loops and tasks in Python, enhancing user feedback.

  • protobuf: A mechanism for serializing structured data, used for efficient data exchange between systems.

  • tensorboard: A tool for visualizing training metrics and debugging deep learning models.

  • pandas: A powerful data analysis and manipulation library, providing data structures like DataFrames.

  • seaborn: A statistical data visualization library based on matplotlib, used for making complex plots simpler.

  • roboflow: An SDK for integrating with the Roboflow platform, used for managing and deploying computer vision models.

  • scikit-learn: A machine learning library providing tools for data mining, analysis, and building predictive models.

  • prophet: A time series forecasting library designed for handling daily seasonality and holidays.

  • csv file: A standard format for storing tabular data, used for reading and writing data in plain text.

  • json file: A lightweight data-interchange format that's easy for humans to read and write, and machines to parse.

  • docker: A platform for developing, shipping, and running applications inside lightweight, portable containers.

  • ipython: An interactive Python shell with advanced features for introspection, rich media, and embedded code.

  • psutil: A library for retrieving information on system utilization (CPU, memory, disks, network, etc.) in Python.

  • thop: A tool for profiling deep learning models, estimating their FLOPs (floating point operations) and parameters.

Open source models used

YOLO v7: https://github.com/WongKinYiu/yolov7

Roboflow: https://roboflow.com/

Prophet: https://facebook.github.io/prophet/

Docker: https://docs.docker.com/build/

System Requirements

To run the code, the following system specifications are required:

GPU: NVIDIA GPU with at least 8GB of VRAM (e.g., NVIDIA RTX 3080)

RAM: Minimum 16GB

CPU: Quad-core Intel or AMD processor with 2.5 GHz or higher

Disk Space: Minimum 50GB of free space

Operating System: Ubuntu 20.04 LTS or Windows 10

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •