Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions detection_2d/detection_2d_rt_detr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#include <gtest/gtest.h>

#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<BaseDetectionModel> CreateRTDetrTensorRTModel()
{
Expand Down Expand Up @@ -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<BaseDetectionModel> CreateRTDetrOnnxRuntimeModel()
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "deploy_core/base_detection.hpp"

namespace easy_deploy {

std::shared_ptr<BaseDetectionModel> CreateRTDetrDetectionModel(
const std::shared_ptr<BaseInferCore> &infer_core,
const std::shared_ptr<IDetectionPreProcess> &preprocess_block,
const int input_height,
const int input_width,
const int input_channel,
const int cls_number,
const std::vector<std::string> &input_blobs_name = {"images"},
const std::vector<std::string> &output_blobs_name = {"labels", "boxes", "scores"});

std::shared_ptr<BaseDetection2DFactory> CreateRTDetrDetectionModelFactory(
std::shared_ptr<BaseInferCoreFactory> infer_core_factory,
std::shared_ptr<BaseDetectionPreprocessFactory> preprocess_factory,
int input_height,
int input_width,
int input_channel,
int cls_number,
const std::vector<std::string> &input_blob_name,
const std::vector<std::string> &output_blob_name);

} // namespace easy_deploy
57 changes: 28 additions & 29 deletions detection_2d/detection_2d_rt_detr/src/rt_detr.cpp
Original file line number Diff line number Diff line change
@@ -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<inference_core::BaseInferCore> &infer_core,
const std::shared_ptr<IDetectionPreProcess> &preprocess_block,
const int input_height,
const int input_width,
const int input_channel,
const int cls_number,
const std::vector<std::string> &input_blobs_name,
const std::vector<std::string> &output_blobs_name);
RTDetrDetection(const std::shared_ptr<BaseInferCore> &infer_core,
const std::shared_ptr<IDetectionPreProcess> &preprocess_block,
const int input_height,
const int input_width,
const int input_channel,
const int cls_number,
const std::vector<std::string> &input_blobs_name,
const std::vector<std::string> &output_blobs_name);

~RTDetrDetection() = default;

private:
bool PreProcess(std::shared_ptr<async_pipeline::IPipelinePackage> pipeline_unit) override;
bool PreProcess(std::shared_ptr<IPipelinePackage> pipeline_unit) override;

bool PostProcess(std::shared_ptr<async_pipeline::IPipelinePackage> pipeline_unit) override;
bool PostProcess(std::shared_ptr<IPipelinePackage> pipeline_unit) override;

private:
const std::vector<std::string> input_blobs_name_;
Expand All @@ -28,11 +28,11 @@ class RTDetrDetection : public BaseDetectionModel {
const int input_channel_;
const int cls_number_;

const std::shared_ptr<inference_core::BaseInferCore> infer_core_;
std::shared_ptr<IDetectionPreProcess> preprocess_block_;
const std::shared_ptr<BaseInferCore> infer_core_;
std::shared_ptr<IDetectionPreProcess> preprocess_block_;
};

RTDetrDetection::RTDetrDetection(const std::shared_ptr<inference_core::BaseInferCore> &infer_core,
RTDetrDetection::RTDetrDetection(const std::shared_ptr<BaseInferCore> &infer_core,
const std::shared_ptr<IDetectionPreProcess> &preprocess_block,
const int input_height,
const int input_width,
Expand All @@ -54,9 +54,8 @@ RTDetrDetection::RTDetrDetection(const std::shared_ptr<inference_core::BaseInfer
auto blobs_tensor = infer_core_->AllocBlobsBuffer();
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!!!");
}
Expand All @@ -72,7 +71,7 @@ RTDetrDetection::RTDetrDetection(const std::shared_ptr<inference_core::BaseInfer
}
}

bool RTDetrDetection::PreProcess(std::shared_ptr<async_pipeline::IPipelinePackage> _package)
bool RTDetrDetection::PreProcess(std::shared_ptr<IPipelinePackage> _package)
{
auto package = std::dynamic_pointer_cast<DetectionPipelinePackage>(_package);
CHECK_STATE(package != nullptr,
Expand All @@ -89,7 +88,7 @@ bool RTDetrDetection::PreProcess(std::shared_ptr<async_pipeline::IPipelinePackag
return true;
}

bool RTDetrDetection::PostProcess(std::shared_ptr<async_pipeline::IPipelinePackage> _package)
bool RTDetrDetection::PostProcess(std::shared_ptr<IPipelinePackage> _package)
{
auto package = std::dynamic_pointer_cast<DetectionPipelinePackage>(_package);
CHECK_STATE(package != nullptr,
Expand Down Expand Up @@ -135,18 +134,18 @@ bool RTDetrDetection::PostProcess(std::shared_ptr<async_pipeline::IPipelinePacka
}

std::shared_ptr<BaseDetectionModel> CreateRTDetrDetectionModel(
const std::shared_ptr<inference_core::BaseInferCore> &infer_core,
const std::shared_ptr<IDetectionPreProcess> &preprocess_block,
const int input_height,
const int input_width,
const int input_channel,
const int cls_number,
const std::vector<std::string> &input_blobs_name,
const std::vector<std::string> &output_blobs_name)
const std::shared_ptr<BaseInferCore> &infer_core,
const std::shared_ptr<IDetectionPreProcess> &preprocess_block,
const int input_height,
const int input_width,
const int input_channel,
const int cls_number,
const std::vector<std::string> &input_blobs_name,
const std::vector<std::string> &output_blobs_name)
{
return std::make_shared<RTDetrDetection>(infer_core, preprocess_block, input_height, input_width,
input_channel, cls_number, input_blobs_name,
output_blobs_name);
}

} // namespace detection_2d
} // namespace easy_deploy
63 changes: 28 additions & 35 deletions detection_2d/detection_2d_rt_detr/src/rt_detr_factory.cpp
Original file line number Diff line number Diff line change
@@ -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<inference_core::BaseInferCoreFactory> infer_core_factory;
std::shared_ptr<detection_2d::BaseDetectionPreprocessFactory> preprocess_factory;
int input_height;
int input_width;
int input_channel;
int cls_number;
std::vector<std::string> input_blob_name;
std::vector<std::string> output_blob_name;
std::shared_ptr<BaseInferCoreFactory> infer_core_factory;
std::shared_ptr<BaseDetectionPreprocessFactory> preprocess_factory;
int input_height;
int input_width;
int input_channel;
int cls_number;
std::vector<std::string> input_blob_name;
std::vector<std::string> output_blob_name;
};

class Detection2DRTDetrFactory : public BaseDetection2DFactory {
public:
Detection2DRTDetrFactory(const RTDetrParams &params) : params_(params)
{}
std::shared_ptr<detection_2d::BaseDetectionModel> Create() override
std::shared_ptr<BaseDetectionModel> Create() override
{
return CreateRTDetrDetectionModel(
params_.infer_core_factory->Create(), params_.preprocess_factory->Create(),
Expand All @@ -37,31 +30,31 @@ class Detection2DRTDetrFactory : public BaseDetection2DFactory {
};

std::shared_ptr<BaseDetection2DFactory> CreateRTDetrDetectionModelFactory(
std::shared_ptr<inference_core::BaseInferCoreFactory> infer_core_factory,
std::shared_ptr<detection_2d::BaseDetectionPreprocessFactory> preprocess_factory,
int input_height,
int input_width,
int input_channel,
int cls_number,
const std::vector<std::string> &input_blob_name,
const std::vector<std::string> &output_blob_name)
std::shared_ptr<BaseInferCoreFactory> infer_core_factory,
std::shared_ptr<BaseDetectionPreprocessFactory> preprocess_factory,
int input_height,
int input_width,
int input_channel,
int cls_number,
const std::vector<std::string> &input_blob_name,
const std::vector<std::string> &output_blob_name)
{
if (infer_core_factory == nullptr || preprocess_factory == nullptr)
{
throw std::invalid_argument("[CreateRTDetrDetectionModelFactory] Got invalid input arguments!");
}

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<Detection2DRTDetrFactory>(params);
}

} // namespace detection_2d
} // namespace easy_deploy
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include <gtest/gtest.h>

#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) \
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions detection_2d/detection_2d_yolov8/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
Loading