ANSFR-UnitTest: classroom attribute-overlay demo + v1.1 vs v1.4 benchmark
- ClassroomAttributesVideoTest (default main): plays classroom.mp4 through the v1.4 pipeline and overlays user name, Gender/Age, and Emotion parsed from each result's extra_info JSON; saves an annotated frame every 30 frames to C:\Programs\DemoAssets for headless review. - --bench old|new|both: per-pack speed benchmark (100 measured frames after 10 warmup, full pipeline with attributes on) run one pack per process. RTX 3070 laptop results: v1.1 arcface+OpenVINO 17.8 ms avg (56.2 fps) vs v1.4 adaface+ONNX/TRT 18.2 ms avg (55.1 fps) at 3.1 faces/frame — the new models carry no throughput cost. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1825,8 +1825,261 @@ int TestModelSwitchV14()
|
|||||||
return failures;
|
return failures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
// Classroom video demo — v1.4 pack with face attributes drawn as overlays.
|
||||||
|
// Each face gets its box, user name, and the Gender / Age / Emotion parsed
|
||||||
|
// from the result's extra_info JSON. ESC quits; an annotated frame is saved
|
||||||
|
// every 30 frames to C:\Programs\DemoAssets\ so there is a reviewable
|
||||||
|
// artifact even in headless runs.
|
||||||
|
// ===========================================================================
|
||||||
|
int ClassroomAttributesVideoTest()
|
||||||
|
{
|
||||||
|
const std::string modelZip = "C:\\Programs\\Models\\ANS_FaceRecognizer_v1.4.zip";
|
||||||
|
const std::string detectorZip = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFDET\\ANS_GenericFD(GPU)_v1.0.zip";
|
||||||
|
const std::string dbFile = "C:\\Programs\\DemoAssets\\ANSFRDB\\v14_test\\ANSFR_v14_test.db";
|
||||||
|
const std::string videoPath = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4";
|
||||||
|
const int maxFrames = 600;
|
||||||
|
|
||||||
|
std::cout << "\n===== ClassroomAttributesVideoTest =====" << std::endl;
|
||||||
|
|
||||||
|
ANSCENTER::ANSFacialRecognition* h = nullptr;
|
||||||
|
// age/gender + emotions + head pose ON, liveness/antispoof OFF for speed
|
||||||
|
int cr = CreateANSRFHandle(&h, "", "", dbFile.c_str(), modelZip.c_str(), detectorZip.c_str(),
|
||||||
|
0, 0.35f, 1, 1, 1, 30, 0.5f, 0, 0);
|
||||||
|
std::cout << "CreateANSRFHandle = " << cr << std::endl;
|
||||||
|
if (cr <= 0 || !h) return 1;
|
||||||
|
|
||||||
|
int le = LoadANSRFEngine(&h);
|
||||||
|
std::cout << "LoadANSRFEngine = " << le << std::endl;
|
||||||
|
std::cout << "Model info: " << h->GetActiveModelInfo() << std::endl;
|
||||||
|
if (le != 1) { ReleaseANSRFHandle(&h); return 1; }
|
||||||
|
|
||||||
|
cv::VideoCapture cap(videoPath);
|
||||||
|
if (!cap.isOpened()) {
|
||||||
|
std::cout << "ERROR: cannot open video " << videoPath << std::endl;
|
||||||
|
ReleaseANSRFHandle(&h);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string win = "ANSFR v1.4 - Face Attributes (ESC to quit)";
|
||||||
|
cv::namedWindow(win, cv::WINDOW_NORMAL);
|
||||||
|
cv::resizeWindow(win, 1280, 720);
|
||||||
|
|
||||||
|
int frameIdx = 0, saved = 0;
|
||||||
|
cv::Mat frame;
|
||||||
|
while (cap.read(frame)) {
|
||||||
|
if (frame.empty()) break;
|
||||||
|
if (++frameIdx > maxFrames) break;
|
||||||
|
|
||||||
|
unsigned int bufLen = 0;
|
||||||
|
unsigned char* bytes = ANSCENTER::ANSFRHelper::CVMatToBytes(frame, bufLen);
|
||||||
|
std::string res = RunANSRFInferenceBinary(&h, bytes, frame.cols, frame.rows);
|
||||||
|
delete bytes;
|
||||||
|
|
||||||
|
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 auto name = GetData<std::string>(r, "user_name");
|
||||||
|
const int x = static_cast<int>(GetData<float>(r, "x"));
|
||||||
|
const int y = static_cast<int>(GetData<float>(r, "y"));
|
||||||
|
const int w = static_cast<int>(GetData<float>(r, "width"));
|
||||||
|
const int ht = static_cast<int>(GetData<float>(r, "height"));
|
||||||
|
|
||||||
|
// extra_info is itself a JSON string:
|
||||||
|
// {"attributes":[{"Gender":..,"Age":..,"Emotion":..,"Pose(r,p,y)":..}]}
|
||||||
|
std::string gender, age, emotion;
|
||||||
|
const auto extra = GetData<std::string>(r, "extra_info");
|
||||||
|
if (!extra.empty()) {
|
||||||
|
try {
|
||||||
|
boost::property_tree::ptree ept;
|
||||||
|
std::stringstream ess; ess << extra;
|
||||||
|
boost::property_tree::read_json(ess, ept);
|
||||||
|
if (ept.count("attributes")) {
|
||||||
|
for (const auto& attr : ept.get_child("attributes")) {
|
||||||
|
gender = GetOptionalValue<std::string>(attr.second, "Gender", "");
|
||||||
|
age = GetOptionalValue<std::string>(attr.second, "Age", "");
|
||||||
|
emotion = GetOptionalValue<std::string>(attr.second, "Emotion", "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool known = (name != "Unknown");
|
||||||
|
const cv::Scalar boxColor = known ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 200, 255);
|
||||||
|
cv::rectangle(frame, cv::Rect(x, y, w, ht), boxColor, 2);
|
||||||
|
|
||||||
|
std::vector<std::string> lines;
|
||||||
|
lines.push_back(name);
|
||||||
|
if (!gender.empty() || !age.empty())
|
||||||
|
lines.push_back(gender + " / " + age);
|
||||||
|
if (!emotion.empty())
|
||||||
|
lines.push_back(emotion);
|
||||||
|
|
||||||
|
int ty = y - 8 - 18 * static_cast<int>(lines.size() - 1);
|
||||||
|
for (const auto& line : lines) {
|
||||||
|
cv::putText(frame, line, cv::Point(x, ty),
|
||||||
|
cv::FONT_HERSHEY_SIMPLEX, 0.55, cv::Scalar(0, 0, 0), 3, cv::LINE_AA);
|
||||||
|
cv::putText(frame, line, cv::Point(x, ty),
|
||||||
|
cv::FONT_HERSHEY_SIMPLEX, 0.55, boxColor, 1, cv::LINE_AA);
|
||||||
|
ty += 18;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...) {}
|
||||||
|
|
||||||
|
cv::putText(frame, cv::format("Frame %d", frameIdx), cv::Point(25, 45),
|
||||||
|
cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(0, 255, 255), 2, cv::LINE_AA);
|
||||||
|
|
||||||
|
if (frameIdx % 30 == 0) {
|
||||||
|
std::string fp = cv::format("C:\\Programs\\DemoAssets\\ANSFR_v14_attr_frame_%04d.jpg", frameIdx);
|
||||||
|
cv::imwrite(fp, frame);
|
||||||
|
++saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::imshow(win, frame);
|
||||||
|
if (cv::waitKey(1) == 27) break; // ESC
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Played " << frameIdx << " frames, saved " << saved
|
||||||
|
<< " annotated frames to C:\\Programs\\DemoAssets\\" << std::endl;
|
||||||
|
cap.release();
|
||||||
|
cv::destroyAllWindows();
|
||||||
|
ReleaseANSRFHandle(&h);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
// Speed benchmark — v1.1 (arcface + OpenVINO attributes) vs
|
||||||
|
// v1.4 (adaface + ONNX/TensorRT attributes) on the same classroom video.
|
||||||
|
// Full pipeline per frame (detect + recognize + attributes), attributes ON.
|
||||||
|
// First run of a pack pays its engine builds; those are excluded from the
|
||||||
|
// timing (LoadEngine reported separately, plus warmup frames).
|
||||||
|
// Run one pack per process with: ANSFR-UnitTest.exe --bench old|new
|
||||||
|
// ===========================================================================
|
||||||
|
static void RunSinglePackBenchmark(const std::string& label,
|
||||||
|
const std::string& modelZip, const std::string& dbFolder,
|
||||||
|
int warmupFrames = 10, int measuredFrames = 100)
|
||||||
|
{
|
||||||
|
const std::string videoPath = "C:\\Programs\\DemoAssets\\Videos\\classroom.mp4";
|
||||||
|
const std::string detectorZip = "C:\\ProgramData\\ANSCENTER\\ANSVIS Server\\ANSFDET\\ANS_GenericFD(GPU)_v1.0.zip";
|
||||||
|
|
||||||
|
std::cout << "\n===== BENCH [" << label << "] =====" << std::endl;
|
||||||
|
std::cout << "model pack: " << modelZip << std::endl;
|
||||||
|
|
||||||
|
std::error_code ec;
|
||||||
|
std::filesystem::remove_all(dbFolder, ec);
|
||||||
|
const std::string dbFile = dbFolder + "\\bench.db";
|
||||||
|
|
||||||
|
ANSCENTER::ANSFacialRecognition* h = nullptr;
|
||||||
|
int cr = CreateANSRFHandle(&h, "", "", dbFile.c_str(), modelZip.c_str(), detectorZip.c_str(),
|
||||||
|
0, 0.35f, 1, 1, 1, 30, 0.5f, 0, 0);
|
||||||
|
if (cr <= 0 || !h) {
|
||||||
|
std::cout << "[BENCH " << label << "] CreateANSRFHandle FAILED: " << cr << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto loadStart = std::chrono::steady_clock::now();
|
||||||
|
int le = LoadANSRFEngine(&h);
|
||||||
|
auto loadMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
std::chrono::steady_clock::now() - loadStart).count();
|
||||||
|
std::cout << "LoadANSRFEngine = " << le << " (" << loadMs << " ms)" << std::endl;
|
||||||
|
std::cout << "Model info: " << h->GetActiveModelInfo() << std::endl;
|
||||||
|
if (le != 1) { ReleaseANSRFHandle(&h); return; }
|
||||||
|
|
||||||
|
cv::VideoCapture cap(videoPath);
|
||||||
|
if (!cap.isOpened()) {
|
||||||
|
std::cout << "ERROR: cannot open video " << videoPath << std::endl;
|
||||||
|
ReleaseANSRFHandle(&h);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double totalMs = 0.0, minMs = 1e9, maxMs = 0.0;
|
||||||
|
long long totalFaces = 0;
|
||||||
|
int measured = 0, frameIdx = 0;
|
||||||
|
cv::Mat frame;
|
||||||
|
while (cap.read(frame) && measured < measuredFrames) {
|
||||||
|
if (frame.empty()) break;
|
||||||
|
++frameIdx;
|
||||||
|
|
||||||
|
unsigned int bufLen = 0;
|
||||||
|
unsigned char* bytes = ANSCENTER::ANSFRHelper::CVMatToBytes(frame, bufLen);
|
||||||
|
|
||||||
|
auto t0 = std::chrono::steady_clock::now();
|
||||||
|
std::string res = RunANSRFInferenceBinary(&h, bytes, frame.cols, frame.rows);
|
||||||
|
double ms = std::chrono::duration<double, std::milli>(
|
||||||
|
std::chrono::steady_clock::now() - t0).count();
|
||||||
|
delete bytes;
|
||||||
|
|
||||||
|
if (frameIdx <= warmupFrames) continue; // engine warmup / TRT autotuning
|
||||||
|
|
||||||
|
++measured;
|
||||||
|
totalMs += ms;
|
||||||
|
minMs = (std::min)(minMs, ms);
|
||||||
|
maxMs = (std::max)(maxMs, ms);
|
||||||
|
|
||||||
|
// rough face count for context
|
||||||
|
size_t pos = 0;
|
||||||
|
while ((pos = res.find("\"user_name\"", pos)) != std::string::npos) {
|
||||||
|
++totalFaces; pos += 11;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cap.release();
|
||||||
|
|
||||||
|
if (measured > 0) {
|
||||||
|
const double avg = totalMs / measured;
|
||||||
|
std::cout << std::fixed << std::setprecision(1);
|
||||||
|
std::cout << "[BENCH " << label << "] frames=" << measured
|
||||||
|
<< " avg=" << avg << " ms"
|
||||||
|
<< " min=" << minMs << " ms"
|
||||||
|
<< " max=" << maxMs << " ms"
|
||||||
|
<< " fps=" << (1000.0 / avg)
|
||||||
|
<< " avg faces/frame=" << (double)totalFaces / measured
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "[BENCH " << label << "] no frames measured" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReleaseANSRFHandle(&h);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ModelSpeedBenchmark()
|
||||||
|
{
|
||||||
|
RunSinglePackBenchmark("v1.1 arcface + OpenVINO attrs",
|
||||||
|
"C:\\Projects\\SharedCore\\ANS_FaceRecognizer_v1.1.zip",
|
||||||
|
"C:\\Programs\\DemoAssets\\ANSFRDB\\v11_bench");
|
||||||
|
RunSinglePackBenchmark("v1.4 adaface + ONNX attrs",
|
||||||
|
"C:\\Programs\\Models\\ANS_FaceRecognizer_v1.4.zip",
|
||||||
|
"C:\\Programs\\DemoAssets\\ANSFRDB\\v14_bench");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
// Single-pack benchmark mode (one pack per process so the packs cannot
|
||||||
|
// influence each other): ANSFR-UnitTest.exe --bench old|new|both
|
||||||
|
if (argc >= 3 && std::string(argv[1]) == "--bench") {
|
||||||
|
const std::string which = argv[2];
|
||||||
|
if (which == "old")
|
||||||
|
RunSinglePackBenchmark("v1.1 arcface + OpenVINO attrs",
|
||||||
|
"C:\\Projects\\SharedCore\\ANS_FaceRecognizer_v1.1.zip",
|
||||||
|
"C:\\Programs\\DemoAssets\\ANSFRDB\\v11_bench");
|
||||||
|
else if (which == "new")
|
||||||
|
RunSinglePackBenchmark("v1.4 adaface + ONNX attrs",
|
||||||
|
"C:\\Programs\\Models\\ANS_FaceRecognizer_v1.4.zip",
|
||||||
|
"C:\\Programs\\DemoAssets\\ANSFRDB\\v14_bench");
|
||||||
|
else
|
||||||
|
ModelSpeedBenchmark();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ── GPU visibility bisect (Blackwell Myelin l2cm debugging) ─────────────
|
// ── GPU visibility bisect (Blackwell Myelin l2cm debugging) ─────────────
|
||||||
// Usage: ANSFR-UnitTest.exe --gpu 0 → only GPU0 visible (Test A, display GPU)
|
// Usage: ANSFR-UnitTest.exe --gpu 0 → only GPU0 visible (Test A, display GPU)
|
||||||
// ANSFR-UnitTest.exe --gpu 1 → only GPU1 visible (Test B, headless GPU)
|
// ANSFR-UnitTest.exe --gpu 1 → only GPU1 visible (Test B, headless GPU)
|
||||||
@@ -1847,7 +2100,8 @@ int main(int argc, char** argv)
|
|||||||
//FaceDetectorTest();
|
//FaceDetectorTest();
|
||||||
//TestFaceRecognition();
|
//TestFaceRecognition();
|
||||||
//TestCompleteFR1();
|
//TestCompleteFR1();
|
||||||
TestModelSwitchV14();
|
//TestModelSwitchV14();
|
||||||
|
ClassroomAttributesVideoTest();
|
||||||
//ANSVISTest();
|
//ANSVISTest();
|
||||||
//ANSVISImageTest();
|
//ANSVISImageTest();
|
||||||
//ANSVISTest();
|
//ANSVISTest();
|
||||||
|
|||||||
Reference in New Issue
Block a user