Update inspireface to 1.2.0

This commit is contained in:
Jingyu
2025-03-25 00:51:26 +08:00
parent 977ea6795b
commit ca64996b84
388 changed files with 28584 additions and 13036 deletions

View File

@@ -1,11 +1,12 @@
//
// Created by tunm on 2023/9/23.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
#include "inspireface/middleware/costman.h"
#include "middleware/inference_helper/customized/rknn_adapter.h"
#include "middleware/inference_wrapper/customized/rknn_adapter.h"
#include "inspireface/feature_hub/simd.h"
#include <memory>
#include "inspireface/recognition_module/extract/extract.h"
@@ -15,16 +16,16 @@ using namespace inspire;
int main() {
std::vector<std::string> names = {
"test_res/images/test_data/0.jpg",
"test_res/images/test_data/1.jpg",
"test_res/images/test_data/2.jpg",
"test_res/images/test_data/0.jpg",
"test_res/images/test_data/1.jpg",
"test_res/images/test_data/2.jpg",
};
InspireArchive loader("test_res/pack/test_zip_rec");
{
InspireModel model;
loader.LoadModel("feature", model);
auto net = std::make_shared<RKNNAdapter>();
net->Initialize((unsigned char* )model.buffer, model.bufferSize);
net->Initialize((unsigned char *)model.buffer, model.bufferSize);
net->setOutputsWantFloat(1);
EmbeddedList list;
@@ -37,27 +38,26 @@ int main() {
auto out = net->GetOutputData(0);
auto dims = net->GetOutputTensorSize(0);
// for (int i = 0; i < dims.size(); ++i) {
// LOGD("%lu", dims[i]);
// }
//
for (int i = 0; i < 512; ++i) {
std::cout << out[i] << ", ";
}
std::cout << std::endl;
// for (int i = 0; i < dims.size(); ++i) {
// LOGD("%lu", dims[i]);
// }
//
for (int i = 0; i < 512; ++i) {
std::cout << out[i] << ", ";
}
std::cout << std::endl;
Embedded emb;
for (int j = 0; j < 512; ++j) {
emb.push_back(out[j]);
}
list.push_back(emb);
}
for (int i = 0; i < list.size(); ++i) {
auto &embedded = list[i];
float mse = 0.0f;
for (const auto &one: embedded) {
for (const auto &one : embedded) {
mse += one * one;
}
mse = sqrt(mse);
@@ -76,24 +76,26 @@ int main() {
Configurable param;
param.set<int>("model_index", 0);
param.set<std::string>("input_layer", "input");
param.set<std::vector<std::string>>("outputs_layers", {"267", });
param.set<std::vector<std::string>>("outputs_layers", {
"267",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
param.set<bool>("swap_color", true); // RK requires rgb input
param.set<bool>("swap_color", true); // RK requires rgb input
m_extract_ = std::make_shared<Extract>();
InspireModel model;
loader.LoadModel("feature", model);
m_extract_->loadData(model, InferenceHelper::kRknn);
m_extract_->loadData(model, InferenceWrapper::INFER_RKNN);
cv::Mat image = cv::imread(names[0]);
// cv::Mat rgb;
// cv::cvtColor(image, rgb, cv::COLOR_BGR2RGB);
// cv::Mat rgb;
// cv::cvtColor(image, rgb, cv::COLOR_BGR2RGB);
auto feat = m_extract_->GetFaceFeature(image);
for (int i = 0; i < 512; ++i) {
std::cout << feat[i] << ", ";
@@ -101,7 +103,6 @@ int main() {
std::cout << std::endl;
}
LOGD("End");
return 0;

View File

@@ -1,8 +1,9 @@
//
// Created by Tunm-Air13 on 2023/9/20.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
//#include "inspireface/middleware/model_loader/model_loader.h"
// #include "inspireface/middleware/model_loader/model_loader.h"
#include "inspireface/track_module/face_detect/all.h"
#include "inspireface/middleware/costman.h"
@@ -30,8 +31,7 @@ int main() {
std::shared_ptr<FaceDetect> m_face_detector_;
m_face_detector_ = std::make_shared<FaceDetect>(320);
m_face_detector_->loadData(model, InferenceHelper::kRknn);
m_face_detector_->loadData(model, InferenceWrapper::INFER_RKNN);
// Load a image
cv::Mat image = cv::imread("test_res/images/face_sample.png");
@@ -42,11 +42,10 @@ int main() {
LOGD("Faces: %ld", locs.size());
for (auto &loc: locs) {
for (auto &loc : locs) {
cv::rectangle(image, cv::Point2f(loc.x1, loc.y1), cv::Point2f(loc.x2, loc.y2), cv::Scalar(0, 0, 255), 3);
}
cv::imwrite("det.jpg", image);
return 0;
}

View File

@@ -1,7 +1,7 @@
//
// Created by tunm on 2023/9/21.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
@@ -15,40 +15,41 @@ using namespace inspire;
std::shared_ptr<InspireArchive> loader;
void rec_function() {
std::shared_ptr<Extract> m_extract_;
Configurable param;
// param.set<int>("model_index", ModelIndex::_03_extract);
// param.set<int>("model_index", ModelIndex::_03_extract);
param.set<std::string>("input_layer", "input");
param.set<std::vector<std::string>>("outputs_layers", {"267", });
param.set<std::vector<std::string>>("outputs_layers", {
"267",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
param.set<bool>("swap_color", true); // RK requires rgb input
param.set<bool>("swap_color", true); // RK requires rgb input
m_extract_ = std::make_shared<Extract>();
InspireModel model;
loader->LoadModel("feature", model);
m_extract_->loadData(model, InferenceHelper::kRknn);
m_extract_->loadData(model, InferenceWrapper::INFER_RKNN);
loader.reset();
std::vector<std::string> files = {
"test_res/images/test_data/0.jpg",
"test_res/images/test_data/1.jpg",
"test_res/images/test_data/2.jpg",
"test_res/images/test_data/0.jpg",
"test_res/images/test_data/1.jpg",
"test_res/images/test_data/2.jpg",
};
EmbeddedList embedded_list;
for (int i = 0; i < files.size(); ++i) {
auto warped = cv::imread(files[i]);
Timer timer;
auto emb = (*m_extract_)(warped);
LOGD("耗时: %f", timer.GetCostTimeUpdate());
LOGD("cost: %f", timer.GetCostTimeUpdate());
embedded_list.push_back(emb);
LOGD("%lu", emb.size());
}
@@ -63,26 +64,21 @@ void rec_function() {
LOGD("0 vs 2 : %f", _0v2);
LOGD("1 vs 2 : %f", _1v2);
// LOGD("size: %lu", embedded_list.size());
// LOGD("num of vector: %lu", embedded_list[2].size());
//
// float _0v1 = simd_dot(embedded_list[0].data(), embedded_list[1].data(), 512);
// float _0v2 = simd_dot(embedded_list[0].data(), embedded_list[2].data(), 512);
// float _1v2 = simd_dot(embedded_list[1].data(), embedded_list[2].data(), 512);
// LOGD("0 vs 1 : %f", _0v1);
// LOGD("0 vs 2 : %f", _0v2);
// LOGD("1 vs 2 : %f", _1v2);
// LOGD("size: %lu", embedded_list.size());
// LOGD("num of vector: %lu", embedded_list[2].size());
//
// float _0v1 = simd_dot(embedded_list[0].data(), embedded_list[1].data(), 512);
// float _0v2 = simd_dot(embedded_list[0].data(), embedded_list[2].data(), 512);
// float _1v2 = simd_dot(embedded_list[1].data(), embedded_list[2].data(), 512);
// LOGD("0 vs 1 : %f", _0v1);
// LOGD("0 vs 2 : %f", _0v2);
// LOGD("1 vs 2 : %f", _1v2);
}
int main() {
loader = std::make_shared<InspireArchive>();
loader->ReLoad("test_res/pack/Gundam_RV1109");
rec_function();
return 0;

View File

@@ -1,6 +1,7 @@
//
// Created by Tunm-Air13 on 2023/9/21.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
#include "inspireface/track_module/face_detect/all.h"
@@ -16,26 +17,25 @@ using namespace inspire;
InspireArchive loader;
void test_rnet() {
std::shared_ptr<RNet> m_rnet_;
Configurable param;
// param.set<int>("model_index", ModelIndex::_04_refine_net);
// param.set<int>("model_index", ModelIndex::_04_refine_net);
param.set<std::string>("input_layer", "input_1");
param.set<std::vector<std::string>>("outputs_layers", {"conv5-1/Softmax", "conv5-2/BiasAdd"});
param.set<std::vector<int>>("input_size", {24, 24});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
InspireModel model;
loader.LoadModel("refine_net", model);
m_rnet_ = std::make_shared<RNet>();
m_rnet_->loadData(model, InferenceHelper::kRknn);
m_rnet_->loadData(model, InferenceWrapper::INFER_RKNN);
{
// Load a image
@@ -56,28 +56,29 @@ void test_rnet() {
LOGD("cost: %f", timer.GetCostTimeUpdate());
LOGD("non face: %f", score);
}
}
void test_mask() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_05_mask);
// param.set<int>("model_index", ModelIndex::_05_mask);
param.set<std::string>("input_layer", "input_1");
param.set<std::vector<std::string>>("outputs_layers", {"activation_1/Softmax",});
param.set<std::vector<std::string>>("outputs_layers", {
"activation_1/Softmax",
});
param.set<std::vector<int>>("input_size", {96, 96});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
std::shared_ptr<MaskPredict> m_mask_predict_;
m_mask_predict_ = std::make_shared<MaskPredict>();
InspireModel model;
loader.LoadModel("mask_detect", model);
m_mask_predict_->loadData(model, InferenceHelper::kRknn);
m_mask_predict_->loadData(model, InferenceWrapper::INFER_RKNN);
{
// Load a image
@@ -98,32 +99,33 @@ void test_mask() {
LOGD("cost: %f", timer.GetCostTimeUpdate());
LOGD("maskless: %f", score);
}
}
void test_quality() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_07_pose_q_fp16);
// param.set<int>("model_index", ModelIndex::_07_pose_q_fp16);
param.set<std::string>("input_layer", "data");
param.set<std::vector<std::string>>("outputs_layers", {"fc1", });
param.set<std::vector<std::string>>("outputs_layers", {
"fc1",
});
param.set<std::vector<int>>("input_size", {96, 96});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<bool>("swap_color", true); // RGB mode
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
std::shared_ptr<FacePoseQuality> m_face_quality_;
m_face_quality_ = std::make_shared<FacePoseQuality>();
InspireModel model;
loader.LoadModel("pose_quality", model);
m_face_quality_->loadData(model, InferenceHelper::kRknn);
m_face_quality_->loadData(model, InferenceWrapper::INFER_RKNN);
{
std::vector<std::string> names = {
"test_res/images/test_data/p3.jpg",
// "test_res/images/test_data/p1.jpg",
"test_res/images/test_data/p3.jpg",
// "test_res/images/test_data/p1.jpg",
};
for (int i = 0; i < names.size(); ++i) {
LOGD("Image: %s", names[i].c_str());
@@ -131,9 +133,9 @@ void test_quality() {
Timer timer;
auto pose_res = (*m_face_quality_)(image);
LOGD("质量cost: %f", timer.GetCostTimeUpdate());
LOGD("quality cost: %f", timer.GetCostTimeUpdate());
for (auto &p: pose_res.lmk) {
for (auto &p : pose_res.lmk) {
cv::circle(image, p, 0, cv::Scalar(0, 0, 255), 2);
}
cv::imwrite("pose.jpg", image);
@@ -141,22 +143,21 @@ void test_quality() {
LOGD("yam: %f", pose_res.yaw);
LOGD("roll: %f", pose_res.roll);
for (auto q: pose_res.lmk_quality) {
for (auto q : pose_res.lmk_quality) {
std::cout << q << ", ";
}
std::cout << std::endl;
}
}
}
void test_landmark_mnn() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_01_lmk);
// param.set<int>("model_index", ModelIndex::_01_lmk);
param.set<std::string>("input_layer", "input_1");
param.set<std::vector<std::string>>("outputs_layers", {"prelu1/add", });
param.set<std::vector<std::string>>("outputs_layers", {
"prelu1/add",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {127.5f, 127.5f, 127.5f});
param.set<std::vector<float>>("norm", {0.0078125f, 0.0078125f, 0.0078125f});
@@ -184,30 +185,28 @@ void test_landmark_mnn() {
}
cv::imwrite("lmk.jpg", image);
}
void test_landmark() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_01_lmk);
// param.set<int>("model_index", ModelIndex::_01_lmk);
param.set<std::string>("input_layer", "input_1");
param.set<std::vector<std::string>>("outputs_layers", {"prelu1/add", });
param.set<std::vector<std::string>>("outputs_layers", {
"prelu1/add",
});
param.set<std::vector<int>>("input_size", {112, 112});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
std::shared_ptr<FaceLandmark> m_landmark_predictor_;
m_landmark_predictor_ = std::make_shared<FaceLandmark>(112);
InspireModel model;
loader.LoadModel("landmark", model);
m_landmark_predictor_->loadData(model, InferenceHelper::kRknn);
m_landmark_predictor_->loadData(model, InferenceWrapper::INFER_RKNN);
cv::Mat image = cv::imread("test_res/images/test_data/0.jpg");
cv::resize(image, image, cv::Size(112, 112));
@@ -226,24 +225,22 @@ void test_landmark() {
}
cv::imwrite("lmk.jpg", image);
}
void test_liveness() {
Configurable param;
// param.set<int>("model_index", ModelIndex::_06_msafa27);
// param.set<int>("model_index", ModelIndex::_06_msafa27);
param.set<std::string>("input_layer", "data");
param.set<std::vector<std::string>>("outputs_layers", {"556",});
param.set<std::vector<std::string>>("outputs_layers", {
"556",
});
param.set<std::vector<int>>("input_size", {80, 80});
param.set<std::vector<float>>("mean", {0.0f, 0.0f, 0.0f});
param.set<std::vector<float>>("norm", {1.0f, 1.0f, 1.0f});
param.set<bool>("swap_color", false); // RGB mode
param.set<int>("data_type", InputTensorInfo::kDataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::kTensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::kTensorTypeFp32);
param.set<bool>("swap_color", false); // RGB mode
param.set<int>("data_type", InputTensorInfo::DataTypeImage);
param.set<int>("input_tensor_type", InputTensorInfo::TensorTypeUint8);
param.set<int>("output_tensor_type", InputTensorInfo::TensorTypeFp32);
param.set<bool>("nchw", false);
std::shared_ptr<RBGAntiSpoofing> m_rgb_anti_spoofing_;
@@ -251,15 +248,11 @@ void test_liveness() {
InspireModel model;
loader.LoadModel("rgb_anti_spoofing", model);
m_rgb_anti_spoofing_ = std::make_shared<RBGAntiSpoofing>(80, true);
m_rgb_anti_spoofing_->loadData(model, InferenceHelper::kRknn);
m_rgb_anti_spoofing_->loadData(model, InferenceWrapper::INFER_RKNN);
std::vector<std::string> names = {
"test_res/images/test_data/real.jpg",
"test_res/images/test_data/fake.jpg",
"test_res/images/test_data/live.jpg",
"test_res/images/test_data/ttt.jpg",
"test_res/images/test_data/w.jpg",
"test_res/images/test_data/w2.jpg",
"test_res/images/test_data/real.jpg", "test_res/images/test_data/fake.jpg", "test_res/images/test_data/live.jpg",
"test_res/images/test_data/ttt.jpg", "test_res/images/test_data/w.jpg", "test_res/images/test_data/w2.jpg",
};
for (int i = 0; i < names.size(); ++i) {
@@ -269,7 +262,6 @@ void test_liveness() {
LOGD("cost: %f", timer.GetCostTimeUpdate());
LOGD("%s : %f", names[i].c_str(), score);
}
}
int test_liveness_ctx() {
@@ -278,13 +270,9 @@ int test_liveness_ctx() {
FaceContext ctx;
ctx.Configuration("test_res/pack/Gundam_RV1109", inspire::DETECT_MODE_IMAGE, 3, parameter);
std::vector<std::string> names = {
"test_res/images/test_data/real.jpg",
"test_res/images/test_data/fake.jpg",
"test_res/images/test_data/live.jpg",
"test_res/images/test_data/ttt.jpg",
"test_res/images/test_data/w.jpg",
"test_res/images/test_data/w2.jpg",
"test_res/images/test_data/bb.png",
"test_res/images/test_data/real.jpg", "test_res/images/test_data/fake.jpg", "test_res/images/test_data/live.jpg",
"test_res/images/test_data/ttt.jpg", "test_res/images/test_data/w.jpg", "test_res/images/test_data/w2.jpg",
"test_res/images/test_data/bb.png",
};
for (int i = 0; i < names.size(); ++i) {
@@ -293,22 +281,21 @@ int test_liveness_ctx() {
LOGD("%s : %f", names[i].c_str(), score);
}
return 0;
}
int main() {
loader.ReLoad("test_res/pack/Gundam_RV1109");
// test_rnet();
// test_rnet();
// test_mask();
// test_mask();
// test_quality();
// test_quality();
// test_landmark_mnn();
// test_landmark_mnn();
// test_landmark();
// test_landmark();
test_liveness();
test_liveness_ctx();

View File

@@ -1,6 +1,7 @@
//
// Created by Tunm-Air13 on 2023/9/22.
//
/**
* Created by Jingyu Yan
* @date 2024-10-01
*/
#include "opencv2/opencv.hpp"
@@ -12,18 +13,14 @@ using namespace inspire;
int main() {
FaceContext ctx;
CustomPipelineParameter param;
int32_t ret = ctx.Configuration(
"test_res/pack/Gundam_RV1109",
DetectMode::DETECT_MODE_VIDEO,
3,
param);
int32_t ret = ctx.Configuration("test_res/pack/Gundam_RV1109", DetectMode::DETECT_MODE_VIDEO, 3, param);
if (ret != HSUCCEED) {
LOGE("Initiate error");
}
cv::Mat frame;
std::string imageFolder = "test_res/video_frames/";
// auto video_frame_num = 10;
// auto video_frame_num = 10;
auto video_frame_num = 288;
for (int i = 0; i < video_frame_num; ++i) {
auto index = i + 1;
@@ -45,7 +42,7 @@ int main() {
LOGD("track id: %d", ctx.GetTrackingFaceList()[0].GetTrackingId());
auto &face = ctx.GetTrackingFaceList()[0];
for (auto &p: face.landmark_) {
for (auto &p : face.landmark_) {
cv::circle(frame, p, 0, cv::Scalar(0, 0, 255), 3);
}
@@ -55,7 +52,8 @@ int main() {
cv::rectangle(frame, rect, cv::Scalar(0, 0, 255), 2, 1);
std::string text = "ID: " + std::to_string(track_id) + " Count: " + std::to_string(track_count) + " Cf: " + std::to_string(face.GetConfidence());
std::string text =
"ID: " + std::to_string(track_id) + " Count: " + std::to_string(track_count) + " Cf: " + std::to_string(face.GetConfidence());
cv::Point text_position(rect.x, rect.y - 10);
int font_face = cv::FONT_HERSHEY_SIMPLEX;
@@ -70,7 +68,5 @@ int main() {
cv::imwrite(saveFile.str(), frame);
}
return 0;
}