Throttle face recognition in full pipeline
This commit is contained in:
parent
fc1f3af81f
commit
b7a7810c26
@ -69,6 +69,8 @@
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [4],
|
||||
"infer_fps": 2,
|
||||
"infer_phase_ms": 120,
|
||||
"model_path": "./models/mobilefacenet_arcface.rknn",
|
||||
"align": true,
|
||||
"emit_embedding": false,
|
||||
|
||||
@ -644,6 +644,20 @@ public:
|
||||
bool Init(const SimpleJson& config, const NodeContext& ctx) override {
|
||||
id_ = config.ValueOr<std::string>("id", "face_recog");
|
||||
model_path_ = config.ValueOr<std::string>("model_path", "");
|
||||
infer_interval_ms_ = std::max<int64_t>(
|
||||
0, static_cast<int64_t>(config.ValueOr<int>("infer_interval_ms", 0)));
|
||||
if (infer_interval_ms_ <= 0) {
|
||||
const double infer_fps = config.ValueOr<double>("infer_fps", 0.0);
|
||||
if (infer_fps > 0.0) {
|
||||
infer_interval_ms_ = static_cast<int64_t>(1000.0 / infer_fps);
|
||||
if (infer_interval_ms_ < 1) infer_interval_ms_ = 1;
|
||||
}
|
||||
}
|
||||
infer_phase_ms_ = std::max<int64_t>(
|
||||
0, static_cast<int64_t>(config.ValueOr<int>("infer_phase_ms", 0)));
|
||||
if (infer_interval_ms_ > 0 && infer_phase_ms_ >= infer_interval_ms_) {
|
||||
infer_phase_ms_ %= infer_interval_ms_;
|
||||
}
|
||||
std::shared_ptr<const FaceRecogConfigSnapshot> snap;
|
||||
BuildFaceRecogConfigSnapshot(config, nullptr, snap);
|
||||
{
|
||||
@ -706,7 +720,9 @@ public:
|
||||
const float thr_accept = cfg ? cfg->thr_accept : 0.0f;
|
||||
const float thr_margin = cfg ? cfg->thr_margin : 0.0f;
|
||||
LogInfo("[ai_face_recog] start id=" + id_ + " align=" + std::string(align ? "true" : "false") +
|
||||
" thr_accept=" + std::to_string(thr_accept) + " thr_margin=" + std::to_string(thr_margin));
|
||||
" thr_accept=" + std::to_string(thr_accept) +
|
||||
" thr_margin=" + std::to_string(thr_margin) +
|
||||
" infer_interval_ms=" + std::to_string(infer_interval_ms_));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -763,6 +779,16 @@ public:
|
||||
if (!frame) return NodeStatus::DROP;
|
||||
|
||||
#if defined(RK3588_ENABLE_RKNN)
|
||||
if (infer_interval_ms_ > 0 && frame->pts > 0) {
|
||||
const int64_t pts_ms = static_cast<int64_t>(frame->pts / 1000ULL);
|
||||
const int64_t effective_pts_ms = pts_ms + infer_phase_ms_;
|
||||
const int64_t delta_ms = effective_pts_ms - last_infer_pts_ms_;
|
||||
if (last_infer_pts_ms_ > 0 && delta_ms > 0 && delta_ms < infer_interval_ms_) {
|
||||
Push(frame);
|
||||
return NodeStatus::OK;
|
||||
}
|
||||
last_infer_pts_ms_ = effective_pts_ms;
|
||||
}
|
||||
Run(frame);
|
||||
#endif
|
||||
Push(frame);
|
||||
@ -958,6 +984,9 @@ private:
|
||||
ModelHandle model_handle_ = kInvalidModelHandle;
|
||||
int model_w_ = 112;
|
||||
int model_h_ = 112;
|
||||
int64_t infer_interval_ms_ = 0;
|
||||
int64_t infer_phase_ms_ = 0;
|
||||
int64_t last_infer_pts_ms_ = 0;
|
||||
};
|
||||
|
||||
REGISTER_NODE(AiFaceRecogNode, "ai_face_recog");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user