ANSCustomFireNSmokeDetection: the ANSVIS custom model is judged by ANSMIND's Fire & Smoke verifier

The DLL used to find a detection in one section of the frame, latch a crop
round it and vote on tracked boxes inside that crop. Measured on the field
recordings that was itself the main false-alarm source (the detector needs
context: a floodlight is fake_fire on the whole frame and fire on a tight
crop of the same lamp), and a PTZ tour broke the latch. ANSMIND's native
vision.fire_smoke node replaced it with a whole-frame-first verifier whose
cues are box-relative and carried by global motion, fire-only native zoom
re-checks, a look-alike filter and a ladder of gates measured on real and
false recordings.

The DLL now feeds that verifier, vendored verbatim from ANSMINDCORE dba11ac
(vendor/engine/fire_smoke.hpp, pure C++): ANSLIB runs the package's
detector on the whole frame at a low floor with class-agnostic NMS, the COCO
filter when there is a candidate to explain, and the detector again on the
few native crops the verifier plans; only confirmed tracks come back, as
fire/smoke CustomObjects with fs_seconds/fs_track/evidence in extraInfo.
Parameters: Sensitivity (slider onto low/balanced/high), SmokeSeconds,
DetectFire/DetectSmoke, ZoomChecks, MaxFps (6: evidence is per second of
scene), CandidateScore, MinObjectSize (49a53c3's knob, kept: a candidate
under that fraction of the frame is noise), ExclusiveROIs. Engines load
inside Initialize: a lazily loaded one faulted in ANSLIB's inference entry
on the first frame.

FireNSmokeDetection_Run replays a recording on the video's clock (parity
harness with firesmoke-run). Measured, same package, TensorRT:
  15.9.9.0_9.51_real_smoke   63 alarms, first at 3.0 s (node: 56, 3.0 s)
  15.9.9.51.10.51_real_smoke 113 alarms, first at 3.0 s (node: 126, 3.0 s)
  8 KA false_* clips          0 alarms (node: 0)
Unit tests updated for the new parameter schema; 9/9 pass. The headless
checker from 49a53c3 builds unchanged against the new class.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-11-01 12:15:33 +11:00
co-authored by Claude Fable 5.1
parent 49a53c344e
commit e893be4a75
10 changed files with 2113 additions and 1400 deletions
+113
View File
@@ -0,0 +1,113 @@
// FireNSmokeDetection_Run — replay a recording through the Fire & Smoke
// custom model the way ANSVIS and ans-custom-host would feed it live, on the
// VIDEO's clock, and print each alarm once as it is confirmed. Headless; this
// is the parity harness against ANSMIND's `firesmoke-run` (same verifier).
//
// FireNSmokeDetection_Run <model dir> <video> [--max-fps N] [--sensitivity F]
// [--smoke-seconds N] [--start S] [--end S] [--log]
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
#include "ANSCustomFireNSmoke.h"
int main(int argc, char** argv) {
if (argc < 3) {
std::fprintf(stderr,
"usage: FireNSmokeDetection_Run <model dir> <video> [--max-fps N] [--sensitivity F]\n"
" [--smoke-seconds N] [--start S] [--end S] [--log]\n");
return 2;
}
const std::string modelDir = argv[1];
const std::string video = argv[2];
double maxFps = 6, startS = 0, endS = 1e9;
std::string sensitivity = "0.5", smokeSeconds = "0";
bool log = false;
for (int i = 3; i < argc; ++i) {
const std::string a = argv[i];
auto next = [&](const char* what) -> std::string {
if (i + 1 >= argc) { std::fprintf(stderr, "%s needs a value\n", what); std::exit(2); }
return argv[++i];
};
if (a == "--max-fps") maxFps = std::stod(next("--max-fps"));
else if (a == "--sensitivity") sensitivity = next("--sensitivity");
else if (a == "--smoke-seconds") smokeSeconds = next("--smoke-seconds");
else if (a == "--start") startS = std::stod(next("--start"));
else if (a == "--end") endS = std::stod(next("--end"));
else if (a == "--log") log = true;
else { std::fprintf(stderr, "unknown option %s\n", a.c_str()); return 2; }
}
if (log) _putenv_s("ANSCUSTOM_FS_LOG", "1");
ANSCustomFS model;
std::string labelMap;
const auto t0 = std::chrono::steady_clock::now();
if (!model.Initialize(modelDir, 0.5f, labelMap)) {
std::fprintf(stderr, "Initialize failed for %s\n", modelDir.c_str());
return 1;
}
const double initMs = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count();
std::printf("model %s\nclasses %s\ninit %.0f ms\n", modelDir.c_str(), labelMap.c_str(), initMs);
// Parameters the way the host pushes them: schema from the plugin, values set.
CustomParams params;
model.ConfigureParameters(params);
for (auto& p : params.Parameters) {
if (p.Name == "MaxFps") p.Value = std::to_string(int(maxFps));
else if (p.Name == "Sensitivity") p.Value = sensitivity;
else if (p.Name == "SmokeSeconds") p.Value = smokeSeconds;
}
model.SetParameters(params);
std::printf("rate %.0f fps of video time, sensitivity %s, smoke_seconds %s\n\n", maxFps,
sensitivity.c_str(), smokeSeconds.c_str());
cv::VideoCapture cap(video);
if (!cap.isOpened()) {
std::fprintf(stderr, "cannot open %s\n", video.c_str());
return 1;
}
const double fps = cap.get(cv::CAP_PROP_FPS) > 1 ? cap.get(cv::CAP_PROP_FPS) : 25.0;
long decoded = 0, processed = 0;
double lastT = 0, msSum = 0;
size_t alarms = 0;
std::map<int, double> firstSeen; // track -> first alarm time
std::map<int, double> lastSeen;
cv::Mat frame;
while (cap.read(frame)) {
const double t = double(decoded) / fps;
++decoded;
if (t < startS) continue;
if (t > endS) break;
model.SetFrameClock(t);
const auto a = std::chrono::steady_clock::now();
const std::vector<CustomObject> objs = model.RunInference(frame, "replay");
const double ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - a).count();
// The plugin holds its last verdict between detector runs; count a
// processed frame by the clock the plugin honours.
if (ms > 0.5) { ++processed; msSum += ms; }
for (const auto& o : objs) {
lastSeen[o.trackId] = t;
if (firstSeen.count(o.trackId)) continue;
firstSeen[o.trackId] = t;
++alarms;
std::printf("ALARM %-5s t=%7.2fs track %-4d conf=%.2f box=%d,%d %dx%d %s\n",
o.className.c_str(), t, o.trackId, o.confidence, o.box.x, o.box.y, o.box.width,
o.box.height, o.extraInfo.c_str());
std::fflush(stdout);
}
lastT = t;
}
size_t held = 0;
for (const auto& d : model.LastDebug())
if (!d.confirmed) ++held;
std::printf("\n%ld frames decoded, %ld processed over %.1fs of video - %zu alarm(s), %zu track(s) held back\n",
decoded, processed, lastT, alarms, held);
if (processed) std::printf("per processed frame: %.1f ms mean\n", msSum / double(processed));
return 0;
}