Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Firearm Detection Pipeline Using YOLO and ResNet

An integrated object detection and classification system for identifying firearms in images and video frames in near real-time.

Table of Contents

  1. Description
  2. Key Features
  3. Tech Stack
  4. Installation
  5. Datasets & Input
  6. Usage
  7. Project Structure
  8. Configuration

Description

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.

Key Features

  • 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.

Tech Stack

  • Language: Python 3.8+
  • Notebook: Jupyter Notebook (MGSC_673_Final_Project.ipynb)
  • Libraries: PyTorch, torchvision, ultralytics (YOLOv8), scikit-learn, matplotlib, seaborn, pandas

Installation

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

Datasets & Input

  • 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.

Usage

  1. Run the detection pipeline:
    python detect_and_classify.py --source data/images --weights yolov8m.pt --classifier weights/resnet50.pth
  2. Evaluate metrics in the Jupyter Notebook:
    jupyter notebook MGSC_673_Final_Project.ipynb
  3. Visualize results: Bounding boxes overlaid on images, and performance curves saved in figures/.

Project Structure

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

Configuration

  • YOLO Confidence Threshold: Adjust --conf parameter 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages