An Accident Detector on IOT devices
Summary
Dataset Creation
Data Processing
The Algorithm
References
The Convolutional neural network algorithm model has created to detect accidents in video footages captured by IOT devices
For the dataset creation purpose we used the CADP Dataset which conatains the accident videos and DETRAC dataset which is mainly used for the vehicular detection
as our non-accident videos. When we converted the CADP videos into frames (using frame_cutter.py), we found that most of the frames like frames before accident have no accident visible in them so after converting all the videos in frames we manually separated the frames with accidents. By doing this we were able to get 4000 images with accidents and similary, we got 8000 images from DETRAC dataset. So we created a dataset containing 12000 accident and non-accident images. We have uploaded the dataset to google drive and link for the same is given below.
We converted each video into its individual frames. Each of these images is a two-dimensional array of pixels where each pixel has information about the red, green, and blue (RGB) color levels. To reduce the dimensionality at the individual image level, we convert the 3-D RGB color arrays to grayscale. Additionally, to make the computations more tractable on a CPU, we resize each image to (128, 128) - in effect reducing the size of each image to a 2-D array of 122 X 128.
We built a convolutional neural network for image classification with keras.
We created a sequential model which linearly stacks all the the layers, using keras.models. We implemented different keras layers like Conv2D- convolutional layer, MaxPooling2D- max pooling layer, Dropout, Dense- add neurons, Flatten- convert the output to 1D vector, using keras.layers along with 'ReLU' and 'softmax' as activation functions.
While compiling the model we used "sparse_categorical_crossentropy" as our loss function, "adam" as our optimizer and "accuracy metrics" as metrics. Then in model fit we ran the model for "10" epochs with "0.2" validation_split.
Using this model we are able to predict whether given video contains accident or not.
You can install Conda for python which resolves all the dependencies for machine learning.
- Run
create_dataset.py
for converting the video to images. - Then run
main.py
to train the model. - Finally, run
model.py
for testing your model.