A computer vision project for detecting handguns in images, videos, and webcam streams using the YOLO object detection framework. The project includes dataset preparation, model training, evaluation, and inference utilities, providing a complete workflow for developing and deploying an object detection model.
This project implements an end-to-end object detection pipeline for handgun detection using deep learning. It covers data preparation, model training, evaluation, and real-time inference, making it suitable for experimentation with object detection techniques and surveillance-related research.
The repository is organized into modular scripts for dataset preparation, training, and inference, allowing individual components to be reused or extended.
- Handgun detection in images
- Video-based object detection
- Real-time webcam inference
- Dataset preparation for YOLO training
- Modular training and inference scripts
- Support for custom datasets
The project uses the YOLO object detection framework to localize and classify handguns.
The pipeline includes:
- Dataset preparation
- Annotation conversion
- Train-validation split
- Model training
- Performance evaluation
- Image and video inference
Supported input sources include:
- Images
- Videos
- Webcam streams
handgun-detection/
│
├── data/
│ └── Data.md
│
├── notebooks/
│ ├── handgun_detection_train.ipynb
│ └── handgun_detection_inference.ipynb
│
├── prepared_data/
│ ├── images/
│ ├── labels/
│ └── data.yaml
│
├── runs/
│
├── scripts/
│ ├── prepare_data.py
│ ├── run_inference.py
│ ├── split_dataset.py
│ └── train_yolo.py
│
├── utils/
│ └── coco_to_yolo.py
│
├── results_metrics.txt
├── requirements.txt
└── README.md
Clone the repository:
git clone https://github.com/gopal092003/handgun-detection.git
cd handgun-detection
Install the required dependencies:
pip install -r requirements.txt
Prepare the dataset before training by converting annotations into the YOLO format and creating the train-validation split.
python scripts/prepare_data.py
python scripts/split_dataset.py
Train the YOLO model using:
python scripts/train_yolo.py
Model checkpoints and training results are saved in the runs/ directory.
Run inference on a video:
python scripts/run_inference.py
The notebooks also demonstrate inference on images and video streams.
The trained model is capable of detecting handguns under a variety of lighting conditions and viewing angles while maintaining near real-time inference performance.
Evaluation metrics are available in:
results_metrics.txt
- Python
- YOLO
- OpenCV
- PyTorch
- NumPy
- Matplotlib
- Expand the training dataset
- Support multiple weapon categories
- Improve detection accuracy for challenging scenes
- Optimize inference for edge devices
- Deploy as a web application or API
Gopal Gupta
GitHub: https://github.com/gopal092003
This project is licensed under the MIT License.