Internship Repoort 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

AI-Powered Traffic Signals

AN INTERNSHIP REPORT

Submitted by
AASHIK H

in partial fulfillment for the award of the degree of


BACHELOR OF TECHNOLOGY
in
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

DECEMBER 2024
AI-Powered Traffic Signals

AN INTERNSHIP REPORT

Submitted by
AASHIK H

in partial fulfillment for the award of the degree of


BACHELOR OF TECHNOLOGY
in
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

DECEMBER 2024

I
BONAFIDE CERTIFICATE

Certified that this Internship report “AI-Powered Traffic Signals ” is the bonafide work of
“AASHIK (210171601001)” who carried out the internship under my supervision.
Certified further, that to the best of our knowledge the work reported herein does not
form part of any other internship report or dissertation on the basis of which a degree or
award was conferred on an earlier occasion on this or any other candidate.

SIGNATURE

Dr. J.BRINDHA MERIN


Assistant Professor (Senior Grade)
Department of CSE
B. S. Abdur Rahman Crescent
Institute of Science and Technology
Vandalur, Chennai - 600048

II
INTERNSHIP CERTIFICATE

III
VIVA VOCE EXAMINATION

The viva voce examination of the project work titled “AI-POWERED TRAFFIC
SIGNALS”, submitted by AASHIK H (210171601001) is held
on ________________

INTERNAL EXAMINER

IV
ACKNOWLEDGEMENT

I sincerely express my heartfelt gratitude to Prof. Dr. T. MURUGESAN, Vice


chancellor and Dr. N. THAJUDDIN, Pro-Vice Chancellor, B.S. Abdur Rahman
Crescent Institute of Science and Technology, for providing me an environment
to carry out my internship successfully.

I sincerely thank Dr. N. RAJA HUSSAIN, Registrar, for furnishing every


essential facility for doing my internship.
I thank Dr. SHARMILA SANKAR, Dean, School of Computer Information and
Mathematical Sciences for her motivation and support.

I thank Dr. W. AISHA BANU, Professor and Head, Department of Computer


Science and Engineering, for providing strong oversight of vision, strategic
direction and valuable suggestions.

I obliged my class advisor Dr. J. BRINDHA MERIN, Assistant Professor(Sr. Gr.),


Department of Computer Science and Engineering for her professional
guidance and continued assistance throughout the internship period.

I thank Mr.Lokesh, project manager, Ideassion Technology Solutions for his


guidance and encouragement throughout the internship period and without his
guidance this project would not have been a successful one.

I thank all the Faculty members and the System Staff of the Department of
Computer Science and Engineering for their valuable support and assistance at
various stages of internship completion.

( AASHIK H )

V
TABLE OF CONTENTS

CHAPTER NO. TITLE PAGE NO.

LIST OF ABBREVIATIONS vii


LIST OF FIGURES viii
1 COMPANY OVERVIEW 1
1.1 Overview 1
1.2 Company Website 1
1.3 Company Logo 1
2 ROLE AND RESPONSIBILITY 2
2.1 ROLE 2
2.2 RESPONSIBILITY 2
3 3
SYSTEM ANALYSIS
3.1 3
Project Objective
3.2 Tools and Technologies 3
3.3 Expected Outcome 3
4 SYSTEM SPECIFICATION 4
4.1 Hardware 4
4.2 Software 5
5 DESIGN AND IMPLEMENTATION 6
5.1 System Architecture 6
5.2 Algorithm Used 10
5.3 Loss Function and Optimization Strategy 15
6 RESULT AND ANALYSIS 16
7 CONCLUSION 18
REFERENCES 19
APPENDIX 20
A1 - Source Code 20
A2 – Technical Biography 26

VI
LIST OF ABBREVIATIONS

YOLOv5 You Only Look Once version 5

ML Machine Learning

ANN Artificial Neural Networks

CNN Convolutional Neural Network

RNN Recurrent Neural Network

LSTM Long Short-Term Memory

mAP mean Average Precision

IoU Intersection over Union

SGD Stochastic Gradient Descent

ROI Region of Interest

CSP Cross-Stage Partial

SPPF Spatial Pyramid Pooling

mAP@50 mean Average Precision at 50% Intersection over


Union threshold

mAP@50-95 mean Average Precision averaged across IoU


thresholds from 50% to 95%

nc number of classes

LR Learning Rate

VII
LIST OF FIGURES

FIGURE NO. TITLE PAGE.NO

1.1 Company Logo 1

5.1 Data Flow 8

5.2 Architecture of YOLOv5 10

6.1 Detection of different vehicles in traffic 16

6.2 Detection of different vehicles in traffic 17

VIII
1. COMPANY OVERVIEW
Ideassion Technology Solutions is an innovative IT company focused on delivering
advanced technology solutions across diverse domains like software development, AI,
cloud computing, data science, and blockchain.
1.1 Overview
The company is committed to transforming businesses by providing tailored solutions in
key areas such as:

 Software Development and AI Tools: Ideassion specializes in creating scalable


applications and AI-powered tools that enhance automation and analytics,
enabling businesses to optimize operations and decision-making.
 Cloud Computing and Data Solutions: It offers efficient cloud migration
strategies and advanced data solutions that convert raw data into actionable
insights for improved business outcomes.
 Blockchain Expertise: Leveraging blockchain technology, Ideassion enhances
security, transparency, and efficiency for clients across industries such as
healthcare, finance, retail, and education.
 Global Reach and Digital Transformation: Ideassion supports businesses
worldwide in navigating their digital transformation journey through high-quality,
customized solutions.

1.2 Company website


The URL of the website Ideassion Technology Solutions is given below,

Website URL: https://ideassion.com

1.3 Comapany Logo


The logo of the Ideassion Technology Solutions is given below, in Fig. 1.1.

Fig 1.1: Comapany Logo

1
2. ROLE AND RESPONSIBILITY

Role and Responsibility define an individual's position and duties within a team or
project. The role specifies their purpose, such as a data scientist, while responsibilities
outline tasks like optimizing performance or managing deployments. Together, they
ensure clarity, accountability, and alignment with project goals.

2.1 Role
· Role: Machine Learning Intern
· Mentor: Mr. Lokesh, Python Developer
· Team: Python Development Team

2.2 Responsibility
Topic Study: Conducted in-depth research on various machine learning and data science
topics, including supervised and unsupervised learning, feature selection, model evaluation
techniques, and deep learning.

Model Implementation: Implemented and tested different machine learning algorithms,


such as linear regression, decision trees, random forests, and neural networks, to solve
real-world problems.

Pipeline Building: Built and optimized machine learning pipelines for efficient data
preprocessing, model training, and evaluation, ensuring streamlined workflows for
model deployment.

Daily Updates: Sent detailed daily updates to the mentor and team, highlighting tasks
completed, challenges faced, and progress made, fostering transparent communication
and enabling timely feedback.

Project Development: Contributed to the development and integration of machine


learning models into ongoing projects, ensuring the models were practical, optimized,
and aligned with project goals.

Skill Development: Focused on enhancing technical skills in Python, data handling,


and model evaluation, while also refining soft skills like problem-solving and effective
communication.

2
3. SYSTEM ANALYSIS
System Analysis delves into the design, functionality, and technical implementation of
the Traffic Light Management System, focusing on its ability to dynamically manage
urban traffic using artificial intelligence and real-time data processing. The system aims
to optimize traffic flow, reduce delays, and provide actionable insights for long-term
urban planning.

3.1 Project Objective


The Traffic Light Management System is designed to revolutionize urban mobility by
leveraging AI to adjust signal timings dynamically. Its objectives include minimizing
congestion, enhancing traffic efficiency, and providing sustainable solutions for urban
challenges. The system’s ability to predict traffic patterns and adapt in real-time ensures
continuous improvement in traffic management, catering to the growing needs of
urbanization.

3.2 Tools and Technologies


The Traffic Light Management System utilizes cutting-edge technologies for its
implementation. YOLOv5 serves as the backbone for vehicle detection, ensuring high
accuracy even in challenging conditions like low light or adverse weather. Python
libraries are used for data processing, machine learning, and system automation.
Cloud-based solutions support data storage and scalability, while interactive
dashboards built using visualization tools provide a user-friendly interface for real-time
monitoring. IoT-enabled devices, such as smart cameras and sensors, ensure seamless
data collection and system integration.

3.3 Expected Outcomes


The implementation of this system is expected to reduce traffic congestion significantly,
ensuring faster vehicle clearance at intersections. By reducing idle time, the system
promotes fuel efficiency and lowers carbon emissions, contributing to environmental
sustainability. Travelers will experience shorter commute times and smoother traffic
flows, enhancing their overall journey experience. Additionally, the system will enable
data-driven decision-making for city planners by providing detailed traffic insights,
helping them design future-proof traffic infrastructure and strategies.

3
4. SYSTEM SPECIFICATION
The system is designed to handle computationally intensive tasks such as real-time
vehicle detection and model training. It utilizes a combination of local and cloud-based
environments for development and training. The local development machine is
equipped with high-performance hardware, while Google Colab provides additional
computational power for large-scale deep learning experiments. The system ensures
efficient processing of data, training of models, and adaptation to real-time traffic
scenarios.

4.1 Hardware

The local development machine used for development was the ASUS Strix G17, a high-
performance laptop designed for computationally intensive tasks. It provided the
necessary power for data processing and machine learning workflows, ensuring smooth
execution of demanding processes.

 Processor: AMD Ryzen 7 , a multi-core processor that delivers fast processing


speeds, essential for handling complex computations and ensuring quick execution
of machine learning tasks and data processing workflows.
 GPU: NVIDIA GeForce GTX 1650 ,a mid-range GPU that accelerates graphics
rendering and data visualization tasks, enabling efficient model testing and
prototype deployment, especially for object detection tasks.
 RAM: 8GB Sufficient for handling moderate-size datasets and performing data
preprocessing, and machine learning tasks.

For computationally intensive tasks, Google Colab was utilized, offering flexibility and
power for large-scale deep learning experiments.

 GPU: NVIDIA Tesla K80/T4, cloud-based GPUs that provide exceptional


performance, particularly useful for accelerating deep learning model training,
reducing processing time, and increasing throughput during large-scale training
tasks.
 Memory: Up to 25GB of system RAM ,provides the capacity to handle large
datasets and supports high-dimensional model computations, ensuring that the
machine learning models run efficiently without running into memory limitations.

4
4.2 Software
Operating System:
The local development environment runs on Windows 10/11, which provides a stable
and user-friendly interface for development tasks and supports a wide range of tools
and frameworks required for machine learning projects.

Programming Environment:

 Anaconda: The Jupyter Notebook interface, accessed via the Anaconda


distribution, served as the primary development platform. It simplifies
dependency management and allows seamless integration of various libraries.
 Python Version 3.8: Chosen for its compatibility with the latest machine learning
libraries and frameworks.

Libraries and Frameworks:


To ensure effective model training, data processing, and visualization, several powerful
libraries and frameworks were employed:

 TensorFlow 2.3: Used for building and training neural networks, TensorFlow
offers extensive capabilities for deep learning tasks, including object detection.
 YOLOv5: The object detection model used in this project for real-time vehicle
detection and traffic flow analysis.

The system utilizes several additional libraries to enhance its functionality. Pandas
and Numpy are used for data manipulation and numerical computations, allowing
efficient handling of large datasets and performing mathematical operations. Matplotlib
plays a key role in data visualization, enabling the creation of graphs and plots to
visualize trends in traffic flow and other important metrics. OpenCV is employed for
image processing and managing video streams, essential for detecting vehicles and
analyzing traffic in real-time. Additionally, scikit-learn is integrated to implement
machine learning models, supporting tasks such as clustering and time series
analysis, further optimizing the traffic management system.

5
5. DESIGN AND IMPLEMENTATION
The design and implementation phase focuses on creating an intelligent system for real-
time traffic management, incorporating AI-driven analysis to optimize signal timings
effectively.

5.1 SYSTEM ARCHITECTURE

The traffic signal regulation system is structured with a robust and intelligent design to
ensure smooth and efficient traffic management at intersections. The architecture
integrates multiple components and processes to analyze traffic, calculate density, and
optimize signal timings in real-time.

The system leverages camera feeds from intersections to monitor traffic flow across
four directions: North, East, South, and West. These camera feeds are processed using
advanced computer vision techniques to detect and count vehicles in each direction.
This real-time monitoring ensures accurate data collection, forming the basis for further
analysis.

A traffic density calculation module processes the vehicle counts to determine


congestion levels for each direction. This module uses machine learning models, such
as object detection algorithms (e.g., YOLOv5), to identify and classify vehicles. The
calculated density is then used to dynamically adjust signal timings.

The signal timing adjustment system is a core component of the architecture. It


modifies the duration of green, yellow, and red signals based on traffic conditions. For
example, directions with heavier traffic are allocated longer green signals to reduce
congestion effectively. Conversely, lighter traffic areas have shorter green signals to
optimize the overall traffic flow.

The system includes a data storage and analysis unit where all real-time traffic data
and adjusted signal timings are logged. This information is crucial for peak-time
analysis, enabling traffic authorities to identify high-congestion periods and develop
strategies for better traffic management in the future.

6
Fig 5.1: Data flow from image capture to signal adjustment

The traffic management system operates through a series of interconnected steps, each
designed to ensure efficient traffic flow by dynamically adjusting signal timings based on
real-time vehicle data. Below is a detailed breakdown of the process:

1. Capture Images

The process begins with cameras strategically placed at intersections to capture images
or live video feeds from all four directions: North, East, South, and West. These
cameras provide a continuous stream of high-quality visual data, forming the foundation
of the system. The high-resolution images ensure accurate detection of vehicles,
including smaller ones like motorcycles and bicycles. This real-time capture allows the
system to assess current traffic conditions as they occur.

7
2. Preprocess Images

Once the images are captured, they are passed through a preprocessing stage to
enhance their quality and make them suitable for analysis. This involves resizing the
images to a standard resolution that the detection model can process efficiently. Noise
reduction techniques are applied to filter out unnecessary elements, such as dust or
glare, ensuring that vehicles are clearly visible. Additionally, contrast adjustment
improves the clarity of the images, making vehicle outlines more distinguishable. These
preprocessing steps are essential for ensuring consistent and accurate results from the
detection model.

3. Vehicle Detection

After preprocessing, the refined images are analyzed using a pre-trained object
detection model, such as YOLO (You Only Look Once). This model scans the images to
identify and classify vehicles, recognizing different types such as cars, buses, trucks,
and two-wheelers. YOLO's speed and accuracy make it ideal for real-time applications,
allowing the system to process multiple images quickly and detect vehicles even in
challenging scenarios, such as crowded intersections or dim lighting conditions. The
model outputs bounding boxes and labels for each detected vehicle, providing a clear
picture of traffic density in every direction.

4. Traffic Estimation

The detected vehicles are counted and aggregated to estimate the traffic density for
each direction. This estimation provides a quantitative understanding of how crowded
each lane is. For instance, a lane with only a few vehicles may be categorized as having
low traffic, while a lane with a significant number of vehicles may be identified as highly
congested. The system uses these density levels to prioritize signal timings, ensuring
that heavily congested directions receive longer green light durations while less
crowded lanes have shorter waiting times.

8
5. Calculate Signal Timing

Using the traffic density estimates, the system calculates the optimal green light
duration for each direction. This calculation is based on predefined thresholds, ensuring
fairness and efficiency. For example, a direction with minimal traffic might be assigned a
green light duration of 15 seconds, while a heavily congested direction could receive 45
seconds. These dynamic adjustments allow the system to clear traffic more effectively,
reducing overall waiting times and minimizing the risk of gridlocks at busy intersections.

6. Store the Timings

The calculated signal timings are recorded in an Excel sheet or a database for future
analysis. Each entry includes the green light duration, the direction it applies to, and a
timestamp. This stored data is invaluable for understanding long-term traffic patterns,
enabling authorities to make informed decisions about infrastructure development and
traffic management strategies. Additionally, having this historical data allows for periodic
reviews and updates to the system's algorithms to improve efficiency further.

7. Update Signals

The calculated signal timings are implemented in real-time by updating the traffic signal
control system. This ensures that the signal durations are adjusted dynamically without
manual intervention. The seamless integration of the signal adjustments into the traffic
control infrastructure enables a smooth and consistent flow of vehicles, enhancing the
overall commuting experience.

8. Peak Time Estimation

Over time, the system uses the stored signal timing data to analyze traffic patterns and
identify peak hours. This analysis highlights specific times of the day, such as morning
and evening rush hours, when traffic volumes are consistently high. By understanding
these peak periods, authorities can devise long-term strategies to manage congestion
more effectively, such as redesigning road layouts, optimizing signal configurations, or
implementing traffic diversion plans. Peak time analysis also helps in anticipating future
traffic trends and planning infrastructure improvements accordingly.

9
5.2 ALGORITHM USED

YOLO (You Only Look Once):

Fig 5.2: YOLOv5 model architecture for object detection

The YOLOv5 architecture is designed to optimize real-time object detection while


maintaining high accuracy and computational efficiency. It is composed of three primary
components: the Backbone, PANet (Path Aggregation Network), and Output Layer.
These components are carefully structured to allow the model to handle complex tasks
like detecting multiple objects in various positions and sizes with minimal computational
cost. Let’s dive deeper into the specifics of each component:

1. Backbone

The Backbone is essential for extracting feature maps from the input image, which
represent important visual information about objects in the image. This is achieved
through a series of BottleNeckCSP layers, which utilize the Cross-Stage Partial (CSP)
strategy. The idea behind CSP is to split the feature maps at an early stage and later
merge them, which reduces the number of computational resources needed, thereby
enhancing efficiency.

10
Another critical feature of the Backbone is the Spatial Pyramid Pooling (SPP) block.
The SPP enhances the network’s ability to detect objects of different sizes by pooling
information at different scales. This enables the model to capture both local details (for
small objects) and broader context (for large objects). With the SPP, YOLOv5 can adapt
to various object sizes within an image, making it more robust across different detection
tasks. The ability to aggregate global context helps YOLOv5 outperform traditional
object detection models when dealing with objects of varying scales.

2. PANet (Path Aggregation Network)

The PANet plays a crucial role in improving the quality of feature maps produced by the
Backbone. It is designed to enhance the flow of information throughout the network,
ensuring that features from different layers are effectively merged. PANet accomplishes
this by performing upsampling from higher-resolution feature maps and concatenating
them with lower-level feature maps. This process enriches the feature maps, providing
more detailed and accurate object predictions.

One of the key innovations of PANet is its use of Conv1x1 layers for dimensionality
reduction before concatenating feature maps. This reduces the size of the feature maps,
which makes the network more efficient, while still allowing for the fusion of important
high-level and low-level features. This combination of fine-grained details from lower
layers with semantic information from higher layers allows the model to better capture
object shapes and positions, resulting in improved detection accuracy.

3. Output Layer

The Output Layer is where the model makes its predictions. It processes the feature
maps from the PANet and predicts bounding boxes, class labels, and confidence
scores for each detected object. YOLOv5 uses three detection heads, each
responsible for detecting objects at different scales. This allows the model to efficiently
detect small, medium, and large objects in a single pass.

11
The detection heads process the feature maps at different resolutions, ensuring that
objects of various sizes are detected. The Conv1x1 layers at the detection heads refine
the predictions, ensuring that the bounding boxes are accurately placed and scaled
according to the objects in the image. The objectness score generated by these heads
indicates the likelihood that a given bounding box contains an object, allowing the model
to discard irrelevant boxes and focus on the most probable detections.

Key Characteristics and Benefits:

Efficiency and Speed: By using advanced techniques like BottleNeckCSP, SPP, and
Conv1x1 layers, YOLOv5 achieves a high level of computational efficiency. This
enables the model to run in real-time without compromising on detection accuracy,
making it ideal for applications that require fast decision-making, such as surveillance
systems, autonomous vehicles, and robotics.

Multi-Scale Detection: The use of multiple detection heads and feature fusion across
layers allows YOLOv5 to detect objects at varying scales. This makes it highly versatile,
able to detect both small objects (e.g., pedestrians) and large objects (e.g., vehicles)
within the same image.

Robustness: YOLOv5’s ability to handle objects of different sizes and detect them with
high precision makes it more robust compared to earlier object detection models. The
architecture is designed to adapt to different environments, lighting conditions, and
cluttered backgrounds, which are common challenges in real-world scenarios.

Real-time Processing: The architecture is optimized for speed, enabling the model to
process images in real-time. This is particularly important in applications where timely
decision-making is critical, such as in autonomous driving or real-time video surveillance.

High Detection Accuracy: YOLOv5’s architecture maintains a balance between speed


and accuracy. By using advanced feature extraction (Backbone), efficient feature fusion
(PANet), and precise output prediction (Output Layer), the model achieves high
detection accuracy, even in complex environments.

12
Scalability: YOLOv5 is scalable and can be adapted to different tasks, from detecting a
single class of objects to multiple classes, thanks to its flexible architecture. This
scalability allows it to be applied in a variety of industries, including security, healthcare,
retail, and transportation.

Summary:

The YOLOv5 model architecture for this project is based on the YOLOv5s base model,
which is designed to strike a balance between speed and accuracy. This model is
specifically adapted to work with 7 custom classes, making it suitable for detecting a
range of objects relevant to the task, such as cars, buses, trucks, and more. The
number of custom classes is specified as nc=7, where each class represents a different
type of object in the traffic signal system.

The model consists of 214 layers with a total of 7,038,508 parameters and 16.0
GFLOPs (Giga Floating Point Operations Per Second). These specifications reflect the
model's complexity, with a relatively high number of parameters that help capture
intricate features of the input data, while maintaining a balance with computational
efficiency. The 214 layers include various types of layers that work together to extract
meaningful features from input images.Several specialized modules within YOLOv5
contribute to the model’s performance follows

models.common.Conv: This module is used to create convolutional layers that


perform feature extraction from the input image. Convolutional layers help detect
patterns and structures such as edges, textures, and shapes, which are critical for
identifying objects.

models.common.C3: This module implements CSP (Cross-Stage Partial) Bottleneck


layers, a key innovation in YOLOv5 that enhances both feature extraction and
computational efficiency. CSP Bottlenecks help reduce the computational cost by
dividing the feature maps and merging them later, which allows the model to process
data more efficiently while preserving accuracy.

13
models.common.SPPF: This module facilitates Spatial Pyramid Pooling (SPP), which
aggregates contextual information across multiple scales. SPP allows the model to
handle objects of varying sizes by pooling features at different spatial resolutions. This
feature is especially beneficial for real-time object detection in dynamic environments,
where object size and scale can vary significantly.

models.yolo.Detect: The detection module is tailored specifically to work with the


defined classes in the dataset. It predicts bounding boxes, class labels, and confidence
scores for each object detected in the image. The detection head utilizes auto-anchor-
generated anchor boxes, which dynamically adjust to the specific object sizes in the
dataset. This makes the model more flexible and accurate when handling various
objects.

To ensure optimal performance, the model was trained and validated with 256x256
resolution images. This resolution was chosen as it strikes a balance between retaining
sufficient detail and reducing processing time, which is crucial for real-time applications.
Additionally, auto-anchor-generated anchor boxes were used during training, which
allows the model to adapt to varying object sizes in the dataset, improving accuracy and
robustness.

During training, special attention was given to detecting very small objects. A warning
system is in place to alert if objects smaller than 3 pixels are detected, as these objects
can be difficult to detect reliably in real-world scenarios. This feature helps refine the
model’s accuracy, ensuring it performs optimally for practical use cases such as traffic
monitoring, where small vehicles or objects may need to be identified accurately.

14
5.3 LOSS FUNCTION AND OPTIMIZATION STRATEGY
· Hyperparameters:

 Learning rate (lr0): 0.01


 Final learning rate fraction (lrf): 0.01
 Momentum: 0.937
 Box loss gain: 0.05
 Class loss gain: 0.5
 Object loss gain: 1.0
 Flip augmentation: 50%

The Loss Functions used in the YOLOv5 model for training play a crucial role in
guiding the optimization process. These include Box Loss, Objectness Loss, and
Classification Loss. Box Loss calculates the error between the predicted bounding box
and the ground truth bounding box, ensuring that the model accurately predicts the
location and size of the detected objects. Objectness Loss focuses on predicting
whether an object is present in a grid cell, allowing the model to differentiate between
empty areas and those containing objects. Finally, Classification Loss is used to assess
how well the model assigns the correct class label to detected objects, ensuring that
objects are classified correctly based on the learned features.

In terms of Training Settings, the model was trained for 50 epochs, which is the
number of times the entire dataset is passed through the network. This allows the model
to learn the underlying patterns in the data and improve its predictions over time. The
batch size was set to 16, meaning that 16 images are processed simultaneously in one
training step, which helps improve the training efficiency. Additionally, the dataloader
workers were configured to 2, meaning two CPU threads are used to load the training
data, ensuring that the model can efficiently handle and process the data during training.
These settings help in fine-tuning the model to achieve high accuracy while maintaining
a balance between computational efficiency and performance.

Optimizer: Stochastic Gradient Descent (SGD)

15
6. RESULT AND ANALYSIS

The YOLOv5 model achieved notable results after 50 epochs of training. A precision
score of 0.700 indicates that 70% of the detections made by the model were correct,
while a recall of 0.729 demonstrates that the model successfully identified
approximately 73% of all objects in the dataset. The mean Average Precision (mAP) at
an IoU threshold of 0.50, a widely used metric for object detection, was recorded at
0.712, signifying that the model accurately detected objects with an average accuracy of
71.2%. Additionally, the mAP across IoU thresholds from 0.50 to 0.95 (in increments of
0.05) was 0.401, highlighting the model's capability to detect objects under stricter and
more comprehensive evaluation criteria.

Sample Output:

Fig 6.1: Detection of different vehicles in traffic

16
Fig 6.2: Detection of different vehicles in traffic

The YOLOv5 model demonstrated strong performance, effectively balancing accuracy


and efficiency in object detection tasks. Its robust architecture and adaptive training
settings enabled it to handle complex scenarios with reliability. The results indicate that
the model is well-suited for real-time applications, showcasing consistent detection
capabilities. Overall, the YOLOv5 model proves to be an efficient solution for practical
object detection use cases.

17
7. CONCLUSION

In conclusion, the development of the traffic signal regulation system leveraging


YOLOv5 marks a significant advancement in intelligent traffic management. The system
has successfully demonstrated its ability to dynamically adjust traffic signal timings in
real-time, responding effectively to varying traffic conditions. By training the model for
50 epochs on a custom dataset of seven vehicle classes, the project achieved
commendable results, particularly in accurately detecting vehicles such as cars, buses,
and two-wheelers. This highlights the potential of AI-driven solutions in mitigating urban
traffic congestion and improving commute efficiency.

However, challenges persist, including varying lighting conditions, weather changes,


occluded vehicles, and difficulties in detecting smaller objects. Addressing these
challenges will require the integration of more sophisticated techniques, such as
advanced data augmentation, multi-modal sensor inputs, and enhanced feature
extraction models. Additionally, refining hyperparameters, expanding the dataset to
include diverse traffic environments, and conducting rigorous real-world testing will be
essential steps.

Moving forward, this system can be scaled to incorporate adaptive learning capabilities,
edge computing for faster processing, and predictive analytics to anticipate and manage
peak traffic periods. These enhancements could significantly contribute to creating not
only smarter but also more sustainable traffic management systems, reducing
environmental impacts and enhancing urban mobility. This project serves as a
testament to the transformative role of AI in reshaping traditional infrastructure into
future-ready solutions.

18
REFERENCES

1. Shaygan, M., Meese, C., Li, W., Zhao, X. (George), & Nejad, M. (2023). “Traffic
prediction using artificial intelligence”: Review of recent advances and emerging
opportunities. Journal of Intelligent Transportation Systems, 27(3), 457-470.
2. Ultralytics YOLO Documentation. Ultralytics
3. Google Colab Documentation for Object Detection Models. Google Developers.
4. Kumar, R., & Singh, P. (2020). Intelligent Traffic Signal Control System Using
Machine Learning. International Journal of Engineering & Technology, 9(4), 76-81.
5. Lee, J., & Park, H. (2019). Smart Traffic Control System with IoT and Machine
Learning. Journal of Advanced Transportation, 8(3), 211-223.
6. Verma, R., & Gupta, A. (2022). Efficient Traffic Flow Analysis Using Machine
Learning. Journal of Urban Computing, 4(2), 45-53

19
APPENDIX
A1 - Source Code
Streamlit_app.py

import streamlit as st

from traffic_signal import update

from update_sheet import update_sheets

from peak_time import peak

def run_input_interface():

st.title("Intelligent Traffic Signal Simulator - Input")

img1 = st.file_uploader("Upload North Image", type=["jpg", "png", "jpeg"])

img2 = st.file_uploader("Upload East Image", type=["jpg", "png", "jpeg"])

img3 = st.file_uploader("Upload South Image", type=["jpg", "png", "jpeg"])

img4 = st.file_uploader("Upload West Image", type=["jpg", "png", "jpeg"])

if st.button("Process Images"):

if img1 and img2 and img3 and img4:

return img1, img2, img3, img4

else:

st.error("Please upload all four images.")

return None, None, None, None

def run_output_interface(red, yellow, green, time_range):

st.title("Traffic Signal Simulator - Results")

st.write("### Signal Times")

signal_directions = ['North', 'East', 'South', 'West']

for i, direction in enumerate(signal_directions):

20
st.write(f"**{direction} Signal Times:**")

st.write(f"- Red: {red[i]} seconds")

st.write(f"- Yellow: {yellow[i]} seconds")

st.write(f"- Green: {green[i]} seconds")

st.write(f"- Peak Time Range: {time_range[direction]['start_time']} to


{time_range[direction]['end_time']}")

st.success("Processing complete and results displayed!")

def process_traffic_signals():

if 'first_run' not in st.session_state:

st.session_state.first_run = True

if 'red' not in st.session_state:

st.session_state.red = [84, 84, 84, 84]

if 'yellow' not in st.session_state:

st.session_state.yellow = [3, 3, 3, 3]

if 'green' not in st.session_state:

st.session_state.green = [25, 25, 25, 25]

img1, img2, img3, img4 = run_input_interface()

if img1 and img2 and img3 and img4:

if st.session_state.first_run:

st.write("### Initial Signal Times")

time_range = peak() # Get time ranges

run_output_interface(

st.session_state.red,

st.session_state.yellow,

st.session_state.green,

time_range

21
)

st.session_state.first_run = False

else:

st.session_state.red, st.session_state.yellow, st.session_state.green =


update(

img1, img2, img3, img4,

st.session_state.red,

st.session_state.yellow,

st.session_state.green

update_sheets(st.session_state.red, st.session_state.green)

time_range = peak() # Get updated time ranges

run_output_interface(

st.session_state.red,

st.session_state.yellow,

st.session_state.green,

time_range

temp = pathlib.PosixPath

pathlib.PosixPath = pathlib.WindowsPath

model = torch.hub.load('yolov5', 'custom', path=r"training_result\exp\weights\best.pt",


source='local', force_reload=True)

def points(img):

def extract_class_counts(results):

class_counts = defaultdict(int)

for *xyxy, conf, cls in results.xyxy[0]:

22
class_id = int(cls)

if class_id not in excluded_classes:

class_name = model.names[class_id]

class_counts[class_name] += 1

return dict(class_counts)

results.print()

class_counts = extract_class_counts(results)

points = {

'Car': 3,

'Two Wheeler': 1,

'Auto': 2,

'Bus': 5,

'Truck': 5

total_points = sum(class_counts.get(cls, 0) * points.get(cls, 0) for cls in


class_counts)

return total_points

def update(img1, img2, img3, img4, red, yellow, green):

signal_points = [points(img1), points(img2), points(img3), points(img4)]

mean_points = np.mean(signal_points)

std_points = np.std(signal_points)

traffic_levels = []

for point in signal_points:

deviation_from_mean = point - mean_points

if deviation_from_mean > std_points:

traffic_levels.append(3)

23
elif deviation_from_mean > 0:

traffic_levels.append(2)

elif deviation_from_mean < -std_points:

traffic_levels.append(0)

else:

traffic_levels.append(1)

for i in range(4):

if traffic_levels[i] == 3:

green[i] = min(green[i] + 5, 60)

elif traffic_levels[i] == 2:

green[i] = min(green[i] - 5, 60)

elif traffic_levels[i] == 0:

green[i] = max(green[i] - 10, 10)

red = []

for i in range(len(green)):

green_sum = sum(green) - green[i]

yellow_sum = sum(yellow) - yellow[i]

red_value = green_sum + yellow_sum

red.append(red_value)

return red, yellow, green

if __name__ == "__main__":

process_traffic_signals()

24
A2: TECHNICAL BIOGRAPHY

Aashik H (210171601001) was born on July 19, 2003, in Madurai, Tamil Nadu, India.
He completed his higher secondary education in 2019 and is currently pursuing a
B.Tech in Artificial Intelligence and Data Science at the School of Computer Information
and Mathematical Sciences at B.S. Abdur Rahman Crescent Institute of Science and
Technology, located in Vandalur, Chennai, India.

His interests lie in the field of Data Science, with a focus on solving real-world
challenges through data-driven insights. Aashik is passionate about leveraging machine
learning, deep learning, and statistical analysis to extract meaningful patterns from
complex datasets, enabling informed decision-making across various domains.

The email for communication is 3aashik7@gmail.com, and his contact number is


+91 98945 75404.

25

You might also like