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:
@@ -99,3 +99,18 @@ target_link_libraries(FireNSmokeDetection_HeadlessCheck PRIVATE
|
||||
if(MSVC)
|
||||
target_compile_options(FireNSmokeDetection_HeadlessCheck PRIVATE /W3 /sdl /permissive-)
|
||||
endif()
|
||||
|
||||
# ============================================================================
|
||||
# 4. Headless replay harness on the video's clock (parity with ANSMIND's firesmoke-run)
|
||||
# ============================================================================
|
||||
add_executable(FireNSmokeDetection_Run
|
||||
run_main.cpp
|
||||
)
|
||||
target_compile_features(FireNSmokeDetection_Run PRIVATE cxx_std_17)
|
||||
target_compile_definitions(FireNSmokeDetection_Run PRIVATE ${COMMON_DEFS})
|
||||
target_include_directories(FireNSmokeDetection_Run PRIVATE ${COMMON_INCLUDES})
|
||||
target_link_directories(FireNSmokeDetection_Run PRIVATE ${ANSLIB_LIB_DIR} ${OPENCV_LIB_DIR})
|
||||
target_link_libraries(FireNSmokeDetection_Run PRIVATE ANSLIB opencv_world4130 ANSCustomFireNSmokeDetection)
|
||||
if(MSVC)
|
||||
target_compile_options(FireNSmokeDetection_Run PRIVATE /W3 /sdl /permissive-)
|
||||
endif()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "TestCommon.h"
|
||||
#include <algorithm>
|
||||
#include "ANSCustomFireNSmoke.h"
|
||||
|
||||
// ===========================================================================
|
||||
@@ -48,25 +49,23 @@ TEST_F(FireNSmokeUnitTest, ConfigureParametersReturnsValidConfig) {
|
||||
EXPECT_EQ(params.ROI_Config[0].MinItems, 0);
|
||||
EXPECT_EQ(params.ROI_Config[0].MaxItems, 20);
|
||||
|
||||
// Should have SmokeScore and Sensitivity parameters
|
||||
ASSERT_GE(params.Parameters.size(), 2u);
|
||||
|
||||
bool hasSmokeScore = false;
|
||||
bool hasSensitivity = false;
|
||||
// The verifier's knobs: Sensitivity (0..1 slider onto the node's
|
||||
// low/balanced/high), SmokeSeconds, DetectFire/DetectSmoke, ZoomChecks,
|
||||
// MaxFps, CandidateScore.
|
||||
std::vector<std::string> names;
|
||||
for (const auto& p : params.Parameters) names.push_back(p.Name);
|
||||
for (const char* want : {"Sensitivity", "SmokeSeconds", "DetectFire", "DetectSmoke", "ZoomChecks", "MaxFps", "CandidateScore", "MinObjectSize"})
|
||||
EXPECT_NE(std::find(names.begin(), names.end(), want), names.end()) << "Missing parameter " << want;
|
||||
for (const auto& p : params.Parameters) {
|
||||
if (p.Name == "SmokeScore") {
|
||||
hasSmokeScore = true;
|
||||
if (p.Name == "Sensitivity") {
|
||||
EXPECT_EQ(p.DataType, "float");
|
||||
EXPECT_EQ(p.MaxValue, 1);
|
||||
EXPECT_EQ(p.MinValue, 0);
|
||||
EXPECT_EQ(p.DefaultValue, "0.5");
|
||||
}
|
||||
if (p.Name == "Sensitivity") {
|
||||
hasSensitivity = true;
|
||||
EXPECT_EQ(p.DataType, "float");
|
||||
}
|
||||
if (p.Name == "DetectFire" || p.Name == "DetectSmoke") EXPECT_EQ(p.DataType, "Boolean");
|
||||
if (p.Name == "MaxFps") EXPECT_EQ(p.DefaultValue, "6");
|
||||
}
|
||||
EXPECT_TRUE(hasSmokeScore) << "Missing SmokeScore parameter";
|
||||
EXPECT_TRUE(hasSensitivity) << "Missing Sensitivity parameter";
|
||||
}
|
||||
|
||||
TEST_F(FireNSmokeUnitTest, DestroySucceeds) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user