From 83054e3973d985e3a43ca2475e85c774b236e2ad Mon Sep 17 00:00:00 2001 From: zz990099 <771647586@qq.com> Date: Mon, 9 Jun 2025 20:22:39 +0800 Subject: [PATCH 1/2] feat[detection_2d]: Add eval on detection_2d Signed-off-by: zz990099 <771647586@qq.com> --- .../detection_2d_rt_detr/CMakeLists.txt | 4 + .../detection_2d_rt_detr/eval/CMakeLists.txt | 49 ++++++++ .../eval/eval_detection_2d_rt_detr.cpp | 74 ++++++++++++ .../detection_2d_yolov8/CMakeLists.txt | 4 + .../benchmark/CMakeLists.txt | 2 - .../detection_2d_yolov8/eval/CMakeLists.txt | 49 ++++++++ .../eval/eval_detection_2d_yolov8.cpp | 114 ++++++++++++++++++ 7 files changed, 294 insertions(+), 2 deletions(-) create mode 100644 detection_2d/detection_2d_rt_detr/eval/CMakeLists.txt create mode 100644 detection_2d/detection_2d_rt_detr/eval/eval_detection_2d_rt_detr.cpp create mode 100644 detection_2d/detection_2d_yolov8/eval/CMakeLists.txt create mode 100644 detection_2d/detection_2d_yolov8/eval/eval_detection_2d_yolov8.cpp diff --git a/detection_2d/detection_2d_rt_detr/CMakeLists.txt b/detection_2d/detection_2d_rt_detr/CMakeLists.txt index de4ffa3..575313b 100644 --- a/detection_2d/detection_2d_rt_detr/CMakeLists.txt +++ b/detection_2d/detection_2d_rt_detr/CMakeLists.txt @@ -35,3 +35,7 @@ endif() if (BUILD_BENCHMARK) add_subdirectory(benchmark) endif() + +if (BUILD_EVAL) + add_subdirectory(eval) +endif() diff --git a/detection_2d/detection_2d_rt_detr/eval/CMakeLists.txt b/detection_2d/detection_2d_rt_detr/eval/CMakeLists.txt new file mode 100644 index 0000000..7027c53 --- /dev/null +++ b/detection_2d/detection_2d_rt_detr/eval/CMakeLists.txt @@ -0,0 +1,49 @@ +add_compile_options(-std=c++17) +add_compile_options(-O3 -Wextra -Wdeprecated -fPIC) +set(CMAKE_CXX_STANDARD 17) + +if(ENABLE_TENSORRT) + list(APPEND platform_core_packages trt_core) +endif() + +if(ENABLE_RKNN) + list(APPEND platform_core_packages rknn_core) +endif() + +if(ENABLE_ORT) + list(APPEND platform_core_packages ort_core) +endif() + +find_package(OpenCV REQUIRED) + +set(source_file + eval_detection_2d_rt_detr.cpp +) + +include_directories( + include + ${OpenCV_INCLUDE_DIRS} +) + +add_executable(eval_detection_2d_rt_detr ${source_file}) + +target_link_libraries(eval_detection_2d_rt_detr PUBLIC + ${OpenCV_LIBS} + deploy_core + image_processing_utils + detection_2d_rt_detr + eval_utils + ${platform_core_packages} +) + +if(ENABLE_TENSORRT) + target_compile_definitions(eval_detection_2d_rt_detr PRIVATE ENABLE_TENSORRT) +endif() + +if(ENABLE_RKNN) + target_compile_definitions(eval_detection_2d_rt_detr PRIVATE ENABLE_RKNN) +endif() + +if(ENABLE_ORT) + target_compile_definitions(eval_detection_2d_rt_detr PRIVATE ENABLE_ORT) +endif() diff --git a/detection_2d/detection_2d_rt_detr/eval/eval_detection_2d_rt_detr.cpp b/detection_2d/detection_2d_rt_detr/eval/eval_detection_2d_rt_detr.cpp new file mode 100644 index 0000000..a682472 --- /dev/null +++ b/detection_2d/detection_2d_rt_detr/eval/eval_detection_2d_rt_detr.cpp @@ -0,0 +1,74 @@ +#include "eval_utils/detection_2d_eval_utils.hpp" +#include "detection_2d_util/detection_2d_util.hpp" +#include "detection_2d_rt_detr/rt_detr.hpp" + +using namespace easy_deploy; + +#ifdef ENABLE_TENSORRT + +#include "trt_core/trt_core.hpp" + +class EvalAccuracyRTDetrTensorRTFixture : public EvalAccuracyDetection2DFixture { +public: + SetUpReturnType SetUp() override + { + std::string model_path = "/workspace/models/rt_detr_v2_single_input.engine"; + const int input_height = 640; + const int input_width = 640; + const int input_channels = 3; + const int cls_number = 80; + const std::vector input_blobs_name = {"images"}; + const std::vector output_blobs_name = {"labels", "boxes", "scores"}; + + auto infer_core = CreateTrtInferCore(model_path); + auto preprocess = CreateCudaDetPreProcess(); + + auto rt_detr_model = + CreateRTDetrDetectionModel(infer_core, preprocess, input_height, input_width, + input_channels, cls_number, input_blobs_name, output_blobs_name); + const std::string coco_eval_dir_path = "/workspace/test_data/coco2017/coco2017_val"; + const std::string coco_annotations_path = + "/workspace/test_data/coco2017/coco2017_annotations/instances_val2017.json"; + return {rt_detr_model, coco_eval_dir_path, coco_annotations_path}; + } +}; + +RegisterEvalAccuracyDetection2D(EvalAccuracyRTDetrTensorRTFixture); + +#endif + +#ifdef ENABLE_ORT + +#include "ort_core/ort_core.hpp" + +class EvalAccuracyRTDetrOnnxRuntimeFixture : public EvalAccuracyDetection2DFixture { +public: + SetUpReturnType SetUp() override + { + std::string model_path = "/workspace/models/rt_detr_v2_single_input.onnx"; + const int input_height = 640; + const int input_width = 640; + const int input_channels = 3; + const int cls_number = 80; + const std::vector input_blobs_name = {"images"}; + const std::vector output_blobs_name = {"labels", "boxes", "scores"}; + + auto infer_core = CreateOrtInferCore(model_path); + auto preprocess = CreateCpuDetPreProcess({0, 0, 0}, {255, 255, 255}, true, true); + + auto rt_detr_model = + CreateRTDetrDetectionModel(infer_core, preprocess, input_height, input_width, + input_channels, cls_number, input_blobs_name, output_blobs_name); + + const std::string coco_eval_dir_path = "/workspace/test_data/coco2017/coco2017_val"; + const std::string coco_annotations_path = + "/workspace/test_data/coco2017/coco2017_annotations/instances_val2017.json"; + return {rt_detr_model, coco_eval_dir_path, coco_annotations_path}; + } +}; + +RegisterEvalAccuracyDetection2D(EvalAccuracyRTDetrOnnxRuntimeFixture); + +#endif + +EVAL_MAIN() diff --git a/detection_2d/detection_2d_yolov8/CMakeLists.txt b/detection_2d/detection_2d_yolov8/CMakeLists.txt index 953f3b4..03375c3 100644 --- a/detection_2d/detection_2d_yolov8/CMakeLists.txt +++ b/detection_2d/detection_2d_yolov8/CMakeLists.txt @@ -35,3 +35,7 @@ endif() if (BUILD_BENCHMARK) add_subdirectory(benchmark) endif() + +if (BUILD_EVAL) + add_subdirectory(eval) +endif() diff --git a/detection_2d/detection_2d_yolov8/benchmark/CMakeLists.txt b/detection_2d/detection_2d_yolov8/benchmark/CMakeLists.txt index d1df83d..6bbf76e 100644 --- a/detection_2d/detection_2d_yolov8/benchmark/CMakeLists.txt +++ b/detection_2d/detection_2d_yolov8/benchmark/CMakeLists.txt @@ -14,7 +14,6 @@ if(ENABLE_ORT) list(APPEND platform_core_packages ort_core) endif() -find_package(glog REQUIRED) find_package(OpenCV REQUIRED) find_package(benchmark REQUIRED) @@ -31,7 +30,6 @@ add_executable(benchmark_detection_2d_yolov8 ${source_file}) target_link_libraries(benchmark_detection_2d_yolov8 PUBLIC benchmark::benchmark - glog::glog ${OpenCV_LIBS} deploy_core image_processing_utils diff --git a/detection_2d/detection_2d_yolov8/eval/CMakeLists.txt b/detection_2d/detection_2d_yolov8/eval/CMakeLists.txt new file mode 100644 index 0000000..df0fa88 --- /dev/null +++ b/detection_2d/detection_2d_yolov8/eval/CMakeLists.txt @@ -0,0 +1,49 @@ +add_compile_options(-std=c++17) +add_compile_options(-O3 -Wextra -Wdeprecated -fPIC) +set(CMAKE_CXX_STANDARD 17) + +if(ENABLE_TENSORRT) + list(APPEND platform_core_packages trt_core) +endif() + +if(ENABLE_RKNN) + list(APPEND platform_core_packages rknn_core) +endif() + +if(ENABLE_ORT) + list(APPEND platform_core_packages ort_core) +endif() + +find_package(OpenCV REQUIRED) + +set(source_file + eval_detection_2d_yolov8.cpp +) + +include_directories( + include + ${OpenCV_INCLUDE_DIRS} +) + +add_executable(eval_detection_2d_yolov8 ${source_file}) + +target_link_libraries(eval_detection_2d_yolov8 PUBLIC + ${OpenCV_LIBS} + deploy_core + image_processing_utils + detection_2d_yolov8 + eval_utils + ${platform_core_packages} +) + +if(ENABLE_TENSORRT) + target_compile_definitions(eval_detection_2d_yolov8 PRIVATE ENABLE_TENSORRT) +endif() + +if(ENABLE_RKNN) + target_compile_definitions(eval_detection_2d_yolov8 PRIVATE ENABLE_RKNN) +endif() + +if(ENABLE_ORT) + target_compile_definitions(eval_detection_2d_yolov8 PRIVATE ENABLE_ORT) +endif() diff --git a/detection_2d/detection_2d_yolov8/eval/eval_detection_2d_yolov8.cpp b/detection_2d/detection_2d_yolov8/eval/eval_detection_2d_yolov8.cpp new file mode 100644 index 0000000..eb866ab --- /dev/null +++ b/detection_2d/detection_2d_yolov8/eval/eval_detection_2d_yolov8.cpp @@ -0,0 +1,114 @@ +#include "eval_utils/detection_2d_eval_utils.hpp" +#include "detection_2d_util/detection_2d_util.hpp" +#include "detection_2d_yolov8/yolov8.hpp" + +using namespace easy_deploy; + +#ifdef ENABLE_TENSORRT + +#include "trt_core/trt_core.hpp" + +class EvalAccuracyYolov8TensorRTFixture : public EvalAccuracyDetection2DFixture { +public: + SetUpReturnType SetUp() override + { + std::string model_path = "/workspace/models/yolov8n.engine"; + const int input_height = 640; + const int input_width = 640; + const int input_channels = 3; + const int cls_number = 80; + const std::vector input_blobs_name = {"images"}; + const std::vector output_blobs_name = {"output0"}; + + auto infer_core = CreateTrtInferCore(model_path); + auto preprocess = CreateCudaDetPreProcess(); + auto postprocess = CreateYolov8PostProcessCpuOrigin(input_height, input_width, cls_number); + + auto yolov8_model = + CreateYolov8DetectionModel(infer_core, preprocess, postprocess, input_height, input_width, + input_channels, cls_number, input_blobs_name, output_blobs_name); + + const std::string coco_eval_dir_path = "/workspace/test_data/coco2017/coco2017_val"; + const std::string coco_annotations_path = + "/workspace/test_data/coco2017/coco2017_annotations/instances_val2017.json"; + return {yolov8_model, coco_eval_dir_path, coco_annotations_path}; + } +}; + +RegisterEvalAccuracyDetection2D(EvalAccuracyYolov8TensorRTFixture); + +#endif + +#ifdef ENABLE_ORT + +#include "ort_core/ort_core.hpp" + +class EvalAccuracyYolov8OnnxRuntimeFixture : public EvalAccuracyDetection2DFixture { +public: + SetUpReturnType SetUp() override + { + std::string model_path = "/workspace/models/yolov8n.onnx"; + const int input_height = 640; + const int input_width = 640; + const int input_channels = 3; + const int cls_number = 80; + const std::vector input_blobs_name = {"images"}; + const std::vector output_blobs_name = {"output0"}; + + auto infer_core = CreateOrtInferCore(model_path); + auto preprocess = CreateCpuDetPreProcess({0, 0, 0}, {255, 255, 255}, true, true); + auto postprocess = CreateYolov8PostProcessCpuOrigin(input_height, input_width, cls_number); + + auto yolov8_model = + CreateYolov8DetectionModel(infer_core, preprocess, postprocess, input_height, input_width, + input_channels, cls_number, input_blobs_name, output_blobs_name); + + const std::string coco_eval_dir_path = "/workspace/test_data/coco2017/coco2017_val"; + const std::string coco_annotations_path = + "/workspace/test_data/coco2017/coco2017_annotations/instances_val2017.json"; + return {yolov8_model, coco_eval_dir_path, coco_annotations_path}; + } +}; + +RegisterEvalAccuracyDetection2D(EvalAccuracyYolov8OnnxRuntimeFixture); + +#endif + +#ifdef ENABLE_RKNN + +#include "rknn_core/rknn_core.hpp" + +class EvalAccuracyYolov8RknnFixture : public EvalAccuracyDetection2DFixture { +public: + SetUpReturnType SetUp() override + { + std::string model_path = "/workspace/models/yolov8n_divide_opset11.rknn"; + const int input_height = 640; + const int input_width = 640; + const int input_channels = 3; + const int cls_number = 80; + const std::vector input_blobs_name = {"images"}; + const std::vector output_blobs_name = {"318", "onnx::ReduceSum_326", "331", + "338", "onnx::ReduceSum_346", "350", + "357", "onnx::ReduceSum_365", "369"}; + + auto infer_core = CreateRknnInferCore(model_path, {{"images", RknnInputTensorType::RK_UINT8}}); + auto preprocess = CreateCpuDetPreProcess({0, 0, 0}, {1, 1, 1}, false, false); + auto postprocess = CreateYolov8PostProcessCpuDivide(input_height, input_width, cls_number); + + auto yolov8_model = + CreateYolov8DetectionModel(infer_core, preprocess, postprocess, input_height, input_width, + input_channels, cls_number, input_blobs_name, output_blobs_name); + + const std::string coco_eval_dir_path = "/workspace/test_data/coco2017/coco2017_val"; + const std::string coco_annotations_path = + "/workspace/test_data/coco2017/coco2017_annotations/instances_val2017.json"; + return {yolov8_model, coco_eval_dir_path, coco_annotations_path}; + } +}; + +RegisterEvalAccuracyDetection2D(EvalAccuracyYolov8RknnFixture); + +#endif + +EVAL_MAIN() From 45d2501cbc25b4cdefe9c6d17d103a2d3e2b045b Mon Sep 17 00:00:00 2001 From: zz990099 <771647586@qq.com> Date: Thu, 12 Jun 2025 00:58:42 +0800 Subject: [PATCH 2/2] update submodule Signed-off-by: zz990099 <771647586@qq.com> --- easy_deploy_tool | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easy_deploy_tool b/easy_deploy_tool index ccc9f5c..c32bd0f 160000 --- a/easy_deploy_tool +++ b/easy_deploy_tool @@ -1 +1 @@ -Subproject commit ccc9f5c6886d81548f7379671109c9fd0b2916a3 +Subproject commit c32bd0f28950e8f4ffcd45706892fbb4ca18ccf6