Weapon Detection
YOLO-based weapon, knife, and gun detection — browser-side (YOLO26n) and server-side (YOLOv8n Firearm)
Overview
SecureGate detects weapons in two contexts: in the browser for real-time camera preview, and on the server for full-resolution analysis. Both pipelines output bounding boxes with class labels: Weapon (generic), Knife, and Gun.
Browser Detection (YOLO26n)
The operator dashboard runs a lightweight YOLO model directly in the browser for real-time weapon detection overlay on camera streams.
| Property | Value |
|---|---|
| Model | YOLO26n (fine-tuned from COCO) |
| Format | ONNX (9.7 MB, opset 12, FP32) |
| Runtime | onnxruntime-web (WebGPU → WebGL → WASM) |
| NMS | NMS-free (built into model head) |
| Classes | Weapon, Knife, Gun |
| Input | 640×640 RGB |
| Precision | 95.3% |
| Recall | 88.2% |
| mAP@50 | 94.9% |
| mAP@50-95 | 75.0% |
| Training | 66 epochs on Weapon-2 dataset (3,839 images) |
| Latency | ~30ms per frame (M1 MacBook) |
YOLO26n is an NMS-free variant, meaning the model's output head performs its own suppression and returns final detections directly. This eliminates the need for a separate non-maximum suppression step in JavaScript, reducing complexity and latency.
The inference engine (OnnxModelRunner) auto-detects the model output format at initialization — it supports both YOLO26 (NMS-free, [1, N, 6]) and legacy YOLO11 ([1, 4+C, 8400] with JS-side NMS) for zero-downtime model upgrades.
Technical report: See SG-TR-2026-001 for full training methodology, dataset quality ablation (250× mAP improvement from data curation), and multi-backend deployment roadmap.
Browser Integration
The model is loaded once when the camera view opens and runs inference on each video frame:
// Simplified browser-side detection loop
const session = await ort.InferenceSession.create('/models/yolo26n.onnx');
function detectFrame(canvas: HTMLCanvasElement) {
const tensor = preprocessFrame(canvas, 640, 640);
const results = await session.run({ images: tensor });
const detections = postprocess(results); // no NMS needed
drawOverlay(canvas, detections);
}Browser detection serves as a preview — it provides immediate visual feedback to the operator. Definitive weapon alerts are generated server-side.
Server Detection (YOLOv8n Firearm)
The ingest service runs a fine-tuned YOLOv8n model for server-side weapon detection on full-resolution frames.
| Property | Value |
|---|---|
| Model | YOLOv8n Firearm |
| Source | Subh775/Firearm_Detection_Yolov8n (Hugging Face) |
| Format | ONNX |
| Runtime | ONNX Runtime with CUDA EP |
| Classes | Weapon, Knife, Gun |
| Input | 640x640 RGB |
| Latency | ~4ms per frame (GH200 GPU) |
Training Data
The server model uses the Subh775/Firearm_Detection_Yolov8n checkpoint from Hugging Face. For improved accuracy, both browser and server models can be retrained on the curated Weapon-2 dataset (Roboflow, 3,839 images, CC BY 4.0) which achieves 250× better mAP than the larger but noisier Subh775/WeaponDetection aggregated dataset.
Detection Flow
Camera Frame
|
v
Ingest Service (:8002)
|
+-- Resize to 640x640
+-- Run YOLOv8n Firearm inference
+-- Standard NMS (conf_thresh=0.25, iou_thresh=0.45)
|
v
Detections: [{class: "Gun", confidence: 0.92, bbox: [x1, y1, x2, y2]}]
|
v
Alert System (webhook / dashboard notification)API
POST /v1/weapons
curl -X POST https://api.securegate.dev.satschel.com/v1/weapons \
-H "Authorization: Bearer $TOKEN" \
-F "image=@frame.jpg"Response:
{
"detections": [
{
"class": "Gun",
"confidence": 0.92,
"bbox": [340, 200, 420, 310]
},
{
"class": "Knife",
"confidence": 0.78,
"bbox": [150, 300, 200, 400]
}
],
"weapon_detected": true
}Classes
| Class | Description |
|---|---|
| Weapon | Generic weapon detection (catch-all) |
| Knife | Bladed weapons — knives, machetes, swords |
| Gun | Firearms — handguns, rifles, shotguns |
Configuration
| Variable | Default | Description |
|---|---|---|
WEAPON_CONF_THRESH | 0.25 | Minimum confidence for server detection |
WEAPON_IOU_THRESH | 0.45 | NMS IoU threshold for server detection |
WEAPON_MODEL | yolov8n_firearm | Server-side model name |