0% found this document useful (0 votes)
56 views12 pages

UML501 Project Report

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views12 pages

UML501 Project Report

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1

Machine Learning
UML501
July 2022 – December 2022

Weapon Detection System


Project Report

Submitted by:

Ananya Malik (102003124)


Rishab Jalota (102003158)
3COE6

Submitted to:

Mr. Niyaz Ahmed Wani


2

Index

1. Problem Description ………………………………………. 3

2. Overview ……………………………………………………. 3

3. Dataset Description ……………………………………….. 4

4. Python Libraries …………………………………………… 4

5. Code ………………………………………………………… 6

6. Output ………………………………………………………. 11
3

Problem Description

Security & surveillance is one of the fastest-growing industries in the world. It is


rapidly becoming a necessity in both personal and professional settings. However,
across the country and the world, there exists the problem of inefficiency due to
overworked security personnel. Quite often a single person is looking into feeds from
multiple cameras which is a hectic task and is prone to errors. Moreover, security
feeds in a majority of settings are just to check recordings in case of a mishap. They
don't have any preventative measures.

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

Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a


multi-platform data visualization library built on NumPy arrays and designed to work with the
broader SciPy stack. One of the greatest benefits of visualization is that it allows us visual
access to huge amounts of data in easily digestible visuals. Matplotlib consists of several plots
like line, bar, scatter, histogram etc.

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

from tensorflow.keras.applications.mobilenet_v2 import preprocess_input


from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.models import load_model
from imutils.video import VideoStream
import numpy as np
import time
import cv2
import os

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)

predictions = np.argmax(predictions, axis=1)


11

if(predictions==1):
print('Safe:No weapon Detected')
else:
print('DANGER!! KNIFE DETECTED')

cv2.imshow("Frame", frame)

key = cv2.waitKey(1) & 0xFF

if key == ord("q"):
break

cv2.destroyAllWindows()
vs.stop()
Output
12

You might also like