From dd1f41940696f60e6821f74e1fae1de6da6afdf8 Mon Sep 17 00:00:00 2001 From: sladro Date: Wed, 7 Jan 2026 17:44:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=BA=E8=84=B8=E7=94=BB?= =?UTF-8?q?=E6=A1=862?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/ai_face_det/ai_face_det_node.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/ai_face_det/ai_face_det_node.cpp b/plugins/ai_face_det/ai_face_det_node.cpp index 6f89b1c..1127e76 100644 --- a/plugins/ai_face_det/ai_face_det_node.cpp +++ b/plugins/ai_face_det/ai_face_det_node.cpp @@ -163,6 +163,8 @@ bool ExtractNc(const Tensor& t, int c, NcTensor& out) { int n = 0; enum class Layout { FlatNc, CxN, NCHW, NHWC } layout = Layout::FlatNc; int dN = 1, dH = 1, dW = 1; + const bool tried_shape = (t.dims.size() == 2 || t.dims.size() == 3 || t.dims.size() == 4); + if (t.dims.size() == 3) { // Common: [1, C, N] or [1, N, C] const uint32_t d1 = t.dims[1]; @@ -208,6 +210,12 @@ bool ExtractNc(const Tensor& t, int c, NcTensor& out) { } } + // IMPORTANT: when dims are present but don't match the requested channel count, + // do NOT fallback to element-count heuristics (it will mis-classify tensors). + if (tried_shape && n <= 0) { + return false; + } + if (n <= 0) { if (elem_cnt % static_cast(c) != 0) return false; n = static_cast(elem_cnt / static_cast(c)); @@ -598,6 +606,9 @@ private: det.model_name = "retinaface"; DecodeRetinaFace(tensors, src_w, src_h, in_w, in_h, det); + if (!logged_decode_.exchange(true)) { + LogInfo("[ai_face_det] decoded faces=" + std::to_string(det.faces.size())); + } frame->face_det = std::make_shared(std::move(det)); } @@ -628,6 +639,11 @@ private: continue; } } + if (!logged_decode_detail_.exchange(true)) { + LogInfo("[ai_face_det] decode tensors: loc_parts=" + std::to_string(locs.size()) + + " conf_parts=" + std::to_string(confs.size()) + + " lmk_parts=" + std::to_string(landms.size())); + } if (locs.empty() || confs.empty()) return; // Concatenate along N. @@ -783,6 +799,8 @@ private: uint32_t n_output_ = 0; std::atomic logged_io_{false}; + std::atomic logged_decode_{false}; + std::atomic logged_decode_detail_{false}; }; REGISTER_NODE(AiFaceDetNode, "ai_face_det");