An integrated object detection and classification system for identifying firearms in images and video frames in near real-time.
- Description
- Key Features
- Tech Stack
- Installation
- Datasets & Input
- Usage
- Project Structure
- Configuration
This project combines a YOLO-based object detection model with a ResNet classifier to detect and confirm the presence of firearms in CCTV images or video. YOLO quickly proposes bounding boxes for potential weapons, and ResNet classifies each crop to reduce false positives and improve accuracy, enabling actionable security insights.
- Real-Time Detection: Near real-time inference with YOLOv8 for fast bounding box proposals (~0.0125s per image).
- Dual-Stage Pipeline: YOLO locates candidate regions; ResNet classifies candidates as firearm vs. background.
- Performance Analytics: Training and validation metrics for detection (precision, recall, mAP) and classification (accuracy, confusion matrix).
- Diagnostics: Precision–Recall curves, F1 curves, and label distributions to assess model reliability.
- Scalable Architecture: Modular pipeline for swapping in alternative detection or classification backbones.
- Language: Python 3.8+
- Notebook: Jupyter Notebook (
MGSC_673_Final_Project.ipynb) - Libraries: PyTorch, torchvision, ultralytics (YOLOv8), scikit-learn, matplotlib, seaborn, pandas
git clone https://github.com/your-username/firearm-detection-pipeline.git
cd firearm-detection-pipeline
python -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
pip install -r requirements.txt- Test Images/Video: Directory of CCTV frames for inference.
- YOLO Training Data: Annotated firearm bounding boxes.
- ResNet Training Data: Cropped firearm vs. non-firearm images for classification.
Place all images in the data/ folder and adjust paths in the notebook as needed.
- Run the detection pipeline:
python detect_and_classify.py --source data/images --weights yolov8m.pt --classifier weights/resnet50.pth
- Evaluate metrics in the Jupyter Notebook:
jupyter notebook MGSC_673_Final_Project.ipynb
- Visualize results: Bounding boxes overlaid on images, and performance curves saved in
figures/.
firearm-detection-pipeline/
├── README_MGSC673.md # This file
├── requirements.txt # Python dependencies
├── data/ # Input images and annotations
│ ├── images/
│ ├── yolo_labels/
│ └── resnet_crops/
├── detect_and_classify.py # Main inference script
├── MGSC_673_Final_Project.ipynb # Analysis and metrics Notebook
├── weights/ # Pretrained model weights
│ ├── yolov8m.pt
│ └── resnet50.pth
└── figures/ # Output visualizations
├── precision_recall.png
└── f1_curve.png
- YOLO Confidence Threshold: Adjust
--confparameter for detection sensitivity. - ResNet Input Size: Modify crop resizing dimensions in the inference script.
- Batch Size & Device: Set GPU/CPU and batch size in the pipeline arguments.