Prevent OOM
This commit is contained in:
@@ -1631,6 +1631,88 @@ int TestCompleteFR1() {
|
||||
std::cout << "End of program.\n";
|
||||
return 1;
|
||||
}
|
||||
// ---- SCRFD-TRT face-detection reproduction on a video (headless) ----------
|
||||
int SCRFDVideoRepro()
|
||||
{
|
||||
std::string licenseKey = "";
|
||||
const char* configFilePath = "";
|
||||
std::string databaseFilePath = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFR\\ANSFR.db";
|
||||
std::string recognizerFile = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFR\\ServerOptimised\\ANS_FaceRecognizer_v1.1_NVIDIAGeForceRTX3070LaptopGPU.zip";
|
||||
std::string detectorFile = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFDET\\ServerOptimised\\ANS_GenericFD(GPU)_v1.0_NVIDIAGeForceRTX3070LaptopGPU.zip";
|
||||
std::string videoPath = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4";
|
||||
|
||||
std::cout << "[REPRO] detector = " << detectorFile << std::endl;
|
||||
std::cout << "[REPRO] recognizer = " << recognizerFile << std::endl;
|
||||
|
||||
ANSCENTER::ANSFacialRecognition* h = nullptr;
|
||||
int cr = CreateANSRFHandle(&h, licenseKey.c_str(), configFilePath,
|
||||
databaseFilePath.c_str(), recognizerFile.c_str(),
|
||||
detectorFile.c_str(), 0.3, 1, 1, 1);
|
||||
std::cout << "[REPRO] CreateANSRFHandle = " << cr << std::endl;
|
||||
|
||||
int le = LoadANSRFEngine(&h);
|
||||
std::cout << "[REPRO] LoadANSRFEngine = " << le << std::endl;
|
||||
|
||||
cv::VideoCapture cap(videoPath);
|
||||
if (!cap.isOpened()) { std::cout << "[REPRO] ERROR: cannot open video " << videoPath << std::endl; return 1; }
|
||||
|
||||
const std::string win = "ANSFR - SCRFD/TensorRT Face Detection (ESC to quit)";
|
||||
cv::namedWindow(win, cv::WINDOW_NORMAL);
|
||||
cv::resizeWindow(win, 1280, 720);
|
||||
|
||||
int frameIdx = 0, totalDet = 0, saved = 0;
|
||||
cv::Mat frame;
|
||||
while (cap.read(frame)) {
|
||||
if (frame.empty()) break;
|
||||
++frameIdx;
|
||||
if (frameIdx > 300) break; // proof run: first 300 frames
|
||||
unsigned int bufLen = 0;
|
||||
unsigned char* jpg = ANSCENTER::ANSFRHelper::CVMatToBytes(frame, bufLen);
|
||||
std::string res = RunANSRFInferenceBinary(&h, jpg, frame.cols, frame.rows);
|
||||
delete jpg;
|
||||
|
||||
int n = 0;
|
||||
try {
|
||||
boost::property_tree::ptree pt; std::stringstream ss; ss << res;
|
||||
boost::property_tree::read_json(ss, pt);
|
||||
if (pt.count("results")) {
|
||||
BOOST_FOREACH(const boost::property_tree::ptree::value_type& child, pt.get_child("results")) {
|
||||
const boost::property_tree::ptree& r = child.second;
|
||||
const int uid = GetData<int>(r, "user_id");
|
||||
const std::string uname = GetData<std::string>(r, "user_name");
|
||||
const float x = GetData<float>(r, "x");
|
||||
const float y = GetData<float>(r, "y");
|
||||
const float w = GetData<float>(r, "width");
|
||||
const float ht = GetData<float>(r, "height");
|
||||
cv::rectangle(frame, cv::Rect((int)x, (int)y, (int)w, (int)ht), cv::Scalar(0, 255, 0), 2);
|
||||
cv::putText(frame, cv::format("%s:%d", uname.c_str(), uid), cv::Point((int)x, (int)y - 8),
|
||||
cv::FONT_HERSHEY_SIMPLEX, 0.7, cv::Scalar(0, 0, 255), 2, cv::LINE_AA);
|
||||
++n;
|
||||
}
|
||||
}
|
||||
} catch (...) {}
|
||||
totalDet += n;
|
||||
|
||||
cv::putText(frame, cv::format("Frame %d faces detected = %d", frameIdx, n),
|
||||
cv::Point(25, 45), cv::FONT_HERSHEY_SIMPLEX, 1.1, cv::Scalar(0, 255, 255), 2, cv::LINE_AA);
|
||||
if (frameIdx % 30 == 0) {
|
||||
std::string fp = cv::format("C:\\Programs\\DemoAssets\\ANSFR_proof_frame_%04d_faces%d.jpg", frameIdx, n);
|
||||
cv::imwrite(fp, frame);
|
||||
++saved;
|
||||
std::cout << "[REPRO] saved annotated frame: " << fp << std::endl;
|
||||
}
|
||||
cv::imshow(win, frame);
|
||||
if (cv::waitKey(1) == 27) break; // ESC to quit
|
||||
}
|
||||
std::cout << "[REPRO] played " << frameIdx << " frames, total faces drawn = " << totalDet
|
||||
<< ", saved " << saved << " annotated images to C:\\Programs\\DemoAssets\\" << std::endl;
|
||||
cap.release();
|
||||
cv::destroyAllWindows();
|
||||
// NOTE: intentionally skipping ReleaseANSRFHandle/cudaDeviceReset here — there is
|
||||
// a known C++ exception at teardown (0xE06D7363); process exit reclaims everything.
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
@@ -1653,8 +1735,7 @@ int main()
|
||||
// TestCompleteFR();
|
||||
//TestFaceRecognition();
|
||||
//FaceRecognitionBenchmark();
|
||||
ANSVISTestCPU_Lightweight();
|
||||
//ANSVISTestCPU();
|
||||
std::cin.get();
|
||||
SCRFDVideoRepro();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1647,6 +1647,9 @@ int HelmetDetectionTest() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// ElasticGPUTest — Verify elastic pool, round-robin dispatch, multi-GPU,
|
||||
// concurrent inference, and idle-slot cleanup.
|
||||
@@ -2222,14 +2225,24 @@ int RTMPOSETest() {
|
||||
VideoDetectorEngine(onnxclmodelFilePath, videoFile, modelType);// 22 is RT, 21 is onnx
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FireNSmokeTest() {
|
||||
int modelType = 16; // Custom model type for helmet detection, adjust as needed based on how the model is set up in the engine
|
||||
std::string onnxclmodelFilePath = "C:\\Projects\\ANSVIS\\Models\\ANS_FireSmoke_v2.0\\ANS_FireSmoke_v2.0.zip";
|
||||
std::string videoFile = "E:\\Programs\\DemoAssets\\Videos\\FireNSmoke\\BCA1.mp4";
|
||||
|
||||
VideoDetectorEngine(onnxclmodelFilePath, videoFile, modelType);// 22 is RT, 21 is onnx
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
//FallDetectorTest();
|
||||
//ALPROD_Test();
|
||||
//FireNSmokeTest();
|
||||
FireNSmokeTest();
|
||||
//ElasticGPUTest();
|
||||
RTMPOSETest_CPP();
|
||||
//RTMPOSETest_CPP();
|
||||
//RTMPOSETest();
|
||||
//YOLO26SEGYolo11Test();
|
||||
//YOLO26POSEYolo11Test();
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// windows.h must be included before any header that pulls in wincrypt.h
|
||||
// (Chilkat, OpenCV transitively). HKEY/RegOpenKeyExW are used by the
|
||||
// watermark readout in GetEventLogErrorsWatermarkTest.
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
#include "ANSUtilities.h"
|
||||
#include "ANSLLM.h"
|
||||
@@ -489,20 +493,123 @@ int GetEventLogErrorsTest()
|
||||
std::cout << "\nGetANSLoggerErrorEventsCpp rc=" << rc
|
||||
<< " bytes=" << fromExtern.size() << std::endl;
|
||||
|
||||
// ── 4. (DANGER) clear the Application channel after reading ─────────────
|
||||
// Uncomment ONLY if you actually want to wipe every event from every
|
||||
// source in the Application log (not just ANSLogger). Run as Admin or
|
||||
// the clear silently fails (the read still succeeds either way).
|
||||
//
|
||||
// std::string cleared;
|
||||
// int rcClear = GetANSLoggerErrorEventsCpp(1 /* clearAfterRead */, cleared);
|
||||
// std::cout << "After clear: rc=" << rcClear
|
||||
// << " events returned=" << std::count(cleared.begin(), cleared.end(), '\n')
|
||||
// << " (next call should report 0)" << std::endl;
|
||||
// ── 4. DIAGNOSTIC: read → read+clear → read, prove whether the clear
|
||||
// flag actually does anything (and if not, capture the OS error).
|
||||
{
|
||||
std::cout << "\n--- clear-flag diagnostic ---" << std::endl;
|
||||
auto countLines = [](const std::string& s) {
|
||||
int n = 0;
|
||||
for (char c : s) if (c == '\n') ++n;
|
||||
return n;
|
||||
};
|
||||
|
||||
std::string before = ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents(false);
|
||||
std::cout << " before clear : " << countLines(before) << " events" << std::endl;
|
||||
|
||||
std::string cleared = ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents(true);
|
||||
std::cout << " with clear=true call returned: "
|
||||
<< countLines(cleared) << " events" << std::endl;
|
||||
|
||||
std::string after = ANSCENTER::ANSUtilities::GetANSLoggerErrorEvents(false);
|
||||
std::cout << " after clear : " << countLines(after)
|
||||
<< " events (should be 0 if clear worked)" << std::endl;
|
||||
|
||||
const int beforeN = countLines(before);
|
||||
const int afterN = countLines(after);
|
||||
if (beforeN == 0) {
|
||||
std::cout << " RESULT: inconclusive (no events to clear). "
|
||||
"Check stderr above for the actual EvtClearLog status."
|
||||
<< std::endl;
|
||||
} else if (afterN == 0) {
|
||||
std::cout << " RESULT: clear SUCCEEDED — process was elevated."
|
||||
<< std::endl;
|
||||
} else if (afterN >= beforeN) {
|
||||
std::cout << " RESULT: clear FAILED. "
|
||||
"Check stderr above for the GetLastError code "
|
||||
"(5 = ACCESS_DENIED — re-run as Administrator)."
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << " RESULT: partial clear (" << beforeN << " -> "
|
||||
<< afterN << "). Likely a concurrent writer."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Example: ANSCENTER::ANSUtilities::GetANSLoggerErrorEventsSinceLastCall
|
||||
//
|
||||
// Watermark-based variant. Two consecutive calls demonstrate the skip:
|
||||
// 1st call: returns every Error event from ANSLogger (same as the full read)
|
||||
// 2nd call: returns 0 (or only events written between the two calls)
|
||||
// The watermark is stored at
|
||||
// HKCU\Software\ANSCENTER\ANSUtilities\EventLogWatermark\ANSLogger (REG_QWORD)
|
||||
// To force a re-read of everything, delete that registry value.
|
||||
// ============================================================================
|
||||
int GetEventLogErrorsWatermarkTest()
|
||||
{
|
||||
std::cout << "\n===== GetANSLoggerErrorEventsSinceLastCall (watermark) ====="
|
||||
<< std::endl;
|
||||
auto countLines = [](const std::string& s) {
|
||||
int n = 0;
|
||||
for (char c : s) if (c == '\n') ++n;
|
||||
return n;
|
||||
};
|
||||
|
||||
// Read the current watermark so we can show it before and after.
|
||||
auto readWatermark = []() -> unsigned long long {
|
||||
HKEY hKey = nullptr;
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
||||
L"Software\\ANSCENTER\\ANSUtilities\\EventLogWatermark",
|
||||
0, KEY_READ, &hKey) != ERROR_SUCCESS) return 0ULL;
|
||||
unsigned long long v = 0;
|
||||
DWORD sz = sizeof(v), tp = 0;
|
||||
LONG rc = RegQueryValueExW(hKey, L"ANSLogger", nullptr, &tp,
|
||||
reinterpret_cast<LPBYTE>(&v), &sz);
|
||||
RegCloseKey(hKey);
|
||||
return (rc == ERROR_SUCCESS && tp == REG_QWORD) ? v : 0ULL;
|
||||
};
|
||||
|
||||
std::cout << " watermark before: " << readWatermark() << std::endl;
|
||||
|
||||
std::string first =
|
||||
ANSCENTER::ANSUtilities::GetANSLoggerErrorEventsSinceLastCall(false);
|
||||
std::cout << " 1st call returned: " << countLines(first) << " event(s)"
|
||||
<< std::endl;
|
||||
std::cout << " watermark after 1st call: " << readWatermark() << std::endl;
|
||||
|
||||
std::string second =
|
||||
ANSCENTER::ANSUtilities::GetANSLoggerErrorEventsSinceLastCall(false);
|
||||
std::cout << " 2nd call returned: " << countLines(second)
|
||||
<< " event(s) (should be 0 if no new errors were logged "
|
||||
"between the two calls)" << std::endl;
|
||||
|
||||
if (countLines(second) == 0 && countLines(first) > 0) {
|
||||
std::cout << " RESULT: watermark works — duplicates suppressed."
|
||||
<< std::endl;
|
||||
} else if (countLines(first) == 0) {
|
||||
std::cout << " RESULT: nothing to test (no ANSLogger errors in log)."
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << " RESULT: 2nd call returned " << countLines(second)
|
||||
<< " event(s) — either new errors arrived between calls, "
|
||||
"or the watermark didn't persist." << std::endl;
|
||||
}
|
||||
|
||||
// Note: passing the LabVIEW extern below as well so its parameter wiring
|
||||
// is exercised. Pass 0 = no clear; clear path is identical to the
|
||||
// already-tested admin-required version in GetEventLogErrorsTest.
|
||||
std::string fromExtern;
|
||||
int rc = GetANSLoggerErrorEventsSinceLastCallCpp(0, fromExtern);
|
||||
std::cout << " GetANSLoggerErrorEventsSinceLastCallCpp rc=" << rc
|
||||
<< " bytes=" << fromExtern.size()
|
||||
<< " (should be 0 — already watermarked above)" << std::endl;
|
||||
|
||||
return countLines(first);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//ANSLLMOllamaTest();
|
||||
@@ -519,5 +626,6 @@ int main()
|
||||
|
||||
ScanDevicesTest();
|
||||
GetEventLogErrorsTest();
|
||||
GetEventLogErrorsWatermarkTest();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user