This project detects five types of weapons in X-ray images using a combination of:
- YOLOv12 for object detection
- ResNet18 for secondary classification
- Grad-CAM for visual explainability
✅ Developed for the Deep Learning course (AIN3002)
- Name: SIXray
- Link: Roboflow Dataset
- Classes:
- Gun
- Knife
- Pliers
- Scissors
- Wrench
- Custom split:
- Train: 497 images
- Validation: 105 images
- Test: 105 images
📦3002_Project
┣ 📁Data/
┃ ┣ 📁train/
┃ ┣ 📁val/
┃ ┗ 📁test/
┣ 📁Crops/ # YOLO-detected objects for classifier
┣ 📁results/ # mAP curves, predictions, visualizations
┣ 📄threat_classifier.pt # Trained ResNet18 model
┣ 📄best.pt # YOLOv12 weights
┣ 📄gradcam_classifier.py
┣ 📄crop_objects.py
┣ 📄train_resnet_classifier.py
┣ 📄data.yaml
┣ 📄yolo12s.yaml
┣ 📄README.md
Install with:
pip install -r requirements.txtMain Dependencies:
- torch
- torchvision
- ultralytics
- opencv-python
- pillow
- pytorch-grad-cam
- matplotlib
from ultralytics import YOLO
model = YOLO("yolo12s.yaml")
model.train(data="data.yaml", epochs=200, imgsz=1024)python crop_objects.pypython train_resnet_classifier.pypython gradcam_classifier.py| Class | Precision | Recall | mAP@50 | mAP@50-95 |
|---|---|---|---|---|
| Gun | 0.732 | 0.684 | 0.749 | 0.325 |
| Knife | 0.343 | 0.360 | 0.324 | 0.156 |
| Pliers | 0.528 | 0.418 | 0.434 | 0.204 |
| Scissors | 0.445 | 0.267 | 0.257 | 0.119 |
| Wrench | 0.175 | 0.125 | 0.166 | 0.082 |
- 🔍 Two-Stage Detection: YOLOv12 for detection → ResNet for refinement
- 🧠 Explainability: Grad-CAM highlights what the classifier sees
- 🧪 Strong Augmentations: Mosaic, Mixup, HSV, Flip, etc.
- 💻 Google Colab Compatible: Code tested on Google Colab Pro
- 🔐 Classifier Confidence Thresholding to reject low-confidence results
- Add a webcam or a real-time app
- Replace ResNet18 with EfficientNet or ViT
- Improve dataset balance (add non-weapon samples)
- Deploy via Streamlit or Flask (optional)
- Ultralytics YOLO
- Roboflow
- PyTorch Grad-CAM