Vaibhav Nakrani
← WorkLog 04 / 11Vision

Weapons detection on 4K CCTV

Find knives, guns, rifles and bats in 4K security footage, in real time. The client asked for an RTX 5090. It runs on a 3060.

Use
Deployed with the South Korean police
Role
Sole ML engineer, freelance
When
October 2025 – January 2026
Stack
YOLO11, TensorRT, ByteTrack, cleanlab, SAM 3, Captum
30 fps4K video on an RTX 3060, measured by the client
0.948mAP50 on a held-out test set of 1,396 weapons
17,490images checked for label errors, twice
4classes: knife, gun, rifle, baseball bat
How it works

Security cameras record in 4K, and in a picture that size a knife can be just a few dozen dots across. Checking every dot of every frame is too slow. Shrinking the frame makes the knife vanish.

So the system finds the people first, on a shrunken copy of the frame. Each person is then cut out of the original, sharp frame, and the weapon search runs on those cut-outs only. I tried a bigger model early on and it scored no better, so the model stayed mid-sized and my time went into the training pictures. A mid-sized model is also why this runs smoothly on a modest graphics card.

Problems and fixes

One-frame scares. A shadow or a phone can look like a gun for a single frame. An alarm now needs the same thing to show up for several frames in a row, and each person is followed for a few seconds so the system remembers what it saw.

Mistakes in the training labels. Some weapons had never been marked, and some were marked as the wrong kind. I let the model point at pictures where it disagreed with the label and went through those by hand. A second small model that sees only the cut-out weapon was better at catching rifles marked as guns.

Lots of guns, few bats. The set had far more guns than baseball bats, so bats were found poorly. After evening out the numbers, bats became the best-detected class.

People holding ordinary things. A phone or an umbrella is held much like a weapon. I collected clips from the real cameras of people carrying everyday things and trained on them as “no weapon”. False alarms dropped.

Heat maps that pointed at nothing. I wanted pictures showing where the model looks. The two usual tools gave stripes and blobs away from the weapon, because they were built for older models. The slow way worked: hide one small patch at a time and see how much the model's confidence drops. The maps below were made that way.

What it looks like
Fig. 1The detector on sample footage. Faces are blurred.
Person holding a gunHeat map for the gun Person holding a knifeHeat map for the knife
Fig. 2Where the model looks. For a gun, tightly on the weapon. For a knife, up the hand and forearm too.
Walkthrough

The seven-minute version, in my own words.

Working on something like this? Message me on LinkedIn → or email nakranivaibhav14@gmail.com