修复人脸识别问题,测试模型问题,添加了调试
Some checks are pending
CI / host-build (push) Waiting to run
CI / rk3588-cross-build (push) Waiting to run

This commit is contained in:
sladro 2026-01-08 15:44:23 +08:00
parent f61b9d4c99
commit 57e4af1d92
2 changed files with 49 additions and 0 deletions

BIN
003_aligned.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -13,6 +13,12 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
// For test image loading
#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_PNG
#define STBI_NO_FAILURE_STRINGS
#include "../../third_party/rknpu2/examples/3rdparty/stb/stb_image.h"
#include "ai_scheduler.h" #include "ai_scheduler.h"
#include "face/face_result.h" #include "face/face_result.h"
#include "node.h" #include "node.h"
@ -709,6 +715,49 @@ public:
const float thr_margin = cfg ? cfg->thr_margin : 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") + 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));
// ========== TEST: Load aligned image and run inference ==========
#if defined(RK3588_ENABLE_RKNN)
{
const char* test_img_path = "./003_aligned.png";
int img_w = 0, img_h = 0, img_c = 0;
unsigned char* img_data = stbi_load(test_img_path, &img_w, &img_h, &img_c, 3);
if (img_data && img_w == 112 && img_h == 112) {
std::cerr << "[TEST] Loaded " << test_img_path << " (" << img_w << "x" << img_h << "x" << img_c << ")\n";
InferInput in;
in.width = 112;
in.height = 112;
in.is_nhwc = true;
in.data = img_data;
in.size = 112 * 112 * 3;
in.type = RKNN_TENSOR_UINT8;
auto r = AiScheduler::Instance().InferBorrowed(model_handle_, in);
if (r.success && !r.outputs.empty()) {
std::vector<float> emb;
if (DecodeEmbedding(r.outputs[0], emb)) {
L2Normalize(emb);
std::cerr << "[TEST] RKNN embedding[0:8]: ";
for (int i = 0; i < 8 && i < static_cast<int>(emb.size()); ++i) {
std::cerr << emb[i] << " ";
}
std::cerr << "\n";
} else {
std::cerr << "[TEST] DecodeEmbedding failed\n";
}
} else {
std::cerr << "[TEST] Inference failed: " << r.error << "\n";
}
stbi_image_free(img_data);
} else {
if (img_data) stbi_image_free(img_data);
std::cerr << "[TEST] Skip: " << test_img_path << " not found or wrong size\n";
}
}
#endif
// ========== END TEST ==========
return true; return true;
} }