Files
FastDeploy/fastdeploy/vision/faceid/contrib/insightface/base.h
Zheng_Bicheng ec67f8ee6d [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

* 删除无用文件

* 更新文档
2022-12-26 21:01:58 +08:00

78 lines
3.2 KiB
C++
Executable File

// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. //NOLINT
//
// 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.
#pragma once
#include "fastdeploy/fastdeploy_model.h"
#include "fastdeploy/vision/faceid/contrib/insightface/postprocessor.h"
#include "fastdeploy/vision/faceid/contrib/insightface/preprocessor.h"
namespace fastdeploy {
namespace vision {
namespace faceid {
/*! @brief InsightFaceRecognition model object used when to load a InsightFaceRecognition model exported by InsightFaceRecognition.
*/
class FASTDEPLOY_DECL InsightFaceRecognitionBase : public FastDeployModel {
public:
/** \brief Set path of model file and the configuration of runtime.
*
* \param[in] model_file Path of model file, e.g ./arcface.onnx
* \param[in] params_file Path of parameter file, e.g arcface/model.pdiparams, if the model format is ONNX, this parameter will be ignored
* \param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in "valid_cpu_backends"
* \param[in] model_format Model format of the loaded model, default is ONNX format
*/
InsightFaceRecognitionBase(
const std::string& model_file, const std::string& params_file = "",
const RuntimeOption& custom_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX);
std::string ModelName() const { return "insightface_rec"; }
/** \brief Predict the detection result for an input image
*
* \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format
* \param[in] result The output FaceRecognitionResult will be writen to this structure
* \return true if the prediction successed, otherwise false
*/
virtual bool Predict(const cv::Mat& im, FaceRecognitionResult* result);
/** \brief Predict the detection results for a batch of input images
*
* \param[in] imgs, The input image list, each element comes from cv::imread()
* \param[in] results The output FaceRecognitionResult list
* \return true if the prediction successed, otherwise false
*/
virtual bool BatchPredict(const std::vector<cv::Mat>& images,
std::vector<FaceRecognitionResult>* results);
/// Get preprocessor reference of InsightFaceRecognition
virtual InsightFaceRecognitionPreprocessor& GetPreprocessor() {
return preprocessor_;
}
/// Get postprocessor reference of InsightFaceRecognition
virtual InsightFaceRecognitionPostprocessor& GetPostprocessor() {
return postprocessor_;
}
protected:
bool Initialize();
InsightFaceRecognitionPreprocessor preprocessor_;
InsightFaceRecognitionPostprocessor postprocessor_;
};
} // namespace faceid
} // namespace vision
} // namespace fastdeploy