mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-08 18:11:00 +08:00

* 修复picodet格式 * * 修正错误文档 * 修复rknpu2 backend后端的部分错误 * 更新pphumanseg example格式 * * 更新pphumanseg example格式 * * 更新picodet example格式 * * 更新scrfd example格式 * * 更新ppseg rknpu2 python example中的错误 * * 修复代码格式问题 * * 修复代码格式问题 * * 修复代码格式问题 * * 修复代码格式问题 * * 修复代码格式问题 * * 修复代码格式问题 Co-authored-by: Jason <jiangjiajun@baidu.com>
83 lines
2.3 KiB
C++
83 lines
2.3 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include "fastdeploy/vision.h"
|
|
|
|
void ONNXInfer(const std::string& model_dir, const std::string& image_file) {
|
|
std::string model_file = model_dir + "/scrfd_500m_bnkps_shape640x640.onnx";
|
|
std::string params_file;
|
|
auto option = fastdeploy::RuntimeOption();
|
|
option.UseCpu();
|
|
auto format = fastdeploy::ModelFormat::ONNX;
|
|
|
|
auto model = fastdeploy::vision::facedet::SCRFD(
|
|
model_file, params_file, option, format);
|
|
|
|
if (!model.Initialized()) {
|
|
std::cerr << "Failed to initialize." << std::endl;
|
|
return;
|
|
}
|
|
|
|
fastdeploy::TimeCounter tc;
|
|
tc.Start();
|
|
auto im = cv::imread(image_file);
|
|
fastdeploy::vision::FaceDetectionResult res;
|
|
if (!model.Predict(&im, &res)) {
|
|
std::cerr << "Failed to predict." << std::endl;
|
|
return;
|
|
}
|
|
auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im, res);
|
|
tc.End();
|
|
tc.PrintInfo("SCRFD in ONNX");
|
|
|
|
cv::imwrite("infer_onnx.jpg", vis_im);
|
|
std::cout
|
|
<< "Visualized result saved in ./infer_onnx.jpg"
|
|
<< std::endl;
|
|
}
|
|
|
|
void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) {
|
|
std::string model_file = model_dir + "/scrfd_500m_bnkps_shape640x640_rk3588.rknn";
|
|
std::string params_file;
|
|
auto option = fastdeploy::RuntimeOption();
|
|
option.UseRKNPU2();
|
|
auto format = fastdeploy::ModelFormat::RKNN;
|
|
|
|
auto model = fastdeploy::vision::facedet::SCRFD(model_file, params_file, option, format);
|
|
|
|
if (!model.Initialized()) {
|
|
std::cerr << "Failed to initialize." << std::endl;
|
|
return;
|
|
}
|
|
model.DisableNormalizeAndPermute();
|
|
|
|
fastdeploy::TimeCounter tc;
|
|
tc.Start();
|
|
auto im = cv::imread(image_file);
|
|
fastdeploy::vision::FaceDetectionResult res;
|
|
if (!model.Predict(&im, &res)) {
|
|
std::cerr << "Failed to predict." << std::endl;
|
|
return;
|
|
}
|
|
auto vis_im = fastdeploy::vision::Visualize::VisFaceDetection(im, res);
|
|
tc.End();
|
|
tc.PrintInfo("SCRFD in RKNN");
|
|
|
|
cv::imwrite("infer_rknn.jpg", vis_im);
|
|
std::cout
|
|
<< "Visualized result saved in ./infer_rknn.jpg"
|
|
<< std::endl;
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if (argc < 3) {
|
|
std::cout
|
|
<< "Usage: infer_demo path/to/model_dir path/to/image run_option, "
|
|
"e.g ./infer_model ./picodet_model_dir ./test.jpeg"
|
|
<< std::endl;
|
|
return -1;
|
|
}
|
|
|
|
RKNPU2Infer(argv[1], argv[2]);
|
|
ONNXInfer(argv[1], argv[2]);
|
|
return 0;
|
|
} |