mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
[Benchmark] Add GetModelResoucesNameFromDir APIs (#1640)
This commit is contained in:
@@ -32,12 +32,18 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto backend = config_info["backend"];
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "infer_cfg.yml";
|
||||
auto model_picodet =
|
||||
vision::detection::PicoDet(model_file, params_file, config_file, option);
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
auto model_picodet = vision::detection::PicoDet(
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
if (FLAGS_no_nms) {
|
||||
model_picodet.GetPostprocessor().ApplyNMS();
|
||||
}
|
||||
|
@@ -34,11 +34,18 @@ int main(int argc, char* argv[]) {
|
||||
if (config_info["backend"] == "paddle_trt") {
|
||||
option.trt_option.max_batch_size = 1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + "inference.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "inference.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "inference_cls.yaml";
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
auto model_ppcls = vision::classification::PaddleClasModel(
|
||||
model_file, params_file, config_file, option);
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
vision::ClassifyResult res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
17
benchmark/cpp/benchmark_ppmatting.cc
Executable file → Normal file
17
benchmark/cpp/benchmark_ppmatting.cc
Executable file → Normal file
@@ -34,9 +34,16 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "deploy.yaml";
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
if (config_info["backend"] == "paddle_trt") {
|
||||
option.paddle_infer_option.collect_trt_shape = true;
|
||||
}
|
||||
@@ -47,8 +54,8 @@ int main(int argc, char* argv[]) {
|
||||
option.trt_option.SetShape("x", trt_shapes[0], trt_shapes[1],
|
||||
trt_shapes[2]);
|
||||
}
|
||||
auto model_ppmatting =
|
||||
vision::matting::PPMatting(model_file, params_file, config_file, option);
|
||||
auto model_ppmatting = vision::matting::PPMatting(
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
vision::MattingResult res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
@@ -34,9 +34,15 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info, false)) {
|
||||
return -1;
|
||||
}
|
||||
// Classification Model
|
||||
auto cls_model_file = FLAGS_model + sep + "inference.pdmodel";
|
||||
auto cls_params_file = FLAGS_model + sep + "inference.pdiparams";
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
if (config_info["backend"] == "paddle_trt") {
|
||||
option.paddle_infer_option.collect_trt_shape = true;
|
||||
}
|
||||
@@ -48,7 +54,7 @@ int main(int argc, char* argv[]) {
|
||||
trt_shapes[2]);
|
||||
}
|
||||
auto model_ppocr_cls =
|
||||
vision::ocr::Classifier(cls_model_file, cls_params_file, option);
|
||||
vision::ocr::Classifier(model_file, params_file, option, model_format);
|
||||
int32_t res_label;
|
||||
float res_score;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
|
@@ -35,8 +35,15 @@ int main(int argc, char* argv[]) {
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
// Detection Model
|
||||
auto det_model_file = FLAGS_model + sep + "inference.pdmodel";
|
||||
auto det_params_file = FLAGS_model + sep + "inference.pdiparams";
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info, false)) {
|
||||
return -1;
|
||||
}
|
||||
// Classification Model
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
if (config_info["backend"] == "paddle_trt") {
|
||||
option.paddle_infer_option.collect_trt_shape = true;
|
||||
}
|
||||
@@ -48,7 +55,7 @@ int main(int argc, char* argv[]) {
|
||||
trt_shapes[2]);
|
||||
}
|
||||
auto model_ppocr_det =
|
||||
vision::ocr::DBDetector(det_model_file, det_params_file, option);
|
||||
vision::ocr::DBDetector(model_file, params_file, option, model_format);
|
||||
std::vector<std::array<int, 8>> res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
@@ -35,9 +35,14 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
// Recognition Model
|
||||
auto rec_model_file = FLAGS_model + sep + "inference.pdmodel";
|
||||
auto rec_params_file = FLAGS_model + sep + "inference.pdiparams";
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info, false)) {
|
||||
return -1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
if (config_info["backend"] == "paddle_trt") {
|
||||
option.paddle_infer_option.collect_trt_shape = true;
|
||||
}
|
||||
@@ -49,7 +54,7 @@ int main(int argc, char* argv[]) {
|
||||
trt_shapes[2]);
|
||||
}
|
||||
auto model_ppocr_rec = vision::ocr::Recognizer(
|
||||
rec_model_file, rec_params_file, FLAGS_rec_label_file, option);
|
||||
model_file, params_file, FLAGS_rec_label_file, option, model_format);
|
||||
std::string text;
|
||||
float rec_score;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
|
@@ -34,9 +34,15 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "deploy.yaml";
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
if (config_info["backend"] == "paddle_trt") {
|
||||
option.paddle_infer_option.collect_trt_shape = true;
|
||||
}
|
||||
@@ -48,7 +54,7 @@ int main(int argc, char* argv[]) {
|
||||
trt_shapes[2]);
|
||||
}
|
||||
auto model_ppseg = vision::segmentation::PaddleSegModel(
|
||||
model_file, params_file, config_file, option);
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
vision::SegmentationResult res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
@@ -32,12 +32,17 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto backend = config_info["backend"];
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "infer_cfg.yml";
|
||||
auto model_ppyoloe =
|
||||
vision::detection::PPYOLOE(model_file, params_file, config_file, option);
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
auto model_ppyoloe = vision::detection::PPYOLOE(
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
if (FLAGS_no_nms) {
|
||||
model_ppyoloe.GetPostprocessor().ApplyNMS();
|
||||
}
|
||||
|
16
benchmark/cpp/benchmark_ppyolov5.cc
Executable file → Normal file
16
benchmark/cpp/benchmark_ppyolov5.cc
Executable file → Normal file
@@ -32,11 +32,17 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "infer_cfg.yml";
|
||||
auto model_ppyolov5 = vision::detection::PaddleYOLOv5(model_file, params_file,
|
||||
config_file, option);
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
auto model_ppyolov5 = vision::detection::PaddleYOLOv5(
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
vision::DetectionResult res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
16
benchmark/cpp/benchmark_ppyolov6.cc
Executable file → Normal file
16
benchmark/cpp/benchmark_ppyolov6.cc
Executable file → Normal file
@@ -32,11 +32,17 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "infer_cfg.yml";
|
||||
auto model_ppyolov6 = vision::detection::PaddleYOLOv6(model_file, params_file,
|
||||
config_file, option);
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
auto model_ppyolov6 = vision::detection::PaddleYOLOv6(
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
vision::DetectionResult res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
16
benchmark/cpp/benchmark_ppyolov7.cc
Executable file → Normal file
16
benchmark/cpp/benchmark_ppyolov7.cc
Executable file → Normal file
@@ -32,11 +32,17 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "infer_cfg.yml";
|
||||
auto model_ppyolov7 = vision::detection::PaddleYOLOv7(model_file, params_file,
|
||||
config_file, option);
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
auto model_ppyolov7 = vision::detection::PaddleYOLOv7(
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
vision::DetectionResult res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
@@ -32,11 +32,17 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "infer_cfg.yml";
|
||||
auto model_ppyolov8 = vision::detection::PaddleYOLOv8(model_file, params_file,
|
||||
config_file, option);
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
auto model_ppyolov8 = vision::detection::PaddleYOLOv8(
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
vision::DetectionResult res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
@@ -32,11 +32,17 @@ int main(int argc, char* argv[]) {
|
||||
std::unordered_map<std::string, std::string> config_info;
|
||||
benchmark::ResultManager::LoadBenchmarkConfig(FLAGS_config_path,
|
||||
&config_info);
|
||||
auto model_file = FLAGS_model + sep + "model.pdmodel";
|
||||
auto params_file = FLAGS_model + sep + "model.pdiparams";
|
||||
auto config_file = FLAGS_model + sep + "infer_cfg.yml";
|
||||
auto model_ppyolox = vision::detection::PaddleYOLOX(model_file, params_file,
|
||||
config_file, option);
|
||||
std::string model_name, params_name, config_name;
|
||||
auto model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!UpdateModelResourceName(&model_name, ¶ms_name, &config_name,
|
||||
&model_format, config_info)) {
|
||||
return -1;
|
||||
}
|
||||
auto model_file = FLAGS_model + sep + model_name;
|
||||
auto params_file = FLAGS_model + sep + params_name;
|
||||
auto config_file = FLAGS_model + sep + config_name;
|
||||
auto model_ppyolox = vision::detection::PaddleYOLOX(
|
||||
model_file, params_file, config_file, option, model_format);
|
||||
vision::DetectionResult res;
|
||||
if (config_info["precision_compare"] == "true") {
|
||||
// Run once at least
|
||||
|
@@ -17,6 +17,9 @@
|
||||
#include <unordered_map>
|
||||
#include "gflags/gflags.h"
|
||||
#include "fastdeploy/benchmark/utils.h"
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
static const char sep = '\\';
|
||||
@@ -91,3 +94,68 @@ static void PrintBenchmarkInfo(std::unordered_map<std::string,
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
static bool GetModelResoucesNameFromDir(
|
||||
const std::string& path, std::string* resource_name,
|
||||
const std::string& suffix = "pdmodel") {
|
||||
DIR *p_dir;
|
||||
struct dirent *ptr;
|
||||
if (!(p_dir = opendir(path.c_str()))) {
|
||||
return false;
|
||||
}
|
||||
bool find = false;
|
||||
while ((ptr = readdir(p_dir)) != 0) {
|
||||
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
||||
std::string tmp_file_name = ptr->d_name;
|
||||
if (tmp_file_name.find(suffix) != std::string::npos) {
|
||||
if (suffix == "pdiparams") {
|
||||
if (tmp_file_name.find("info") == std::string::npos) {
|
||||
find = true;
|
||||
*resource_name = tmp_file_name;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
find = true;
|
||||
*resource_name = tmp_file_name;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (suffix == "yml") {
|
||||
if (tmp_file_name.find("yaml") != std::string::npos) {
|
||||
find = true;
|
||||
*resource_name = tmp_file_name;
|
||||
break;
|
||||
}
|
||||
} else if (suffix == "yaml") {
|
||||
if (tmp_file_name.find("yml") != std::string::npos) {
|
||||
find = true;
|
||||
*resource_name = tmp_file_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(p_dir);
|
||||
return find;
|
||||
}
|
||||
|
||||
static bool UpdateModelResourceName(
|
||||
std::string* model_name, std::string* params_name,
|
||||
std::string* config_name, fastdeploy::ModelFormat* model_format,
|
||||
std::unordered_map<std::string, std::string>& config_info,
|
||||
bool use_config_file = true, bool use_quant_model = false) {
|
||||
*model_format = fastdeploy::ModelFormat::PADDLE;
|
||||
if (!(GetModelResoucesNameFromDir(FLAGS_model, model_name, "pdmodel")
|
||||
&& GetModelResoucesNameFromDir(FLAGS_model, params_name, "pdiparams"))) {
|
||||
std::cout << "Can not find Paddle model resources." << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (use_config_file) {
|
||||
if (!GetModelResoucesNameFromDir(FLAGS_model, config_name, "yml")) {
|
||||
std::cout << "Can not find config yaml resources." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user