This project explored how machine learning and computer vision can support security by detecting weapon related objects in image data. The aim was to build a convolutional neural network capable of classifying whether an image contained a knife, demonstrating how AI can be applied to threat detection and surveillance analysis scenarios. It can be deployed in various applications such as policing, private investigations etc. While this model focuses on weapon detection the principle is that this model can be retrained to detect something different entirely to expand into other disciplines/applications such as construction or healthcare.
The model was built using Python, TensorFlow and Keras, with the dataset prepared in TFRecord format and resized to 640×640 resolution. I used a Roboflow knife dataset and implemented preprocessing steps such as JPEG decoding, image resizing, pixel normalisation and label extraction. The model was trained as a binary classification task, separating knife images from background/non knife examples.
The CNN architecture used convolutional layers for feature extraction, max pooling layers for dimensionality reduction, dense layers for classification and dropout to reduce overfitting. The model was compiled with the Adam optimiser and sparse categorical cross entropy, then trained using callbacks such as EarlyStopping, ModelCheckpoint and TensorBoard to monitor performance and avoid unnecessary training.
Testing involved loading the trained model, evaluating it against unseen TFRecord test data, calculating accuracy and visualising predictions using Matplotlib. The project helped me understand that AI based security detection is not only about training a model but it also relies on dataset quality, preprocessing, validation, confidence interpretation and awareness of false positives and false negatives.
Below is a walkthrough of the compilation of epochs and testing I executed: