This repository presents a deep learning–powered vision system that detects and classifies weapons from live surveillance feeds or recorded videos. Unlike traditional motion-based systems, this model is trained to minimize false triggers from everyday objects (toys, kitchen items, etc.), ensuring reliable and context-aware detection. The goal is to support public safety and threat prevention by providing early alerts of dangerous objects in the scene.
- Detect Threats: Accurately identify a wide range of weapons in live video feeds.
- Reduce False Positives: Distinguish real weapons from harmless objects for reliable alerts.
- Showcase Performance: Provide clear, standout metrics and visuals to highlight model capability.
- Clone the repository
git clone https://github.com/Soohaam/Weapon-Detection-Assignment.git cd Weapon-Detection - Create & activate a virtual environment
Windows (PowerShell):
python -m venv venv venv\Scripts\activate
- Install dependencies
pip install -r requirements.txt
- Download model weights
The weights (best.pt) can be found in: My Drive.
pip install -r requirements.txt results/weapons_train/weights/best.pt
Weapon-Detection/
├── data/
│ ├── images/ # Test images
│ ├── videos/ # Test videos
│ └── weapons_dataset/ # Train/valid/test split dataset
│
├── models/ # Base YOLO weights
│ └── yolov8n.pt
│
├── results/
│ ├── weapons_detection_results/ # Outputs (images/frames)
│ └── weapons_train/ # Training logs + weights
│ └── weights/
│ ├── best.pt
│ └── last.pt
│
├── src/
│ ├── detect.py # Inference script (images/videos)
│ └── train.py # Training script
│
├── requirements.txt
├── data.yaml
└── README.md
Run detection on an image
cd src
python detect.py ../results/weapons_train/weights/best.pt ../data/images/sample1.jpg
Run detection on a video (outputs frames in results/weapons_detection_results/)
cd src
python detect.py ../results/weapons_train/weights/best.pt ../data/videos/samplevideo.mp4
Train the model (optional, if retraining is needed)
The model was trained on a custom dataset. Download it from Google Drive and place it in the data/weapons_dataset/ directory.
cd src
python train.py
-
- Performance Highlight: Peaks at 0.56 (confidence 0.404), showcasing an optimal balance of precision and recall for threat detection.
-
- Performance Highlight: Soars to 1.0 at high confidence (0.996), ensuring near-perfect accuracy and minimizing false alarms on toys or utensils.
-
- Performance Highlight: Achieves a stellar 0.82 at low confidence, guaranteeing most genuine threats are caught.
-
- Performance Highlight: Boasts an impressive mAP@0.5 = 0.543, reflecting strong overall detection across all weapon classes.
-
- Performance Highlight: Reveals a solid average accuracy, with standout detection for Knife and Missile.
- Description: This plot showcases the model's mean Average Precision at IoU=0.5 (mAP50) and across IoU 0.5-0.95 (mAP50-95), highlighting its robust detection capabilities over varying thresholds.
- Description: This plot displays the Precision and Recall curves, demonstrating the model's ability to balance accurate detections with comprehensive threat identification.
| Raw Image | Detected Image |
|---|---|
![]() |
![]() |
| Description: The original test image. | Description: A sample frame highlighting the model's accurate detection of a handgun. |
| Raw Image | Detected Image |
|---|---|
![]() |
![]() |
| Description: The original test image. | Description: An example frame showcasing the model's capability to detect a rifle in a real-world image setting. |









