Downloads · 30 days
0
Subh775/Firearm_Detection_Yolov8n
Firearm_Detection_Yolov8n is a object detection model from Subh775. Use it when you need objects located in an image. The card lists the license as agpl-3.0.
[](https://opensource.org/licenses/Apache-2.0) [](https://github.com/ultralytics/ultralytics) [](https://ultralytics.com/)
Downloads · 30 days
0
Access
Public
Updated Mar 24, 2026
Repo size
203 MB
Likes
5
Public
Click a slice to open those files.
.pt197 MB · 97%
From the Hugging Face model README
Try out the more accurate version at:
A high-performance YOLOv8-nano model specifically trained for firearm detection in images and videos. This model achieves exceptional accuracy with 89.0% [email protected] and is optimized for real-time inference applications in security and surveillance systems.
This model is trained on a comprehensive firearm detection (A custom dataset) containing over 7k high-quality images. The model can detect various types of firearms including pistols, rifles, shotguns, and other weapon types unified under a single "Gun" class for detection of fire-armed weapons
Key Features:
Here is an example output by the model:
<video muted autoplay loop controls src="https://cdn-uploads.huggingface.co/production/uploads/66c6048d0bf40704e4159a23/N6B80__zusImbOoplh_6R.mp4" width=800></video>
The model demonstrates exceptional performance on the validation dataset after 100 epochs of training:
| Metric | Value |
|---|---|
| [email protected] | 0.890 |
| [email protected] | 0.602 |
| Precision | 0.864 |
| Recall | 0.824 |
| F1-Score | 0.84 |
The training progression over 100 epochs shows consistent improvement across all metrics:

The graphs demonstrate:
The dataset contains 6,800 gun instances across 7,068 training images, with balanced spatial distribution and varied object sizes for robust detection capabilities.
Absolute Counts:

Normalized Values:

The confusion matrices show:
These curves demonstrate optimal performance at confidence threshold 0.4, balancing precision and recall for practical deployment.
Training Dataset Composition:
Source Datasets:
Quality Assurance:
pip install ultralytics huggingface_hub
from ultralytics import YOLO
from huggingface_hub import hf_hub_download
# Download model from Hugging Face Hub
model_path = hf_hub_download(
repo_id="Subh775/Firearm_Detection_Yolov8n",
filename="weights/best.pt"
)
# Load model
model = YOLO(model_path)
# Run inference
results = model("path/to/your/image.jpg")
# Display results
for box in results[0].boxes:
class_name = model.names[int(box.cls[0])]
confidence = box.conf[0]
print(f"Detected: {class_name} (Confidence: {confidence:.3f})")
# Show annotated image
results[0].show()
import cv2
from ultralytics import YOLO
from huggingface_hub import hf_hub_download
import torch
from tqdm import tqdm
# Configuration
MODEL_REPO = "Subh775/Firearm_Detection_Yolov8n"
INPUT_VIDEO = "input_video.mp4"
OUTPUT_VIDEO = "output_video.mp4"
CONFIDENCE_THRESHOLD = 0.4
BATCH_SIZE = 32 # Adjust based on GPU memory
# Setup device
device = 0 if torch.cuda.is_available() else "cpu"
print(f"Using device: {'GPU' if device == 0 else 'CPU'}")
# Load model
model_path = hf_hub_download(repo_id=MODEL_REPO, filename="weights/best.pt")
model = YOLO(model_path)
# Process video
cap = cv2.VideoCapture(INPUT_VIDEO)
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = int(cap.get(cv2.CAP_PROP_FPS))
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(OUTPUT_VIDEO, fourcc, fps, (frame_width, frame_height))
frames_batch = []
with tqdm(total=total_frames, desc="Processing video") as pbar:
while cap.isOpened():
success, frame = cap.read()
if success:
frames_batch.append(frame)
if len(frames_batch) == BATCH_SIZE:
# Batch inference
results = model(frames_batch, conf=CONFIDENCE_THRESHOLD,
device=device, verbose=False)
# Write annotated frames
for result in results:
annotated_frame = result.plot()
out.write(annotated_frame)
pbar.update(len(frames_batch))
frames_batch = []
else:
break
# Process remaining frames
if frames_batch:
results = model(frames_batch, conf=CONFIDENCE_THRESHOLD,
device=device, verbose=False)
for result in results:
annotated_frame = result.plot()
out.write(annotated_frame)
pbar.update(len(frames_batch))
cap.release()
out.release()
print(f"Processed video saved to: {OUTPUT_VIDEO}")
Technical Limitations:
Recommended Usage:
This model is released under the Apache 2.0 License. See the LICENSE file for details.
Disclaimer: This model is provided for research purposes only. The predictions can not be used to solve real world problems.