ANSFR: configurable slow-attribute refresh interval

New API SetANSRFAttributeInterval(Handle, frames) / UpdateAttributeInterval
(1..60, default 5) controls how often the slow attributes (age/gender +
emotions) refresh per camera; head pose and recognition are unaffected.
GetANSRFModelInfo now reports "attribute_interval". The adaptive logic's
stable-scene branch previously capped at a hardcoded 10 - it now doubles
the configured interval instead (default behaviour 10/5/2 unchanged).

Motivation: the v1.4 ViT age-gender model is heavier per attribute frame
than the old OpenVINO IR. Interval sweep on RTX 3070 (classroom.mp4,
~3.1 faces/frame) vs the v1.1 baseline at 16.0 ms / 62 fps:
  interval  5 (default): 19.9 ms / 50 fps  (+3.9 ms)
  interval 10:           17.1 ms / 58 fps  (+1.1 ms)
  interval 20:           16.5 ms / 61 fps  (parity)
Recommendation: default on 8 GB GPUs; interval 10 on small-VRAM machines.

ANSFR-UnitTest: --bench old|new [interval] runs the sweep.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 01:57:54 +10:00
co-authored by Claude Fable 5
parent 89b2efe182
commit f34817c620
4 changed files with 63 additions and 8 deletions
+20 -2
View File
@@ -1348,6 +1348,22 @@ namespace ANSCENTER {
}
}
bool ANSFacialRecognition::UpdateAttributeInterval(int frames) {
if (frames < 1 || frames > 60) {
LogThreadSafe("ANSFacialRecognition::UpdateAttributeInterval",
"Invalid interval " + std::to_string(frames) + " (expected 1..60)");
return false;
}
{
std::lock_guard<std::mutex> lock(_configMutex);
_attributeInterval = frames;
}
LogThreadSafe("ANSFacialRecognition::UpdateAttributeInterval",
"Attribute refresh interval set to " + std::to_string(frames) + " frames",
LogLevel::Info);
return true;
}
int ANSFacialRecognition::GetRecognizerModelType() const {
return static_cast<int>(_recognizer ? _activeRecModel : _requestedRecModel);
}
@@ -1373,6 +1389,7 @@ namespace ANSCENTER {
info["recognizer_loaded"] = (_recognizer != nullptr);
info["agegender_backend"] = agegenderBackend;
info["emotion_backend"] = emotionBackend;
info["attribute_interval"] = _attributeInterval;
return info.dump();
}
catch (const std::exception& e) {
@@ -3072,9 +3089,10 @@ namespace ANSCENTER {
}
camDataPtr->previousTrackIdCount = currentTrackIdCount;
// Adapt interval: stable scene → increase (max 10), changes → decrease (min 2)
// Adapt interval: stable scene → double the configured
// interval, changes → decrease (min 2)
if (camDataPtr->stableFrameCount > 30) {
camDataPtr->currentAttributeInterval = std::min(10, _attributeInterval * 2);
camDataPtr->currentAttributeInterval = _attributeInterval * 2;
} else if (camDataPtr->stableFrameCount > 10) {
camDataPtr->currentAttributeInterval = _attributeInterval;
} else {
+13
View File
@@ -98,6 +98,13 @@ namespace ANSCENTER
bool UpdateFaceQueue(int queueSize, int faceThresholdSize, bool enableFaceQueue);
bool GetFaceQueue(int& queueSize, int& faceThresholdSize, bool& enableFaceQueue);
// How often the slow attributes (age/gender + emotions) refresh:
// every N frames per camera (1 = every frame). Head pose still runs
// every frame. The adaptive logic doubles N on stable scenes and
// halves it (min 2) when faces appear/disappear. Default 5.
bool UpdateAttributeInterval(int frames);
int GetAttributeInterval() const { return _attributeInterval; }
// Recognizer model switching (0 = AdaFace [default], 1 = ArcFace).
// Before LoadEngine: just records the preference. After LoadEngine:
// re-initializes the recognizer, regenerates every stored embedding
@@ -391,6 +398,12 @@ extern "C" ANSFR_API int GetANSRFRecognizerModel(ANSCENTER::ANSFacialRe
// JSON describing the loaded models, e.g.
// {"recognizer_model":"adaface","agegender_backend":"onnx","emotion_backend":"onnx",...}
extern "C" ANSFR_API int GetANSRFModelInfo(ANSCENTER::ANSFacialRecognition** Handle, LStrHandle modelInfo);
// Slow-attribute (age/gender + emotions) refresh interval in frames per
// camera (1 = every frame, default 5; clamped to [1, 60]). Larger values
// cut the attribute-model GPU cost proportionally at the price of slower
// attribute updates — useful on smaller GPUs with the heavier v1.4 ONNX
// age-gender model. Returns 1 on success, -1 on invalid arguments.
extern "C" ANSFR_API int SetANSRFAttributeInterval(ANSCENTER::ANSFacialRecognition** Handle, int frames);
+12
View File
@@ -1330,6 +1330,18 @@ extern "C" ANSFR_API int GetANSRFModelInfo(ANSCENTER::ANSFacialRecognit
}
}
extern "C" ANSFR_API int SetANSRFAttributeInterval(ANSCENTER::ANSFacialRecognition** Handle, int frames) {
ANS_DBG("ANSFR","SetANSRFAttributeInterval: HandlePtr=%p, *Handle=%p, frames=%d",
(void*)Handle, (void*)(Handle ? *Handle : nullptr), frames);
try {
if (!Handle || !*Handle) return -1;
return (*Handle)->UpdateAttributeInterval(frames) ? 1 : -1;
}
catch (const std::exception&) {
return -1;
}
}
extern "C" ANSFR_API int RunInferenceComplete_LV(
ANSCENTER::ANSFacialRecognition** Handle,
cv::Mat** cvImage,