[Model] 更新SCRFD模型demo以及文档 (#1108)

* 更新scrfd

* 更新scrfd
This commit is contained in:
Zheng-Bicheng
2023-01-11 13:56:17 +08:00
committed by GitHub
parent 9d288962d8
commit dd01b3ca0b
7 changed files with 78 additions and 100 deletions

View File

@@ -1,16 +1,16 @@
#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";
void ONNXInfer(const std::string& model_file, const std::string& image_file) {
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);
auto model = fastdeploy::vision::facedet::SCRFD(model_file, params_file,
option, format);
if (!model.Initialized()) {
std::cerr << "Failed to initialize." << std::endl;
@@ -31,19 +31,17 @@ void ONNXInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << res.Str() << std::endl;
cv::imwrite("infer_onnx.jpg", vis_im);
std::cout
<< "Visualized result saved in ./infer_onnx.jpg"
<< std::endl;
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";
void RKNPU2Infer(const std::string& model_file, const std::string& image_file) {
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);
auto model = fastdeploy::vision::facedet::SCRFD(model_file, params_file,
option, format);
if (!model.Initialized()) {
std::cerr << "Failed to initialize." << std::endl;
@@ -66,21 +64,25 @@ void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) {
std::cout << res.Str() << std::endl;
cv::imwrite("infer_rknn.jpg", vis_im);
std::cout
<< "Visualized result saved in ./infer_rknn.jpg"
<< std::endl;
std::cout << "Visualized result saved in ./infer_rknn.jpg" << std::endl;
}
int main(int argc, char* argv[]) {
if (argc < 3) {
if (argc < 4) {
std::cout
<< "Usage: infer_demo path/to/model_dir path/to/image run_option, "
"e.g ./infer_model ./picodet_model_dir ./test.jpeg"
<< "Usage: infer_demo path/to/model path/to/image run_option, "
"e.g ./infer_model scrfd_500m_bnkps_shape640x640.onnx ./test.jpeg 0"
<< std::endl;
std::cout << "The data type of run_option is int, "
"0: run with cpu; 1: run with rknpu2."
<< std::endl;
return -1;
}
RKNPU2Infer(argv[1], argv[2]);
ONNXInfer(argv[1], argv[2]);
if (std::atoi(argv[3]) == 0) {
ONNXInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 1) {
RKNPU2Infer(argv[1], argv[2]);
}
return 0;
}