Internship Repoort 3
Internship Repoort 3
Internship Repoort 3
AN INTERNSHIP REPORT
Submitted by
AASHIK H
DECEMBER 2024
AI-Powered Traffic Signals
AN INTERNSHIP REPORT
Submitted by
AASHIK H
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
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 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
VI
LIST OF ABBREVIATIONS
ML Machine Learning
nc number of classes
LR Learning Rate
VII
LIST OF FIGURES
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:
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.
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.
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
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.
For computationally intensive tasks, Google Colab was utilized, offering flexibility and
power for large-scale deep learning experiments.
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:
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.
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.
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.
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.
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
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.
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.
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.
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
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.
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:
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.
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:
16
Fig 6.2: Detection of different vehicles in traffic
17
7. CONCLUSION
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
def run_input_interface():
if st.button("Process Images"):
else:
20
st.write(f"**{direction} Signal Times:**")
def process_traffic_signals():
st.session_state.first_run = True
st.session_state.yellow = [3, 3, 3, 3]
if st.session_state.first_run:
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_sheets(st.session_state.red, st.session_state.green)
run_output_interface(
st.session_state.red,
st.session_state.yellow,
st.session_state.green,
time_range
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
def points(img):
def extract_class_counts(results):
class_counts = defaultdict(int)
22
class_id = int(cls)
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
return total_points
mean_points = np.mean(signal_points)
std_points = np.std(signal_points)
traffic_levels = []
traffic_levels.append(3)
23
elif deviation_from_mean > 0:
traffic_levels.append(2)
traffic_levels.append(0)
else:
traffic_levels.append(1)
for i in range(4):
if traffic_levels[i] == 3:
elif traffic_levels[i] == 2:
elif traffic_levels[i] == 0:
red = []
for i in range(len(green)):
red.append(red_value)
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.
25