diff --git a/detection_2d/detection_2d_rt_detr/CMakeLists.txt b/detection_2d/detection_2d_rt_detr/CMakeLists.txt index 142c8e9..de4ffa3 100644 --- a/detection_2d/detection_2d_rt_detr/CMakeLists.txt +++ b/detection_2d/detection_2d_rt_detr/CMakeLists.txt @@ -6,7 +6,6 @@ add_compile_options(-O3 -Wextra -Wdeprecated -fPIC) set(CMAKE_CXX_STANDARD 17) find_package(OpenCV REQUIRED) -find_package(glog REQUIRED) include_directories( include @@ -19,9 +18,9 @@ set(source_file src/rt_detr.cpp add_library(${PROJECT_NAME} SHARED ${source_file}) target_link_libraries(${PROJECT_NAME} PUBLIC - glog::glog ${OpenCV_LIBS} deploy_core + common_utils ) install(TARGETS ${PROJECT_NAME} diff --git a/detection_2d/detection_2d_rt_detr/benchmark/benchmark_detection_2d_rt_detr.cpp b/detection_2d/detection_2d_rt_detr/benchmark/benchmark_detection_2d_rt_detr.cpp index 6a545d1..3dfa8a9 100644 --- a/detection_2d/detection_2d_rt_detr/benchmark/benchmark_detection_2d_rt_detr.cpp +++ b/detection_2d/detection_2d_rt_detr/benchmark/benchmark_detection_2d_rt_detr.cpp @@ -1,16 +1,14 @@ #include -#include "detection_2d_util/detection_2d_util.h" -#include "detection_2d_rt_detr/rt_detr.h" +#include "detection_2d_util/detection_2d_util.hpp" +#include "detection_2d_rt_detr/rt_detr.hpp" #include "benchmark_utils/detection_2d_benchmark_utils.hpp" -using namespace inference_core; -using namespace detection_2d; -using namespace benchmark_utils; +using namespace easy_deploy; #ifdef ENABLE_TENSORRT -#include "trt_core/trt_core.h" +#include "trt_core/trt_core.hpp" std::shared_ptr CreateRTDetrTensorRTModel() { @@ -46,7 +44,7 @@ BENCHMARK(benchmark_detection_2d_rt_detr_tensorrt_async)->Arg(500)->UseRealTime( #ifdef ENABLE_ORT -#include "ort_core/ort_core.h" +#include "ort_core/ort_core.hpp" std::shared_ptr CreateRTDetrOnnxRuntimeModel() { diff --git a/detection_2d/detection_2d_rt_detr/include/detection_2d_rt_detr/rt_detr.h b/detection_2d/detection_2d_rt_detr/include/detection_2d_rt_detr/rt_detr.h deleted file mode 100644 index 2951eef..0000000 --- a/detection_2d/detection_2d_rt_detr/include/detection_2d_rt_detr/rt_detr.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * @Description: - * @Author: Teddywesside 18852056629@163.com - * @Date: 2024-11-26 19:41:34 - * @LastEditTime: 2024-12-02 19:22:30 - * @FilePath: /easy_deploy/detection_2d/detection_2d_rt_detr/include/detection_2d_rt_detr/rt_detr.h - */ -#ifndef __DETECTION_RTDETR_H -#define __DETECTION_RTDETR_H - -#include "deploy_core/base_detection.h" - -namespace detection_2d { - -std::shared_ptr CreateRTDetrDetectionModel( - const std::shared_ptr &infer_core, - const std::shared_ptr &preprocess_block, - const int input_height, - const int input_width, - const int input_channel, - const int cls_number, - const std::vector &input_blobs_name = {"images"}, - const std::vector &output_blobs_name = {"labels", "boxes", "scores"}); - -std::shared_ptr CreateRTDetrDetectionModelFactory( - std::shared_ptr infer_core_factory, - std::shared_ptr preprocess_factory, - int input_height, - int input_width, - int input_channel, - int cls_number, - const std::vector &input_blob_name, - const std::vector &output_blob_name); - -} // namespace detection_2d -#endif diff --git a/detection_2d/detection_2d_rt_detr/include/detection_2d_rt_detr/rt_detr.hpp b/detection_2d/detection_2d_rt_detr/include/detection_2d_rt_detr/rt_detr.hpp new file mode 100644 index 0000000..0bd37d5 --- /dev/null +++ b/detection_2d/detection_2d_rt_detr/include/detection_2d_rt_detr/rt_detr.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "deploy_core/base_detection.hpp" + +namespace easy_deploy { + +std::shared_ptr CreateRTDetrDetectionModel( + const std::shared_ptr &infer_core, + const std::shared_ptr &preprocess_block, + const int input_height, + const int input_width, + const int input_channel, + const int cls_number, + const std::vector &input_blobs_name = {"images"}, + const std::vector &output_blobs_name = {"labels", "boxes", "scores"}); + +std::shared_ptr CreateRTDetrDetectionModelFactory( + std::shared_ptr infer_core_factory, + std::shared_ptr preprocess_factory, + int input_height, + int input_width, + int input_channel, + int cls_number, + const std::vector &input_blob_name, + const std::vector &output_blob_name); + +} // namespace easy_deploy diff --git a/detection_2d/detection_2d_rt_detr/src/rt_detr.cpp b/detection_2d/detection_2d_rt_detr/src/rt_detr.cpp index 5dabc22..6c069b8 100644 --- a/detection_2d/detection_2d_rt_detr/src/rt_detr.cpp +++ b/detection_2d/detection_2d_rt_detr/src/rt_detr.cpp @@ -1,24 +1,24 @@ -#include "detection_2d_rt_detr/rt_detr.h" +#include "detection_2d_rt_detr/rt_detr.hpp" -namespace detection_2d { +namespace easy_deploy { class RTDetrDetection : public BaseDetectionModel { public: - RTDetrDetection(const std::shared_ptr &infer_core, - const std::shared_ptr &preprocess_block, - const int input_height, - const int input_width, - const int input_channel, - const int cls_number, - const std::vector &input_blobs_name, - const std::vector &output_blobs_name); + RTDetrDetection(const std::shared_ptr &infer_core, + const std::shared_ptr &preprocess_block, + const int input_height, + const int input_width, + const int input_channel, + const int cls_number, + const std::vector &input_blobs_name, + const std::vector &output_blobs_name); ~RTDetrDetection() = default; private: - bool PreProcess(std::shared_ptr pipeline_unit) override; + bool PreProcess(std::shared_ptr pipeline_unit) override; - bool PostProcess(std::shared_ptr pipeline_unit) override; + bool PostProcess(std::shared_ptr pipeline_unit) override; private: const std::vector input_blobs_name_; @@ -28,11 +28,11 @@ class RTDetrDetection : public BaseDetectionModel { const int input_channel_; const int cls_number_; - const std::shared_ptr infer_core_; - std::shared_ptr preprocess_block_; + const std::shared_ptr infer_core_; + std::shared_ptr preprocess_block_; }; -RTDetrDetection::RTDetrDetection(const std::shared_ptr &infer_core, +RTDetrDetection::RTDetrDetection(const std::shared_ptr &infer_core, const std::shared_ptr &preprocess_block, const int input_height, const int input_width, @@ -54,9 +54,8 @@ RTDetrDetection::RTDetrDetection(const std::shared_ptrAllocBlobsBuffer(); if (blobs_tensor->Size() != input_blobs_name_.size() + output_blobs_name_.size()) { - LOG(ERROR) << "[RTDetrDetection] Infer core should has {" - << input_blobs_name_.size() + output_blobs_name_.size() << "} blobs !" - << " but got " << blobs_tensor->Size() << " blobs"; + LOG_ERROR("[RTDetrDetection] Infer core should has {%ld} blobs, but got {%ld} blobs", + input_blobs_name_.size() + output_blobs_name_.size(), blobs_tensor->Size()); throw std::runtime_error( "[RTDetrDetection] Construction Failed!!! Got invalid blobs_num size!!!"); } @@ -72,7 +71,7 @@ RTDetrDetection::RTDetrDetection(const std::shared_ptr _package) +bool RTDetrDetection::PreProcess(std::shared_ptr _package) { auto package = std::dynamic_pointer_cast(_package); CHECK_STATE(package != nullptr, @@ -89,7 +88,7 @@ bool RTDetrDetection::PreProcess(std::shared_ptr _package) +bool RTDetrDetection::PostProcess(std::shared_ptr _package) { auto package = std::dynamic_pointer_cast(_package); CHECK_STATE(package != nullptr, @@ -135,18 +134,18 @@ bool RTDetrDetection::PostProcess(std::shared_ptr CreateRTDetrDetectionModel( - const std::shared_ptr &infer_core, - const std::shared_ptr &preprocess_block, - const int input_height, - const int input_width, - const int input_channel, - const int cls_number, - const std::vector &input_blobs_name, - const std::vector &output_blobs_name) + const std::shared_ptr &infer_core, + const std::shared_ptr &preprocess_block, + const int input_height, + const int input_width, + const int input_channel, + const int cls_number, + const std::vector &input_blobs_name, + const std::vector &output_blobs_name) { return std::make_shared(infer_core, preprocess_block, input_height, input_width, input_channel, cls_number, input_blobs_name, output_blobs_name); } -} // namespace detection_2d +} // namespace easy_deploy diff --git a/detection_2d/detection_2d_rt_detr/src/rt_detr_factory.cpp b/detection_2d/detection_2d_rt_detr/src/rt_detr_factory.cpp index b8d03d6..f8a151c 100644 --- a/detection_2d/detection_2d_rt_detr/src/rt_detr_factory.cpp +++ b/detection_2d/detection_2d_rt_detr/src/rt_detr_factory.cpp @@ -1,30 +1,23 @@ -/* - * @Description: - * @Author: Teddywesside 18852056629@163.com - * @Date: 2024-12-02 19:22:45 - * @LastEditTime: 2024-12-02 19:33:03 - * @FilePath: /easy_deploy/detection_2d/detection_2d_rt_detr/src/rt_detr_factory.cpp - */ -#include "detection_2d_rt_detr/rt_detr.h" +#include "detection_2d_rt_detr/rt_detr.hpp" -namespace detection_2d { +namespace easy_deploy { struct RTDetrParams { - std::shared_ptr infer_core_factory; - std::shared_ptr preprocess_factory; - int input_height; - int input_width; - int input_channel; - int cls_number; - std::vector input_blob_name; - std::vector output_blob_name; + std::shared_ptr infer_core_factory; + std::shared_ptr preprocess_factory; + int input_height; + int input_width; + int input_channel; + int cls_number; + std::vector input_blob_name; + std::vector output_blob_name; }; class Detection2DRTDetrFactory : public BaseDetection2DFactory { public: Detection2DRTDetrFactory(const RTDetrParams ¶ms) : params_(params) {} - std::shared_ptr Create() override + std::shared_ptr Create() override { return CreateRTDetrDetectionModel( params_.infer_core_factory->Create(), params_.preprocess_factory->Create(), @@ -37,14 +30,14 @@ class Detection2DRTDetrFactory : public BaseDetection2DFactory { }; std::shared_ptr CreateRTDetrDetectionModelFactory( - std::shared_ptr infer_core_factory, - std::shared_ptr preprocess_factory, - int input_height, - int input_width, - int input_channel, - int cls_number, - const std::vector &input_blob_name, - const std::vector &output_blob_name) + std::shared_ptr infer_core_factory, + std::shared_ptr preprocess_factory, + int input_height, + int input_width, + int input_channel, + int cls_number, + const std::vector &input_blob_name, + const std::vector &output_blob_name) { if (infer_core_factory == nullptr || preprocess_factory == nullptr) { @@ -52,16 +45,16 @@ std::shared_ptr CreateRTDetrDetectionModelFactory( } RTDetrParams params; - params.infer_core_factory = infer_core_factory; - params.preprocess_factory = preprocess_factory; - params.input_height = input_height; - params.input_width = input_width; - params.input_channel = input_channel; - params.cls_number = cls_number; - params.input_blob_name = input_blob_name; - params.output_blob_name = output_blob_name; + params.infer_core_factory = infer_core_factory; + params.preprocess_factory = preprocess_factory; + params.input_height = input_height; + params.input_width = input_width; + params.input_channel = input_channel; + params.cls_number = cls_number; + params.input_blob_name = input_blob_name; + params.output_blob_name = output_blob_name; return std::make_shared(params); } -} // namespace detection_2d +} // namespace easy_deploy diff --git a/detection_2d/detection_2d_rt_detr/test/test_detection_2d_rt_detr.cpp b/detection_2d/detection_2d_rt_detr/test/test_detection_2d_rt_detr.cpp index 1e3b506..6789ae9 100644 --- a/detection_2d/detection_2d_rt_detr/test/test_detection_2d_rt_detr.cpp +++ b/detection_2d/detection_2d_rt_detr/test/test_detection_2d_rt_detr.cpp @@ -1,12 +1,10 @@ #include -#include "detection_2d_util/detection_2d_util.h" -#include "detection_2d_rt_detr/rt_detr.h" +#include "detection_2d_util/detection_2d_util.hpp" +#include "detection_2d_rt_detr/rt_detr.hpp" #include "test_utils/detection_2d_test_utils.hpp" -using namespace inference_core; -using namespace detection_2d; -using namespace test_utils; +using namespace easy_deploy; #define GEN_TEST_CASES(Tag, FixtureClass) \ TEST_F(FixtureClass, test_rt_detr_##Tag##_correctness) \ @@ -33,7 +31,7 @@ class BaseRTDetrFixture : public testing::Test { #ifdef ENABLE_TENSORRT -#include "trt_core/trt_core.h" +#include "trt_core/trt_core.hpp" class RTDetr_TensorRT_Fixture : public BaseRTDetrFixture { public: @@ -67,7 +65,7 @@ GEN_TEST_CASES(tensorrt, RTDetr_TensorRT_Fixture); #ifdef ENABLE_ORT -#include "ort_core/ort_core.h" +#include "ort_core/ort_core.hpp" class RTDetr_OnnxRuntime_Fixture : public BaseRTDetrFixture { public: diff --git a/detection_2d/detection_2d_yolov8/CMakeLists.txt b/detection_2d/detection_2d_yolov8/CMakeLists.txt index 8d58d24..953f3b4 100644 --- a/detection_2d/detection_2d_yolov8/CMakeLists.txt +++ b/detection_2d/detection_2d_yolov8/CMakeLists.txt @@ -6,7 +6,6 @@ add_compile_options(-O3 -Wextra -Wdeprecated -fPIC) set(CMAKE_CXX_STANDARD 17) find_package(OpenCV REQUIRED) -find_package(glog REQUIRED) include_directories( include @@ -19,9 +18,9 @@ set(source_file src/yolov8.cpp add_library(${PROJECT_NAME} SHARED ${source_file}) target_link_libraries(${PROJECT_NAME} PUBLIC - glog::glog ${OpenCV_LIBS} deploy_core + common_utils ) install(TARGETS ${PROJECT_NAME} diff --git a/detection_2d/detection_2d_yolov8/benchmark/benchmark_detection_2d_yolov8.cpp b/detection_2d/detection_2d_yolov8/benchmark/benchmark_detection_2d_yolov8.cpp index edca386..4da881e 100644 --- a/detection_2d/detection_2d_yolov8/benchmark/benchmark_detection_2d_yolov8.cpp +++ b/detection_2d/detection_2d_yolov8/benchmark/benchmark_detection_2d_yolov8.cpp @@ -1,16 +1,14 @@ #include -#include "detection_2d_util/detection_2d_util.h" -#include "detection_2d_yolov8/yolov8.h" +#include "detection_2d_util/detection_2d_util.hpp" +#include "detection_2d_yolov8/yolov8.hpp" #include "benchmark_utils/detection_2d_benchmark_utils.hpp" -using namespace inference_core; -using namespace detection_2d; -using namespace benchmark_utils; +using namespace easy_deploy; #ifdef ENABLE_TENSORRT -#include "trt_core/trt_core.h" +#include "trt_core/trt_core.hpp" std::shared_ptr CreateYolov8TensorRTModel() { @@ -47,7 +45,7 @@ BENCHMARK(benchmark_detection_2d_yolov8_tensorrt_async)->Arg(1000)->UseRealTime( #ifdef ENABLE_ORT -#include "ort_core/ort_core.h" +#include "ort_core/ort_core.hpp" std::shared_ptr CreateYolov8OnnxRuntimeModel() { @@ -84,7 +82,7 @@ BENCHMARK(benchmark_detection_2d_yolov8_onnxruntime_async)->Arg(200)->UseRealTim #ifdef ENABLE_RKNN -#include "rknn_core/rknn_core.h" +#include "rknn_core/rknn_core.hpp" std::shared_ptr CreateYolov8RknnModel() { diff --git a/detection_2d/detection_2d_yolov8/include/detection_2d_yolov8/yolov8.h b/detection_2d/detection_2d_yolov8/include/detection_2d_yolov8/yolov8.h deleted file mode 100644 index 65e2a37..0000000 --- a/detection_2d/detection_2d_yolov8/include/detection_2d_yolov8/yolov8.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * @Description: - * @Author: Teddywesside 18852056629@163.com - * @Date: 2024-11-26 19:41:34 - * @LastEditTime: 2024-12-02 19:20:57 - * @FilePath: /easy_deploy/detection_2d/detection_2d_yolov8/include/detection_2d_yolov8/yolov8.h - */ -#ifndef __EASY_DEPLOY_DETECTION_YOLOV8_H -#define __EASY_DEPLOY_DETECTION_YOLOV8_H - -#include "deploy_core/base_detection.h" -#include "deploy_core/base_infer_core.h" - -namespace detection_2d { - -/** - * @brief Create a Yolov 8 Detection Model instance - * - * @param infer_core - * @param preprocess_block - * @param postprocess_block - * @param input_height - * @param input_width - * @param input_channel - * @param cls_number - * @param input_blob_name - * @param output_blob_name - * @param downsample_scales - * @return std::shared_ptr - */ -std::shared_ptr CreateYolov8DetectionModel( - const std::shared_ptr &infer_core, - const std::shared_ptr &preprocess_block, - const std::shared_ptr &postprocess_block, - const int input_height, - const int input_width, - const int input_channel, - const int cls_number, - const std::vector &input_blob_name, - const std::vector &output_blob_name, - const std::vector downsample_scales = {8, 16, 32}); - -std::shared_ptr CreateYolov8DetectionModelFactory( - std::shared_ptr infer_core_factory, - std::shared_ptr preprocess_factory, - std::shared_ptr postprocess_factory, - int input_height, - int input_width, - int input_channel, - int cls_number, - const std::vector &input_blob_name, - const std::vector &output_blob_name, - const std::vector &downsample_scales = {8, 16, 32}); - -} // namespace detection_2d -#endif diff --git a/detection_2d/detection_2d_yolov8/include/detection_2d_yolov8/yolov8.hpp b/detection_2d/detection_2d_yolov8/include/detection_2d_yolov8/yolov8.hpp new file mode 100644 index 0000000..6957ecd --- /dev/null +++ b/detection_2d/detection_2d_yolov8/include/detection_2d_yolov8/yolov8.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include "deploy_core/base_detection.hpp" +#include "deploy_core/base_infer_core.hpp" + +namespace easy_deploy { + +/** + * @brief Create a Yolov 8 Detection Model instance + * + * @param infer_core + * @param preprocess_block + * @param postprocess_block + * @param input_height + * @param input_width + * @param input_channel + * @param cls_number + * @param input_blob_name + * @param output_blob_name + * @param downsample_scales + * @return std::shared_ptr + */ +std::shared_ptr CreateYolov8DetectionModel( + const std::shared_ptr &infer_core, + const std::shared_ptr &preprocess_block, + const std::shared_ptr &postprocess_block, + const int input_height, + const int input_width, + const int input_channel, + const int cls_number, + const std::vector &input_blob_name, + const std::vector &output_blob_name, + const std::vector downsample_scales = {8, 16, 32}); + +std::shared_ptr CreateYolov8DetectionModelFactory( + std::shared_ptr infer_core_factory, + std::shared_ptr preprocess_factory, + std::shared_ptr postprocess_factory, + int input_height, + int input_width, + int input_channel, + int cls_number, + const std::vector &input_blob_name, + const std::vector &output_blob_name, + const std::vector &downsample_scales = {8, 16, 32}); + +} // namespace easy_deploy diff --git a/detection_2d/detection_2d_yolov8/src/yolov8.cpp b/detection_2d/detection_2d_yolov8/src/yolov8.cpp index 7d96bfd..cc7e87d 100644 --- a/detection_2d/detection_2d_yolov8/src/yolov8.cpp +++ b/detection_2d/detection_2d_yolov8/src/yolov8.cpp @@ -1,33 +1,26 @@ -/* - * @Description: - * @Author: Teddywesside 18852056629@163.com - * @Date: 2024-11-26 19:41:34 - * @LastEditTime: 2024-12-03 15:57:46 - * @FilePath: /EasyDeploy/detection_2d/detection_2d_yolov8/src/yolov8.cpp - */ -#include "detection_2d_yolov8/yolov8.h" +#include "detection_2d_yolov8/yolov8.hpp" -namespace detection_2d { +namespace easy_deploy { class Yolov8Detection : public BaseDetectionModel { public: - Yolov8Detection(const std::shared_ptr &infer_core, - const std::shared_ptr &preprocess_block, - const std::shared_ptr &postprocess_block, - const int input_height, - const int input_width, - const int input_channel, - const int cls_number, - const std::vector &input_blobs_name, - const std::vector &output_blobs_name, - const std::vector downsample_scales = {8, 16, 32}); + Yolov8Detection(const std::shared_ptr &infer_core, + const std::shared_ptr &preprocess_block, + const std::shared_ptr &postprocess_block, + const int input_height, + const int input_width, + const int input_channel, + const int cls_number, + const std::vector &input_blobs_name, + const std::vector &output_blobs_name, + const std::vector downsample_scales = {8, 16, 32}); ~Yolov8Detection() = default; private: - bool PreProcess(std::shared_ptr pipeline_unit) override; + bool PreProcess(std::shared_ptr pipeline_unit) override; - bool PostProcess(std::shared_ptr pipeline_unit) override; + bool PostProcess(std::shared_ptr pipeline_unit) override; private: const std::vector input_blobs_name_; @@ -39,12 +32,12 @@ class Yolov8Detection : public BaseDetectionModel { const std::vector downsample_scales_; - const std::shared_ptr infer_core_; - std::shared_ptr preprocess_block_; - std::shared_ptr postprocess_block_; + const std::shared_ptr infer_core_; + std::shared_ptr preprocess_block_; + std::shared_ptr postprocess_block_; }; -Yolov8Detection::Yolov8Detection(const std::shared_ptr &infer_core, +Yolov8Detection::Yolov8Detection(const std::shared_ptr &infer_core, const std::shared_ptr &preprocess_block, const std::shared_ptr &postprocess_block, const int input_height, @@ -70,9 +63,8 @@ Yolov8Detection::Yolov8Detection(const std::shared_ptrAllocBlobsBuffer(); if (blobs_tensor->Size() != input_blobs_name_.size() + output_blobs_name_.size()) { - LOG(ERROR) << "[Yolov8Detection] Infer core should has {" - << input_blobs_name_.size() + output_blobs_name_.size() << "} blobs !" - << " but got " << blobs_tensor->Size() << " blobs"; + LOG_ERROR("[Yolov8Detection] Infer core should has {%ld} blobs, but got {%ld} blobs", + input_blobs_name_.size() + output_blobs_name_.size(), blobs_tensor->Size()); throw std::runtime_error("[Yolov8Detection] Got invalid input arguments!!"); } @@ -90,18 +82,18 @@ Yolov8Detection::Yolov8Detection(const std::shared_ptr _package) +bool Yolov8Detection::PreProcess(std::shared_ptr _package) { auto package = std::dynamic_pointer_cast(_package); CHECK_STATE(package != nullptr, @@ -118,7 +110,7 @@ bool Yolov8Detection::PreProcess(std::shared_ptr _package) +bool Yolov8Detection::PostProcess(std::shared_ptr _package) { auto package = std::dynamic_pointer_cast(_package); CHECK_STATE(package != nullptr, @@ -140,20 +132,20 @@ bool Yolov8Detection::PostProcess(std::shared_ptr CreateYolov8DetectionModel( - const std::shared_ptr &infer_core, - const std::shared_ptr &preprocess_block, - const std::shared_ptr &postprocess_block, - const int input_height, - const int input_width, - const int input_channel, - const int cls_number, - const std::vector &input_blobs_name, - const std::vector &output_blobs_name, - const std::vector downsample_scales) + const std::shared_ptr &infer_core, + const std::shared_ptr &preprocess_block, + const std::shared_ptr &postprocess_block, + const int input_height, + const int input_width, + const int input_channel, + const int cls_number, + const std::vector &input_blobs_name, + const std::vector &output_blobs_name, + const std::vector downsample_scales) { return std::make_shared(infer_core, preprocess_block, postprocess_block, input_height, input_width, input_channel, cls_number, input_blobs_name, output_blobs_name, downsample_scales); } -} // namespace detection_2d +} // namespace easy_deploy diff --git a/detection_2d/detection_2d_yolov8/src/yolov8_factory.cpp b/detection_2d/detection_2d_yolov8/src/yolov8_factory.cpp index 903197f..cb31463 100644 --- a/detection_2d/detection_2d_yolov8/src/yolov8_factory.cpp +++ b/detection_2d/detection_2d_yolov8/src/yolov8_factory.cpp @@ -1,32 +1,25 @@ -/* - * @Description: - * @Author: Teddywesside 18852056629@163.com - * @Date: 2024-12-02 19:08:10 - * @LastEditTime: 2024-12-02 19:31:43 - * @FilePath: /easy_deploy/detection_2d/detection_2d_yolov8/src/yolov8_factory.cpp - */ -#include "detection_2d_yolov8/yolov8.h" +#include "detection_2d_yolov8/yolov8.hpp" -namespace detection_2d { +namespace easy_deploy { struct Yolov8Params { - std::shared_ptr infer_core_factory; - std::shared_ptr preprocess_factory; - std::shared_ptr postprocess_factory; - int input_height; - int input_width; - int input_channel; - int cls_number; - std::vector input_blob_name; - std::vector output_blob_name; - std::vector downsample_scales; + std::shared_ptr infer_core_factory; + std::shared_ptr preprocess_factory; + std::shared_ptr postprocess_factory; + int input_height; + int input_width; + int input_channel; + int cls_number; + std::vector input_blob_name; + std::vector output_blob_name; + std::vector downsample_scales; }; class Detection2DYolov8Factory : public BaseDetection2DFactory { public: Detection2DYolov8Factory(const Yolov8Params ¶ms) : params_(params) {} - std::shared_ptr Create() override + std::shared_ptr Create() override { return CreateYolov8DetectionModel( params_.infer_core_factory->Create(), params_.preprocess_factory->Create(), @@ -40,16 +33,16 @@ class Detection2DYolov8Factory : public BaseDetection2DFactory { }; std::shared_ptr CreateYolov8DetectionModelFactory( - std::shared_ptr infer_core_factory, - std::shared_ptr preprocess_factory, - std::shared_ptr postprocess_factory, - int input_height, - int input_width, - int input_channel, - int cls_number, - const std::vector &input_blob_name, - const std::vector &output_blob_name, - const std::vector &downsample_scales) + std::shared_ptr infer_core_factory, + std::shared_ptr preprocess_factory, + std::shared_ptr postprocess_factory, + int input_height, + int input_width, + int input_channel, + int cls_number, + const std::vector &input_blob_name, + const std::vector &output_blob_name, + const std::vector &downsample_scales) { if (infer_core_factory == nullptr || preprocess_factory == nullptr || postprocess_factory == nullptr) @@ -72,4 +65,4 @@ std::shared_ptr CreateYolov8DetectionModelFactory( return std::make_shared(params); } -} // namespace detection_2d +} // namespace easy_deploy diff --git a/detection_2d/detection_2d_yolov8/test/test_detection_2d_yolov8.cpp b/detection_2d/detection_2d_yolov8/test/test_detection_2d_yolov8.cpp index af37d6e..e12ae14 100644 --- a/detection_2d/detection_2d_yolov8/test/test_detection_2d_yolov8.cpp +++ b/detection_2d/detection_2d_yolov8/test/test_detection_2d_yolov8.cpp @@ -1,12 +1,10 @@ #include -#include "detection_2d_util/detection_2d_util.h" -#include "detection_2d_yolov8/yolov8.h" +#include "detection_2d_util/detection_2d_util.hpp" +#include "detection_2d_yolov8/yolov8.hpp" #include "test_utils/detection_2d_test_utils.hpp" -using namespace inference_core; -using namespace detection_2d; -using namespace test_utils; +using namespace easy_deploy; #define GEN_TEST_CASES(Tag, FixtureClass) \ TEST_F(FixtureClass, test_yolov8_##Tag##_correctness) \ @@ -33,7 +31,7 @@ class BaseYolov8Fixture : public testing::Test { #ifdef ENABLE_TENSORRT -#include "trt_core/trt_core.h" +#include "trt_core/trt_core.hpp" class Yolov8_TensorRT_Fixture : public BaseYolov8Fixture { public: @@ -68,7 +66,7 @@ GEN_TEST_CASES(tensorrt, Yolov8_TensorRT_Fixture); #ifdef ENABLE_ORT -#include "ort_core/ort_core.h" +#include "ort_core/ort_core.hpp" class Yolov8_OnnxRuntime_Fixture : public BaseYolov8Fixture { public: @@ -103,7 +101,7 @@ GEN_TEST_CASES(onnxruntime, Yolov8_OnnxRuntime_Fixture); #ifdef ENABLE_RKNN -#include "rknn_core/rknn_core.h" +#include "rknn_core/rknn_core.hpp" class Yolov8_Rknn_Fixture : public BaseYolov8Fixture { public: diff --git a/easy_deploy_tool b/easy_deploy_tool index 6c254c6..ccc9f5c 160000 --- a/easy_deploy_tool +++ b/easy_deploy_tool @@ -1 +1 @@ -Subproject commit 6c254c6d53e429513d46924f96fb1e543364497f +Subproject commit ccc9f5c6886d81548f7379671109c9fd0b2916a3 diff --git a/sam/sam_mobilesam/CMakeLists.txt b/sam/sam_mobilesam/CMakeLists.txt index ac8dfe4..146b141 100644 --- a/sam/sam_mobilesam/CMakeLists.txt +++ b/sam/sam_mobilesam/CMakeLists.txt @@ -6,8 +6,6 @@ add_compile_options(-O3 -Wextra -Wdeprecated -fPIC) set(CMAKE_CXX_STANDARD 17) find_package(OpenCV REQUIRED) -find_package(glog REQUIRED) - set(source_file src/mobilesam.cpp src/mobilesam_factory.cpp) @@ -20,9 +18,9 @@ include_directories( add_library(${PROJECT_NAME} SHARED ${source_file}) target_link_libraries(${PROJECT_NAME} PUBLIC - glog::glog ${OpenCV_LIBS} deploy_core + common_utils ) install(TARGETS ${PROJECT_NAME} diff --git a/sam/sam_mobilesam/benchmark/benchmark_sam_mobilesam.cpp b/sam/sam_mobilesam/benchmark/benchmark_sam_mobilesam.cpp index fbfa1a5..4f94e85 100644 --- a/sam/sam_mobilesam/benchmark/benchmark_sam_mobilesam.cpp +++ b/sam/sam_mobilesam/benchmark/benchmark_sam_mobilesam.cpp @@ -1,17 +1,14 @@ #include -#include "detection_2d_util/detection_2d_util.h" -#include "sam_mobilesam/mobilesam.h" +#include "detection_2d_util/detection_2d_util.hpp" +#include "sam_mobilesam/mobilesam.hpp" #include "benchmark_utils/sam_benchmark_utils.hpp" -using namespace inference_core; -using namespace detection_2d; -using namespace sam; -using namespace benchmark_utils; +using namespace easy_deploy; #ifdef ENABLE_TENSORRT -#include "trt_core/trt_core.h" +#include "trt_core/trt_core.hpp" std::shared_ptr CreateSAMTensorRTModel(const std::string &image_encoder_model_path) { @@ -82,7 +79,7 @@ BENCHMARK(benchmark_sam_nanosam_tensorrt_async)->Arg(200)->UseRealTime(); #ifdef ENABLE_ORT -#include "ort_core/ort_core.h" +#include "ort_core/ort_core.hpp" std::shared_ptr CreateSAMOnnxRuntimeModel(const std::string &image_encoder_model_path) { @@ -154,7 +151,7 @@ BENCHMARK(benchmark_sam_nanosam_onnxruntime_async)->Arg(50)->UseRealTime(); #ifdef ENABLE_RKNN -#include "rknn_core/rknn_core.h" +#include "rknn_core/rknn_core.hpp" std::shared_ptr CreateSAMRknnModel(const std::string &image_encoder_model_path) { diff --git a/sam/sam_mobilesam/include/sam_mobilesam/mobilesam.h b/sam/sam_mobilesam/include/sam_mobilesam/mobilesam.h deleted file mode 100644 index 1030583..0000000 --- a/sam/sam_mobilesam/include/sam_mobilesam/mobilesam.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * @Description: - * @Author: Teddywesside 18852056629@163.com - * @Date: 2024-11-26 19:41:34 - * @LastEditTime: 2024-12-02 18:55:08 - * @FilePath: /easy_deploy/sam/sam_mobilesam/include/sam_mobilesam/mobilesam.h - */ -#ifndef __EASY_DEPLOY_MOBILE_SAM_H -#define __EASY_DEPLOY_MOBILE_SAM_H - -#include "deploy_core/base_sam.h" -#include "deploy_core/base_detection.h" - -namespace sam { - -std::shared_ptr CreateMobileSamModel( - std::shared_ptr image_encoder_core, - std::shared_ptr mask_points_decoder_core, - std::shared_ptr mask_boxes_decoder_core, - std::shared_ptr image_preprocess_block, - const std::vector &encoder_blob_names = {"images", "features"}, - const std::vector &box_dec_blob_names = {"image_embeddings", "boxes", "mask_input", - "has_mask_input", "masks", "scores"}, - const std::vector &point_dec_blob_names = {"image_embeddings", "point_coords", - "point_labels", "mask_input", - "has_mask_input", "masks", "scores"}); - -std::shared_ptr CreateSamMobileSamModelFactory( - std::shared_ptr image_encoder_core_factory, - std::shared_ptr mask_points_decoder_core_factory, - std::shared_ptr mask_boxes_decoder_core_factory, - std::shared_ptr image_preprocess_block_factory, - const std::vector &encoder_blob_names = {"images", "features"}, - const std::vector &box_dec_blob_names = {"image_embeddings", "boxes", "mask_input", - "has_mask_input", "masks", "scores"}, - const std::vector &point_dec_blob_names = {"image_embeddings", "point_coords", - "point_labels", "mask_input", - "has_mask_input", "masks", "scores"}); - -} // namespace sam -#endif diff --git a/sam/sam_mobilesam/include/sam_mobilesam/mobilesam.hpp b/sam/sam_mobilesam/include/sam_mobilesam/mobilesam.hpp new file mode 100644 index 0000000..408ce4e --- /dev/null +++ b/sam/sam_mobilesam/include/sam_mobilesam/mobilesam.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "deploy_core/base_sam.hpp" +#include "deploy_core/base_detection.hpp" + +namespace easy_deploy { + +std::shared_ptr CreateMobileSamModel( + std::shared_ptr image_encoder_core, + std::shared_ptr mask_points_decoder_core, + std::shared_ptr mask_boxes_decoder_core, + std::shared_ptr image_preprocess_block, + const std::vector &encoder_blob_names = {"images", "features"}, + const std::vector &box_dec_blob_names = {"image_embeddings", "boxes", "mask_input", + "has_mask_input", "masks", "scores"}, + const std::vector &point_dec_blob_names = {"image_embeddings", "point_coords", + "point_labels", "mask_input", + "has_mask_input", "masks", "scores"}); + +std::shared_ptr CreateSamMobileSamModelFactory( + std::shared_ptr image_encoder_core_factory, + std::shared_ptr mask_points_decoder_core_factory, + std::shared_ptr mask_boxes_decoder_core_factory, + std::shared_ptr image_preprocess_block_factory, + const std::vector &encoder_blob_names = {"images", "features"}, + const std::vector &box_dec_blob_names = {"image_embeddings", "boxes", "mask_input", + "has_mask_input", "masks", "scores"}, + const std::vector &point_dec_blob_names = {"image_embeddings", "point_coords", + "point_labels", "mask_input", + "has_mask_input", "masks", "scores"}); + +} // namespace easy_deploy diff --git a/sam/sam_mobilesam/src/mobilesam.cpp b/sam/sam_mobilesam/src/mobilesam.cpp index efe08d5..55e7882 100644 --- a/sam/sam_mobilesam/src/mobilesam.cpp +++ b/sam/sam_mobilesam/src/mobilesam.cpp @@ -1,11 +1,11 @@ -#include "sam_mobilesam/mobilesam.h" +#include "sam_mobilesam/mobilesam.hpp" -#include "deploy_core/wrapper.h" +#include "deploy_core/wrapper.hpp" #include #include -namespace sam { +namespace easy_deploy { static void ThrowRuntimeError(const std::string &hint, uint64_t line_num) { @@ -13,9 +13,9 @@ static void ThrowRuntimeError(const std::string &hint, uint64_t line_num) throw std::runtime_error(exception_message); } -static void CheckBlobNameMatched(const std::string &infer_core_name, - const std::shared_ptr &infer_core, - const std::vector &blob_names) +static void CheckBlobNameMatched(const std::string &infer_core_name, + const std::shared_ptr &infer_core, + const std::vector &blob_names) { auto blobs_tensor = infer_core->AllocBlobsBuffer(); if (blob_names.size() != blobs_tensor->Size()) @@ -93,13 +93,13 @@ static void rknn_nchw_2_nhwc(float *nchw, float *nhwc, int N, int C, int H, int class MobileSam : public BaseSamModel { public: - MobileSam(std::shared_ptr image_encoder_core, - std::shared_ptr mask_points_decoder_core, - std::shared_ptr mask_boxes_decoder_core, - std::shared_ptr image_preprocess_block, - const std::vector &encoder_blob_names, - const std::vector &box_dec_blob_names, - const std::vector &point_dec_blob_names); + MobileSam(std::shared_ptr image_encoder_core, + std::shared_ptr mask_points_decoder_core, + std::shared_ptr mask_boxes_decoder_core, + std::shared_ptr image_preprocess_block, + const std::vector &encoder_blob_names, + const std::vector &box_dec_blob_names, + const std::vector &point_dec_blob_names); ~MobileSam() = default; @@ -120,7 +120,7 @@ class MobileSam : public BaseSamModel { const std::vector box_dec_blob_names_; const std::vector point_dec_blob_names_; - std::shared_ptr image_preprocess_block_; + std::shared_ptr image_preprocess_block_; private: // defualt params, no access provided to user @@ -136,13 +136,13 @@ class MobileSam : public BaseSamModel { const std::string MobileSam::model_name_ = "MobileSam"; -MobileSam::MobileSam(std::shared_ptr image_encoder_core, - std::shared_ptr mask_points_decoder_core, - std::shared_ptr mask_boxes_decoder_core, - std::shared_ptr image_preprocess_block, - const std::vector &encoder_blob_names, - const std::vector &box_dec_blob_names, - const std::vector &point_dec_blob_names) +MobileSam::MobileSam(std::shared_ptr image_encoder_core, + std::shared_ptr mask_points_decoder_core, + std::shared_ptr mask_boxes_decoder_core, + std::shared_ptr image_preprocess_block, + const std::vector &encoder_blob_names, + const std::vector &box_dec_blob_names, + const std::vector &point_dec_blob_names) : BaseSamModel( model_name_, image_encoder_core, mask_points_decoder_core, mask_boxes_decoder_core), image_preprocess_block_(image_preprocess_block), @@ -202,10 +202,10 @@ bool MobileSam::PromptBoxPreProcess(ParsingType package) auto image_features_ptr = encoder_output_tensor->Cast(); ////////////////// Transpose if decoder is rknn framework ////////////////// - if (mask_boxes_decoder_core_->GetType() == inference_core::InferCoreType::RKNN) + if (mask_boxes_decoder_core_->GetType() == InferCoreType::RKNN) { - LOG(WARNING) - << "[MobileSAM] Got rknn mask box decoder! Transposing Image Features to `NHWC` format!!!"; + LOG_DEBUG( + "[MobileSAM] Got rknn mask box decoder! Transposing Image Features to `NHWC` format!!!"); const size_t total_image_feature_elements_num = IMAGE_FEATURE_HEIGHT * IMAGE_FEATURE_WIDTH * IMAGE_FEATURES_LEN; std::vector hwc_buffer(total_image_feature_elements_num); @@ -264,10 +264,10 @@ bool MobileSam::PromptPointPreProcess(ParsingType package) auto image_features_ptr = encoder_output_tensor->Cast(); ////////////////// Transpose if decoder is rknn framework ////////////////// - if (mask_boxes_decoder_core_->GetType() == inference_core::InferCoreType::RKNN) + if (mask_boxes_decoder_core_->GetType() == InferCoreType::RKNN) { - LOG(WARNING) - << "[MobileSAM] Got rknn mask box decoder! Transposing Image Features to `NHWC` format!!!"; + LOG_DEBUG( + "[MobileSAM] Got rknn mask box decoder! Transposing Image Features to `NHWC` format!!!"); const size_t total_image_feature_elements_num = IMAGE_FEATURE_HEIGHT * IMAGE_FEATURE_WIDTH * IMAGE_FEATURES_LEN; std::vector hwc_buffer(total_image_feature_elements_num); @@ -355,17 +355,17 @@ bool MobileSam::MaskPostProcess(ParsingType package) } std::shared_ptr CreateMobileSamModel( - std::shared_ptr image_encoder_core, - std::shared_ptr mask_points_decoder_core, - std::shared_ptr mask_boxes_decoder_core, - std::shared_ptr image_preprocess_block, - const std::vector &encoder_blob_names, - const std::vector &box_dec_blob_names, - const std::vector &point_dec_blob_names) + std::shared_ptr image_encoder_core, + std::shared_ptr mask_points_decoder_core, + std::shared_ptr mask_boxes_decoder_core, + std::shared_ptr image_preprocess_block, + const std::vector &encoder_blob_names, + const std::vector &box_dec_blob_names, + const std::vector &point_dec_blob_names) { return std::make_shared(image_encoder_core, mask_points_decoder_core, mask_boxes_decoder_core, image_preprocess_block, encoder_blob_names, box_dec_blob_names, point_dec_blob_names); } -} // namespace sam +} // namespace easy_deploy diff --git a/sam/sam_mobilesam/src/mobilesam_factory.cpp b/sam/sam_mobilesam/src/mobilesam_factory.cpp index def3d2c..3a39d40 100644 --- a/sam/sam_mobilesam/src/mobilesam_factory.cpp +++ b/sam/sam_mobilesam/src/mobilesam_factory.cpp @@ -1,22 +1,15 @@ -/* - * @Description: - * @Author: Teddywesside 18852056629@163.com - * @Date: 2024-12-02 18:58:26 - * @LastEditTime: 2024-12-02 19:09:02 - * @FilePath: /easy_deploy/sam/sam_mobilesam/src/mobilesam_factory.cpp - */ -#include "sam_mobilesam/mobilesam.h" +#include "sam_mobilesam/mobilesam.hpp" -namespace sam { +namespace easy_deploy { struct SamParams { - std::shared_ptr image_encoder_core_factory; - std::shared_ptr mask_points_decoder_core_factory; - std::shared_ptr mask_boxes_decoder_core_factory; - std::shared_ptr image_preprocess_block_factory; - std::vector encoder_blob_names; - std::vector box_dec_blob_names; - std::vector point_dec_blob_names; + std::shared_ptr image_encoder_core_factory; + std::shared_ptr mask_points_decoder_core_factory; + std::shared_ptr mask_boxes_decoder_core_factory; + std::shared_ptr image_preprocess_block_factory; + std::vector encoder_blob_names; + std::vector box_dec_blob_names; + std::vector point_dec_blob_names; }; class SamMobileSamFactory : public BaseSamFactory { @@ -24,7 +17,7 @@ class SamMobileSamFactory : public BaseSamFactory { SamMobileSamFactory(const SamParams ¶ms) : params_(params) {} - std::shared_ptr Create() override + std::shared_ptr Create() override { return CreateMobileSamModel(params_.image_encoder_core_factory->Create(), params_.mask_points_decoder_core_factory->Create(), @@ -39,13 +32,13 @@ class SamMobileSamFactory : public BaseSamFactory { }; std::shared_ptr CreateSamMobileSamModelFactory( - std::shared_ptr image_encoder_core_factory, - std::shared_ptr mask_points_decoder_core_factory, - std::shared_ptr mask_boxes_decoder_core_factory, - std::shared_ptr image_preprocess_block_factory, - const std::vector &encoder_blob_names, - const std::vector &box_dec_blob_names, - const std::vector &point_dec_blob_names) + std::shared_ptr image_encoder_core_factory, + std::shared_ptr mask_points_decoder_core_factory, + std::shared_ptr mask_boxes_decoder_core_factory, + std::shared_ptr image_preprocess_block_factory, + const std::vector &encoder_blob_names, + const std::vector &box_dec_blob_names, + const std::vector &point_dec_blob_names) { if (image_encoder_core_factory == nullptr || mask_points_decoder_core_factory == nullptr || mask_boxes_decoder_core_factory == nullptr || image_preprocess_block_factory == nullptr) @@ -66,4 +59,4 @@ std::shared_ptr CreateSamMobileSamModelFactory( return std::make_shared(params); } -} // namespace sam +} // namespace easy_deploy diff --git a/sam/sam_mobilesam/test/test_sam_mobilesam.cpp b/sam/sam_mobilesam/test/test_sam_mobilesam.cpp index 55c9d6b..8e59c1b 100644 --- a/sam/sam_mobilesam/test/test_sam_mobilesam.cpp +++ b/sam/sam_mobilesam/test/test_sam_mobilesam.cpp @@ -1,13 +1,10 @@ #include -#include "detection_2d_util/detection_2d_util.h" -#include "sam_mobilesam/mobilesam.h" +#include "detection_2d_util/detection_2d_util.hpp" +#include "sam_mobilesam/mobilesam.hpp" #include "test_utils/sam_test_utils.hpp" -using namespace inference_core; -using namespace detection_2d; -using namespace sam; -using namespace test_utils; +using namespace easy_deploy; #define GEN_MOBILESAM_TEST_CASES(Tag, FixtureClass) \ TEST_F(FixtureClass, test_mobilesam_##Tag##_correctness_with_points) \ @@ -72,7 +69,7 @@ class BaseSamFixture : public testing::Test { #ifdef ENABLE_TENSORRT -#include "trt_core/trt_core.h" +#include "trt_core/trt_core.hpp" class Sam_TensorRT_Fixture : public BaseSamFixture { public: @@ -145,7 +142,7 @@ GEN_NANOSAM_TEST_CASES(tensorrt, Sam_TensorRT_Fixture); #ifdef ENABLE_ORT -#include "ort_core/ort_core.h" +#include "ort_core/ort_core.hpp" class Sam_OnnxRuntime_Fixture : public BaseSamFixture { public: @@ -219,7 +216,7 @@ GEN_NANOSAM_TEST_CASES(onnxruntime, Sam_OnnxRuntime_Fixture); #ifdef ENABLE_RKNN -#include "rknn_core/rknn_core.h" +#include "rknn_core/rknn_core.hpp" class Sam_Rknn_Fixture : public BaseSamFixture { public: