SecureGate Docs

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.

PropertyValue
ModelYOLO26n (fine-tuned from COCO)
FormatONNX (9.7 MB, opset 12, FP32)
Runtimeonnxruntime-web (WebGPU → WebGL → WASM)
NMSNMS-free (built into model head)
ClassesWeapon, Knife, Gun
Input640×640 RGB
Precision95.3%
Recall88.2%
mAP@5094.9%
mAP@50-9575.0%
Training66 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.

PropertyValue
ModelYOLOv8n Firearm
SourceSubh775/Firearm_Detection_Yolov8n (Hugging Face)
FormatONNX
RuntimeONNX Runtime with CUDA EP
ClassesWeapon, Knife, Gun
Input640x640 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

ClassDescription
WeaponGeneric weapon detection (catch-all)
KnifeBladed weapons — knives, machetes, swords
GunFirearms — handguns, rifles, shotguns

Configuration

VariableDefaultDescription
WEAPON_CONF_THRESH0.25Minimum confidence for server detection
WEAPON_IOU_THRESH0.45NMS IoU threshold for server detection
WEAPON_MODELyolov8n_firearmServer-side model name

On this page