UML501 Project Report
UML501 Project Report
Machine Learning
UML501
July 2022 – December 2022
Submitted by:
Submitted to:
Index
2. Overview ……………………………………………………. 3
5. Code ………………………………………………………… 6
6. Output ………………………………………………………. 11
3
Problem Description
Overview
AI surveillance can help detect dangerous objects like guns or knives at entry points or
inside the building and execute appropriate preventative actions, such as: setting off
alarms, alerting security personnel, and/or automatically locking doors depending
upon the situation.
Our program involves training a model that is able to detect knives, and applying it to
a camera stream in order to print an alert when one is detected. The feed from the
CCTV will be passed into the model frame by frame which will detect the presence of
any weapon. If the weapon is detected at the gate, it will immediately print an alert to
notify the relevant security personnel. This model can be used in CCTV camera
streams to pre-emptively detect dangerous objects & hence prevent untoward
incidents from happening.
Our model utilises the YOLO (You Only Look Once) algorithm and is trained on a
labelled dataset of images to detect knives. The YOLO algorithm outperforms other
object detection algorithms, such as R-CNN and its variants, in terms of speed.
The YOLO framework is unique in that it takes the entire image in a single instance
and predicts the bounding box coordinates and class probabilities for these boxes.
Whereas algorithms like Faster RCNN work by detecting possible regions of interest
using the Region Proposal Network and then perform recognition on those regions
separately. Methods that use Region Proposal Networks thus end up performing
multiple iterations for the same image, while YOLO achieves the same result with a
single iteration.
4
Dataset Description
The dataset used in this project consists of two separate folders, each containing
images in which a knife may be present. The with_knife folder consists of 646
images extracted from various sources that depict knives held in human hands from
various angles. On the other hand, the without_knife folder contains 1605 images of
random objects. The images contained in both these folders have been collected from
various sources on the Internet, such as Kaggle and Github, as well as ~250 images
that have been manually taken by the project creators and added to the database.
These labelled folders are used for training the model.
Python Libraries
1. os:
Python OS module provides the facility to establish the interaction between the user and the
operating system. It offers many useful OS functions that are used to perform OS-based tasks
and get related information about operating system. The OS comes under Python's standard
utility modules.
2. keras:
It is an open-source high-level Neural Network library, which is written in Python is capable
enough to run on Theano, TensorFlow, or CNTK. It was developed by one of the Google
engineers, Francois Chollet. It is made user-friendly, extensible, and modular for facilitating
faster experimentation with deep neural networks. It not only supports Convolutional
Networks and Recurrent Networks individually but also their combination.
3. sklearn:
Scikit-learn (Sklearn) is the most useful and robust library for machine learning in Python. It
provides a selection of efficient tools for machine learning and statistical modeling including
classification, regression, clustering and dimensionality reduction via a consistence interface
in Python. This library, which is largely written in Python, is built upon NumPy, SciPy and
Matplotlib.
4. numpy:
NumPy is a general-purpose array-processing package. It provides a high-performance
multidimensional array object, and tools for working with these arrays. It is the fundamental
package for scientific computing with Python. It is open-source software.
5. matplotlib:
5
6. imutils:
A series of convenience functions to make basic image processing functions such as
translation, rotation, resizing, skeletonization, displaying Matplotlib images, sorting contours,
detecting edges, and much more easier with OpenCV and both Python 2.7 and Python 3.
7. cv2:
OpenCV-Python is a library of Python bindings designed to solve computer vision problems.
cv2.imread() method loads an image from the specified file. If the image cannot be read
(because of missing file, improper permissions, unsupported or invalid format) then this
method returns an empty matrix.
6
Code
model-training.ipynb
7
8
9
10
knife-detector-video.py
os.getcwd()
Knife_detector = load_model("knife_detector.model5")
#print(Knife_detector.summary())
vs = VideoStream(src=0).start()
while True:
frame = vs.read()
image=cv2.resize(frame,(224,224),interpolation=cv2.INTER_AREA)
image = img_to_array(image)
image = preprocess_input(image)
image = image.reshape(1,224,224,3)
predictions = Knife_detector.predict(image, batch_size=32)
if(predictions==1):
print('Safe:No weapon Detected')
else:
print('DANGER!! KNIFE DETECTED')
cv2.imshow("Frame", frame)
if key == ord("q"):
break
cv2.destroyAllWindows()
vs.stop()
Output
12