1822 B.E Cse Batchno 157
1822 B.E Cse Batchno 157
at
BONAFIDE CERTIFICATE
Certified that this project report titled “ACCIDENT DETECTION USING MACHINE
LEARNING METHODS” is the bonafide work of MANUKONDA TEJASREE , MUCHUMARRI
SAI JAHNAVI who carried out the project work under my supervision during the academic
year 2021-2022.
Internal Guide
Dr. A. Viji Amutha Mary, M.Tech., Ph.D
I, MANUKONDA TEJASREE , MUCHUMARRI SAI JAHNAVI hearby declare that the project
report entitled ACCIDENT DETECTION USING MACHINE LEARNING METHODS done by us
under the guidance of Dr. A. Viji Amutha Mary, M.Tech., Ph.Df is submitted in partial fulfillment of
the requirements for the award of Bachelor Of Engineering Degree in Computer Science and
Engineering.
2
ABSTRACT
There are lots of studies about preventing or detecting the car accidents. Most of them includes sensing
objects which might cause accident or statistics about accidents. In this study, a system which detects
happening accidents will be studied. The system will collect necessary information from neighbor
vehicles and process that information using machine learning tools to detect possible accidents. Machine
learning algorithms have shown success on distinguishing abnormal behaviors than normal behaviors.
This study aims to analyze traffic behavior and consider vehicles which move different than current
traffic behavior as a possible accident. Results showed that clustering algorithms can successfully detect
accidents.The problem of deaths and injuries as a result of accidents is to be a global phenomenon.
Traffic safety has been a serious concern since the start of the automobile age, almost one hundred years
ago.It has been estimated that over 300,000 persons die and 10 to 15 million persons are injured every
year in road accidents throughout the world.Statistics have also shown that mortality in road accidents is
very high among young adults that constitute the major part of the work force. In order to overcome this
problem, there is need of various has road safety strategies and measure.Losses in road accidents are
unbearable, to the society as well as a developing country like us. So, it has become an essential
requirement to control and arrange traffic with an advanced system to decrease the number of road
accidents in our country. By taking simple precautions, based on prediction of a sophisticated system may
prevent traffic accidents. Moreover, to tackle this situation where every day so many people were killed
in a traffic accident. and day by day this rate is getting increased. The implementation of machine
learning is a functional and a great approach to take an accurate decision with the experience to manage
the current situation and the findings of the analysis part which we are suggested to traffic authorities.
3
ACKNOWLEDGEMENT
I convey my thanks to Dr. T. Sasikala M.E., Ph.D, Dean, School of Computing, Dr. S.
Vigneshwari, M.E., Ph.D. and Dr. L. Lakshmanan, M.E., Ph.D., Heads of the
Department of Computer Science and Engineering for providing me necessary support
and details at the right time during the progressive reviews.
I would like to express my sincere and deep sense of gratitude to my Project Guide Dr. A.
Viji Amutha Mary, M.Tech., Ph.D for his valuable guidance, suggestions and constant
encouragement paved way for the successful completion of my project work.
I wish to express my thanks to all Teaching and Non-teaching staff members of the
Department of Computer Science and Engineering who were helpful in many ways for
the completion of the project.
4
TABLE OF CONTENTS
PAGE
CHAPTER NO TITLE
NO
ABSTRACT 3
LIST OF FIGURES 7
LIST OF TABLES 6
1 INTRODUCTION 8
1.1 Technologies used 9
1.1.1 Machine Learning 9
1.2 Importance of Machine learning 10
1.3 Machine learning process 10
1.4 Types.of Machine Learning 12
1.5 Supervised Machine Learning 12
1.6 Unsupervised Machine Learning 13
2 LITERATURE REVIEW 15
2.1 Incident detection algorithm 15
2.2 Design of a system solution for relative
16
positioning
2.3 Vehicle - to - Vehicle safety messaging in
17
DSRC
2.4 Integrating dead reckoning,map matching and
18
GPS positioning
2.5 Challange for localisation-based Systems 19
3 PROJECT DESCRIPTION 20
5
3.1 Existing system 20
3.2 Proposed system 20
3.3 Working 21
3.4 Module Description 21
4.2.2 Working
4.3 Disadvantages of Existing System
25
4.5 Applications 26
6 RESULTS 40
6
6.1 Final results 43
7 CONCLUSION 44
7.1 Conclusion 44
7.2 Future work 44
7.3 Scope of further study 44
8 REFERENCES 46
7
LIST OF FIGURES
8
CHAPTER 1
INTRODUCTION
Machine Learning (ML) is coming into its own, with a growing recognition that
ML can play a key role in a wide range of critical applications, such as data
mining, natural language processing, image recognition, and expert systems.
9
" A computer program is said to learn from experience E with respect to some task
T and some performance measure P, if its performance on T, as measured by P,
improves with experience E.”
Machine learning workflow refers to the series of stages or steps involved in the
process of building a successful machine learning system.
The various stages involved in the machine learning workflow are-
10
Figure 1.2 Machine Learning Process
Data Collection- In this stage,
Data is collected from different sources.The type of data collected depends upon the type
of desired project.Data may be collected from various sources such as files, databases
etc.The quality and quantity of gathered data directly affects the accuracy of the desired
system.
11
1.4Types of Machine Learning
12
b) Regression : Regression algorithms are used to solve regression problems in
which there is a linear relationship between input and output variables. These
are used to predict continuous output variables, such as market trends,
weather prediction, etc.
13
taking action, learning from experiences, and improving its performance.
Reinforcement learning is categorized mainly into two types of methods/algorithms:
14
CHAPTER -2 LITERATURE
REVIEW
2 LITERATURE SURVEY:
15
2.2 : Kukshya, V., Krishnan, H., Kellum, C., n.d. Design of a system
solution for relative positioning of vehicles using vehicle-to-vehicle radio
communications during GPS outages.
Proposed work
Active safety applications for vehicles have been at the forefront of the
automotive safety community for a number of years. Cooperative collision
warning based on vehicle-to-vehicle radio communications and GPS
systems is one such promising active safety application that has evoked
considerable interest among automobile manufacturers and research
communities worldwide. In this paper, we address one of the key functional
components of the cooperative collision warning application, which is,
accurate estimation of relative positions of all the neighboring vehicles based
on real-time exchange of their individual GPS position coordinates, and then
propose a novel system solution for achieving the same (relative positioning
functionality) during persistent GPS outages. Based on survey results, we
also qualitatively assess various radio based ranging and relative positioning
techniques, experimentally evaluate the received signal strength based
ranging technique, and comment on their suitability for our proposed
solution.
16
2.3 Xu, Q., Mak, T., Ko, J., Sengupta, R., 2004. Vehicle-to-vehicle
safety messaging in DSRC. AC
2.4 Krakiwsky, E.J., Harris, C.B., Wong, R.V.., 1988. A Kalman filter for
integrating dead reckoning, map matching and GPS positioning, in: ,
IEEE Position Location and Navigation Symposium, 1988. Record.
Navigation into the 21st Century. IEEE PLANS ’88. Presented at the ,
IEEE Position Location and Navigation Symposium, 1988. Record.
Navigation into the 21st Century. IEEE PLANS ’88, IEEE, pp. 39-46.
To make driving easier and safer, modern vehicles are equipped with driver
support systems. Some of these systems, for example navigation or
17
curvature warning systems, need the global position of the vehicle. To
determine this position, the Global Positioning System (GPS) or a Dead
Reckoning (DR) system can be used. However, these systems have often
certain drawbacks. For example, DR systems suffer from error growth with
time and GPS signal masking can occur. By integrating the DR position
and the GPS position, the complementary characteristics of these two
systems can be used advantageously. In this thesis, low cost in-vehicle
sensors (gyroscope and speedometer) are used to perform DR and the
GPS receiver used has a low update frequency. The two systems are
integrated with an extended Kalman filter in order to estimate a position.
The evaluation of the implemented positioning algorithm shows that the
system is able to give an estimated position in the horizontal plane with a
relatively high update frequency and with the accuracy of the GPS receiver
used. Furthermore, it is shown that the system can handle GPS signal
masking for a period of time. In order to increase the performance of a
positioning system, map matching can be added. The idea with map
matching is to compare the estimated trajectory of a vehicle with roads
stored in a map data base, and the best match is chosen as the position of
the vehicle. In this thesis, a simple off-line map matching algorithm is
implemented and added to the positioning system. The evaluation shows
that the algorithm is able to distinguish roads with different direction of
travel from each other and handle off-road driving.
18
2.5 Boukerche, A., Oliveira, H., Nakamura, E., Loureiro, A., 2008.
Vehicular Ad Hoc Networks: A New Challenge for Localization-Based
Systems. Computer Communications 31, 2838–2849.
The new kind of ad hoc network is hitting the streets: Vehicular Ad Hoc
Networks. (VANets). In these networks, vehicles communicate with each
other and possibly with a roadside infrastructure to provide a long list of
applications varying from transit safety to driver assistance and Internet
access. In these networks, knowledge of the real-time position of nodes is
an assumption made by most protocols, algorithms, and applications. This
is a very reasonable assumption, since GPS receivers can be installed
easily in vehicles, a number of which already comes with this technology.
But as VANets advance into critical areas and become more dependent on
localization systems, GPS is starting to show some undesired problems
such as not always being available or not being robust enough for some
applications. For this reason, a number of other localization techniques
such as Dead Reckoning, Cellular Localization, and Image/Video
Localization has been used in VANets to overcome GPS limitations. A
common procedure in all these cases is to use Data Fusion techniques to
compute the accurate position of vehicles, creating a new paradigm for
localization in which several known localization techniques are combined
into a single solution that is more robust and precise than the individual
approaches. In this paper, we further discuss this subject by studying and
analyzing the localization requirements of the main VANet applications.
19
CHAPTER - 3 PROJECT DESCRIPTION
20
3.3 WORKING
21
Data imbalance. Some classes or categories in the data may have a disproportionately high
or low number of corresponding samples. As a result, they risk being under-represented in
the model.
Data bias. Depending on how the data, subjects and labels themselves are chosen, the
model could propagate inherent biases on gender, politics, age or region, for example.
Data bias is difficult to detect and remove.
Data Preprocessing : Real-world raw data and images are often incomplete, inconsistent
and lacking in certain behaviors or trends. They are also likely to contain many errors. So,
once collected, they are pre-processed into a format the machine learning algorithm can
use for the model.
Pre-processing includes a number of techniques and actions:
Data cleaning. These techniques, manual and automated, remove data incorrectly added or
classified.
Data imputations. Most ML frameworks include methods and APIs for balancing or filling
in missing data. Techniques generally include imputing missing values with standard
deviation, mean, median and k-nearest neighbors (k-NN) of the data in the given field.
22
3.4.2 Data cleaning :
Data cleaning is one of the important parts of machine learning. It plays a significant
part in building a model. It surely isn’t the fanciest part of machine learning and at the
same time, there aren’t any hidden tricks or secrets to uncover. However, the success or
failure of a project relies on proper data cleaning. Professional data scientists usually
invest a very large portion of their time in this step because of the belief that “Better data
beats fancier algorithms”.
23
CHAPTER -4
METHODOLOGY FLOW
This chapter describes the overall design. It also describes each module that
is to be implemented.
Our goal is to train a custom deep learning model to detect whether a accident has
occurred or not .
24
4.2.1 Accident dataset creation :
To create this dataset, Then creating a custom computer vision Python script to add
accidents to them, thereby creating an artificial (but still real-world applicable)
datasetThis method is actually a lot easier than it sounds once you apply landmarks to the
problem.
4.2.2 Working :
First we collect the data from CCTV cameras.Then we apply data preprocessing
technique.after preprocessing the data we train the system by using data
set(accident) & (non accident).after completion of training we will apply YOLO
algorithm to detect the object.By using YOLO algorithm it will divide into frames
then the frames will detect whether the accident is happened or not.
25
4.4 ADVANTAGES OF PROPOSED SYSTEM:
4.5 APPLICATIONS:
● Used in traffic .
● Used in Highways .
● We can also use this at driving schools and vehicle exhibitions
26
CHAPTER-5
TOOLS AND TECHNIQUES
SOFTWARE REQUIREMENTS
● Python
● Pycharm
5.1. Python
27
no exclusivity either, as Python and all the necessary tools are available on all
major platforms. Therefore, it is an enticing option for developers who don't want
to worry about paying high development costs.
If this description of Python over your head, don't worry. You will
understand it soon enough. What you need to take away from this section is that
Python is a programming language used to develop software on the web and in app
form, including mobile. It's relatively easy to learn, and the necessary tools are
available to all free of cost.
5.2 PYCHARM
Pros:
● "I have been using PyCharm since over 4 years now and It is one of the best
IDEs out there for python developers. Great product with auto-complete
features."
28
● "Also PyCharm have some tools to find errors and helps you to correct them. I also
like the style and colors very nice for me”.
● "The best all in one IDE out there, the python supporting features are great and it
has a many templates for different projects for ease of architecture."
● "PyCharm is probably the best IDE for Python projects as it has so many Python
orientated features. Personally, I only use PyCharm for the occasional Python
project and I am very satisfied with that."
temp_dir = 'test_input'
output_dir = 'output_frames'
29
for video_file in os.listdir(temp_dir):
path = os.path.join(temp_dir, video_file)
print(path)
output_dir_folder = os.path.join(output_dir, video_file)
os.mkdir(output_dir_folder)
sec = 0
frameRate = 2.0 #//it will capture image in each 0.5 second
count=1
success = getFrame(sec, path, output_dir_folder)
while success:
count = count + 1
sec = sec + frameRate
sec = round(sec, 2)
success = getFrame(sec, path, output_dir_folder)
import cv2
import tensorflow as tf
import os
from skimage.transform import resize
import numpy as np
from PIL import Image
model = tf.keras.models.load_model('model_train')
categories = ["Accident", "Non-Accident"]
30
main_dir = "test_frames"
for dirs in os.listdir(main_dir):
test_dir = os.path.join(main_dir, dirs)
print(test_dir)
a=0
for img_t in os.listdir(test_dir):
31
return hasFrames
temp_dir = 'test_input'
output_dir = 'output_frames'
32
import cv2
from skimage.transform import resize
train = tf.keras.models.load_model('model_train')
categories = ["Accident", "Non-Accident"]
img_test = np.load("labels/test_features.npy")
label_test = np.load("labels/test_labels.npy")
img_test = img_test / 255
img_test = img_test.reshape(list(img_test.shape) + [1])
print(img_test.shape)
train.evaluate(img_test, label_test)[1]
print("index \t label \t predicted")
#classes = train.predict_classes(img_test)
classes = train.predict(img_test)
np.argmax(classes)
for i in range(len(label_test)):
print(i+1,"\t", categories[label_test[i]])
#, "\t", categories[classes[i]]
import tensorflow as tf
33
import cv2
from skimage.transform import resize
X = np.load("labels/train_features.npy")
print("St 1")
Y = np.load("labels/train_labels.npy")
print("St 2")
X = X / 255
print("St 3")
X = X.reshape(list(X.shape) + [1])
print("St 4")
print(X.shape)
#creating my model
model = Sequential();
#adding first layer i.e convolutional layer, passing input_shape only in first layer
model.add(Conv2D(32, (5 , 5), activation="relu", input_shape=(128, 128, 1)))
34
model.add(MaxPooling2D(pool_size = (2 , 2)))
35
#training the model
train = model.fit(X, Y, batch_size = 256, epochs = 10, validation_split=0.2,
shuffle=True)
model.save('model_train')
Train_DIR = r"/home/sparsh/Desktop/Accident_Detection/Accident-Dataset/train"
Test_DIR = r"/home/sparsh/Desktop/Accident_Detection/Accident-Dataset/test"
categories = ["Accident", "Non-Accident"]
test_data = []
train_data = []
36
def getTrainData():
i=0
for index, category in enumerate(categories):
path = os.path.join(Train_DIR , category)
for img in os.listdir(path):
i += 1
print(i)
try:
image = cv2.imread(os.path.join(path, img),
cv2.IMREAD_GRAYSCALE)
image = resize(image, (128, 128))
train_data.append([image , index])
except Exception as e:
pass
def getTestData():
i=0
for index, category in enumerate(categories):
path = os.path.join(Test_DIR , category)
for img in os.listdir(path):
i += 1
print(i)
try:
37
image = cv2.imread(os.path.join(path, img),
cv2.IMREAD_GRAYSCALE)
image = resize(image, (128, 128))
test_data.append([image , index])
except Exception as e:
pass
print("Getting Train Data")
getTrainData()
random.shuffle(train_data)
random.shuffle(test_data)
train_features = []
train_labels = []
test_features = []
test_labels = []
train_features = np.array(train_features)
train_labels = np.array(train_labels)
38
print(type(train_features))
test_features = np.array(test_features)
test_labels = np.array(test_labels)
print(type(test_features))
np.save("train_features", train_features)
np.save("train_labels", train_labels)
np.save("test_features", test_features)
np.save("test_labels", test_labels)
39
CHAPTER-6
FINAL RESULTS
We take the input video from a Source (CC TV camera �) and divide the video
into severalframes.On each frame a Vehicle is detected whether Accident has
occurred or not. If accident occurred it will print the image number with “accident”
message.
6.1 FINAL RESULTS
40
smashed to each other .
41
Comment [1]: Accident occurred
42
Fig 6.4 : No of Accident occurred
In this picture we got 4 images displayed with name accident , because in that
video 4 accidents has happened so we got displayed that.
43
CHAPTER – 7
7.1 CONCLUSION
44
CHAPTER - 8
REFERENCE
1. Kardas K, Cicekli NK. SVAS: surveillance video analysis system.
Expert Syst Appl. 2017;89:343–61.
4. P.A. Viola and M.J. Jones, ―Rapid object detection using a boosted
cascade of simple features,‖ in Proc. CVPR, 2001, no. 1, pp. 511–518.
45
10. X. Tong, Z. Hong, S. Liu, X. Zhang, H. Xie, Z. Li, S. Yang, W.
Wang and F. Bao, ―Building-damage detection using pre-and post-
seismic high-resolution satellite stereo imagery: a case study of the May
2008 Wenchuan earthquake,‖ ISPRS Journal of Photogrammetry and
Remote.Sensingg, vol. 68, pp.13-27, Mar. 2012.
46