[Model] Refactor insightface models (#919)

* 重构insightface代码

* 重写insightface example代码

* 重写insightface example代码

* 删除多余代码

* 修改预处理代码

* 修改文档

* 修改文档

* 恢复误删除的文件

* 修改cpp example

* 修改cpp example

* 测试python代码

* 测试python代码

* 测试python代码

* 测试python代码

* 测试python代码

* 测试python代码

* 测试python代码

* 跑通python代码

* 修复重复初始化的bug

* 更新adaface的python代码

* 修复c++重复初始化的问题

* 修复c++重复初始化的问题

* 修复Python重复初始化的问题

* 新增preprocess的几个参数的获取方式

* 修复注释的错误

* 按照要求修改

* 修改文档中的图片为图片压缩包

* 修改编译完成后程序的提示

* 更新错误include

* 删除无用文件

* 更新文档
This commit is contained in:
Zheng_Bicheng
2022-12-26 21:01:58 +08:00
committed by GitHub
parent df940b750f
commit ec67f8ee6d
62 changed files with 1750 additions and 2100 deletions

View File

@@ -1,14 +1,17 @@
/***************************************************************************
*
* Copyright (c) 2021 Baidu.com, Inc. All Rights Reserved
*
**************************************************************************/
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @author Baidu
* @brief demo_image_inference
*
**/
#include "fastdeploy/vision.h"
void CpuInfer(const std::string &model_file, const std::string &params_file,
@@ -28,8 +31,8 @@ void CpuInfer(const std::string &model_file, const std::string &params_file,
fastdeploy::vision::FaceRecognitionResult res1;
fastdeploy::vision::FaceRecognitionResult res2;
if ((!model.Predict(&face0, &res0)) || (!model.Predict(&face1, &res1)) ||
(!model.Predict(&face2, &res2))) {
if ((!model.Predict(face0, &res0)) || (!model.Predict(face1, &res1)) ||
(!model.Predict(face2, &res2))) {
std::cerr << "Prediction Failed." << std::endl;
}
@@ -40,9 +43,11 @@ void CpuInfer(const std::string &model_file, const std::string &params_file,
std::cout << "--- [Face 2]:" << res2.Str();
float cosine01 = fastdeploy::vision::utils::CosineSimilarity(
res0.embedding, res1.embedding, model.l2_normalize);
res0.embedding, res1.embedding,
model.GetPostprocessor().GetL2Normalize());
float cosine02 = fastdeploy::vision::utils::CosineSimilarity(
res0.embedding, res2.embedding, model.l2_normalize);
res0.embedding, res2.embedding,
model.GetPostprocessor().GetL2Normalize());
std::cout << "Detect Done! Cosine 01: " << cosine01
<< ", Cosine 02:" << cosine02 << std::endl;
}
@@ -65,8 +70,8 @@ void XpuInfer(const std::string &model_file, const std::string &params_file,
fastdeploy::vision::FaceRecognitionResult res1;
fastdeploy::vision::FaceRecognitionResult res2;
if ((!model.Predict(&face0, &res0)) || (!model.Predict(&face1, &res1)) ||
(!model.Predict(&face2, &res2))) {
if ((!model.Predict(face0, &res0)) || (!model.Predict(face1, &res1)) ||
(!model.Predict(face2, &res2))) {
std::cerr << "Prediction Failed." << std::endl;
}
@@ -77,9 +82,11 @@ void XpuInfer(const std::string &model_file, const std::string &params_file,
std::cout << "--- [Face 2]:" << res2.Str();
float cosine01 = fastdeploy::vision::utils::CosineSimilarity(
res0.embedding, res1.embedding, model.l2_normalize);
res0.embedding, res1.embedding,
model.GetPostprocessor().GetL2Normalize());
float cosine02 = fastdeploy::vision::utils::CosineSimilarity(
res0.embedding, res2.embedding, model.l2_normalize);
res0.embedding, res2.embedding,
model.GetPostprocessor().GetL2Normalize());
std::cout << "Detect Done! Cosine 01: " << cosine01
<< ", Cosine 02:" << cosine02 << std::endl;
}
@@ -103,8 +110,8 @@ void GpuInfer(const std::string &model_file, const std::string &params_file,
fastdeploy::vision::FaceRecognitionResult res1;
fastdeploy::vision::FaceRecognitionResult res2;
if ((!model.Predict(&face0, &res0)) || (!model.Predict(&face1, &res1)) ||
(!model.Predict(&face2, &res2))) {
if ((!model.Predict(face0, &res0)) || (!model.Predict(face1, &res1)) ||
(!model.Predict(face2, &res2))) {
std::cerr << "Prediction Failed." << std::endl;
}
@@ -115,9 +122,11 @@ void GpuInfer(const std::string &model_file, const std::string &params_file,
std::cout << "--- [Face 2]:" << res2.Str();
float cosine01 = fastdeploy::vision::utils::CosineSimilarity(
res0.embedding, res1.embedding, model.l2_normalize);
res0.embedding, res1.embedding,
model.GetPostprocessor().GetL2Normalize());
float cosine02 = fastdeploy::vision::utils::CosineSimilarity(
res0.embedding, res2.embedding, model.l2_normalize);
res0.embedding, res2.embedding,
model.GetPostprocessor().GetL2Normalize());
std::cout << "Detect Done! Cosine 01: " << cosine01
<< ", Cosine 02:" << cosine02 << std::endl;
}
@@ -143,8 +152,8 @@ void TrtInfer(const std::string &model_file, const std::string &params_file,
fastdeploy::vision::FaceRecognitionResult res1;
fastdeploy::vision::FaceRecognitionResult res2;
if ((!model.Predict(&face0, &res0)) || (!model.Predict(&face1, &res1)) ||
(!model.Predict(&face2, &res2))) {
if ((!model.Predict(face0, &res0)) || (!model.Predict(face1, &res1)) ||
(!model.Predict(face2, &res2))) {
std::cerr << "Prediction Failed." << std::endl;
}
@@ -155,9 +164,11 @@ void TrtInfer(const std::string &model_file, const std::string &params_file,
std::cout << "--- [Face 2]:" << res2.Str();
float cosine01 = fastdeploy::vision::utils::CosineSimilarity(
res0.embedding, res1.embedding, model.l2_normalize);
res0.embedding, res1.embedding,
model.GetPostprocessor().GetL2Normalize());
float cosine02 = fastdeploy::vision::utils::CosineSimilarity(
res0.embedding, res2.embedding, model.l2_normalize);
res0.embedding, res2.embedding,
model.GetPostprocessor().GetL2Normalize());
std::cout << "Detect Done! Cosine 01: " << cosine01
<< ", Cosine 02:" << cosine02 << std::endl;
}