From 02d29aa0c33835d900c0e706cc78906222f75d38 Mon Sep 17 00:00:00 2001 From: DefTruth Date: Tue, 12 Jul 2022 02:51:41 +0000 Subject: [PATCH 1/6] update .gitignore --- .gitignore | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index b2602607a9..b268868c02 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,12 @@ fastdeploy/libs/lib* +build +cmake-build-debug +cmake-build-release +.vscode +FastDeploy.cmake +fastdeploy/core/config.h +build-debug.sh +*dist +fastdeploy.egg-info +.setuptools-cmake-build +fastdeploy/version.py \ No newline at end of file From afa81147a6df3a7072912231cdd9cbd1c02282e4 Mon Sep 17 00:00:00 2001 From: DefTruth Date: Tue, 12 Jul 2022 06:41:55 +0000 Subject: [PATCH 2/6] Added checking for cmake include dir --- CMakeLists.txt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bbc8139b9..2ff2b85f01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,13 +172,15 @@ install( TARGETS fastdeploy LIBRARY DESTINATION lib ) -install( - DIRECTORY ${PROJECT_SOURCE_DIR}/fastdeploy - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING - PATTERN "*.h" - PATTERN "${PROJECT_SOURCE_DIR}/fastdeploy/backends/*/*.h" -) +if (DEFINED CMAKE_INSTALL_INCLUDEDIR) + install( + DIRECTORY ${PROJECT_SOURCE_DIR}/fastdeploy + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "${PROJECT_SOURCE_DIR}/fastdeploy/backends/*/*.h" + ) +endif() install( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install DESTINATION ${CMAKE_INSTALL_PREFIX}/third_libs From 659c14c5b90028fba4440af02ef942796f03a5a3 Mon Sep 17 00:00:00 2001 From: DefTruth Date: Tue, 12 Jul 2022 06:44:21 +0000 Subject: [PATCH 3/6] fixed missing trt_backend option bug when init from trt --- fastdeploy/backends/tensorrt/trt_backend.cc | 3 ++- fastdeploy/backends/tensorrt/trt_backend.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fastdeploy/backends/tensorrt/trt_backend.cc b/fastdeploy/backends/tensorrt/trt_backend.cc index dfc2840c2b..5dbb61ffe8 100644 --- a/fastdeploy/backends/tensorrt/trt_backend.cc +++ b/fastdeploy/backends/tensorrt/trt_backend.cc @@ -52,7 +52,8 @@ std::vector toVec(const nvinfer1::Dims& dim) { return out; } -bool TrtBackend::InitFromTrt(const std::string& trt_engine_file) { +bool TrtBackend::InitFromTrt(const std::string& trt_engine_file, + const TrtBackendOption& option) { if (initialized_) { FDERROR << "TrtBackend is already initlized, cannot initialize again." << std::endl; diff --git a/fastdeploy/backends/tensorrt/trt_backend.h b/fastdeploy/backends/tensorrt/trt_backend.h index 3b77c8bc24..e3f848a012 100644 --- a/fastdeploy/backends/tensorrt/trt_backend.h +++ b/fastdeploy/backends/tensorrt/trt_backend.h @@ -69,7 +69,8 @@ class TrtBackend : public BaseBackend { bool InitFromOnnx(const std::string& model_file, const TrtBackendOption& option = TrtBackendOption(), bool from_memory_buffer = false); - bool InitFromTrt(const std::string& trt_engine_file); + bool InitFromTrt(const std::string& trt_engine_file, + const TrtBackendOption& option = TrtBackendOption()); bool Infer(std::vector& inputs, std::vector* outputs); From 17a43cebd0507ee02ee3234958ce49cc52ad8c16 Mon Sep 17 00:00:00 2001 From: DefTruth Date: Tue, 12 Jul 2022 06:46:38 +0000 Subject: [PATCH 4/6] remove un-need data layout and add pre-check for dtype --- fastdeploy/vision/common/processors/cast.cc | 34 +++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/fastdeploy/vision/common/processors/cast.cc b/fastdeploy/vision/common/processors/cast.cc index 2f8a0993ec..77a1b249ae 100644 --- a/fastdeploy/vision/common/processors/cast.cc +++ b/fastdeploy/vision/common/processors/cast.cc @@ -18,30 +18,40 @@ namespace fastdeploy { namespace vision { bool Cast::CpuRun(Mat* mat) { - if (mat->layout != Layout::CHW) { - FDERROR << "Cast: The input data must be Layout::HWC format!" << std::endl; - return false; - } cv::Mat* im = mat->GetCpuMat(); + int c = im->channels(); if (dtype_ == "float") { - im->convertTo(*im, CV_32FC(im->channels())); + if (im->type() != CV_32FC(c)) { + im->convertTo(*im, CV_32FC(c)); + } } else if (dtype_ == "double") { - im->convertTo(*im, CV_64FC(im->channels())); + if (im->type() != CV_64FC(c)) { + im->convertTo(*im, CV_64FC(c)); + } + } else { + FDLogger() << "[WARN] Cast not support for " << dtype_ + << " now! will skip this operation." + << std::endl; } return true; } #ifdef ENABLE_OPENCV_CUDA bool Cast::GpuRun(Mat* mat) { - if (mat->layout != Layout::CHW) { - FDERROR << "Cast: The input data must be Layout::HWC format!" << std::endl; - return false; - } cv::cuda::GpuMat* im = mat->GetGpuMat(); + int c = im->channels(); if (dtype_ == "float") { - im->convertTo(*im, CV_32FC(im->channels())); + if (im->type() != CV_32FC(c)) { + im->convertTo(*im, CV_32FC(c)); + } } else if (dtype_ == "double") { - im->convertTo(*im, CV_64FC(im->channels())); + if (im->type() != CV_64FC(c)) { + im->convertTo(*im, CV_64FC(c)); + } + } else { + FDLogger() << "[WARN] Cast not support for " << dtype_ + << " now! will skip this operation." + << std::endl; } return true; } From 75948f831317bacfb77bc70a8be7289f55f093eb Mon Sep 17 00:00:00 2001 From: DefTruth Date: Tue, 12 Jul 2022 06:48:36 +0000 Subject: [PATCH 5/6] changed RGB2BRG to BGR2RGB in ppcls model --- fastdeploy/vision/ppcls/model.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastdeploy/vision/ppcls/model.cc b/fastdeploy/vision/ppcls/model.cc index ad894f3daf..915cb97512 100644 --- a/fastdeploy/vision/ppcls/model.cc +++ b/fastdeploy/vision/ppcls/model.cc @@ -44,7 +44,7 @@ bool Model::BuildPreprocessPipelineFromConfig() { return false; } auto preprocess_cfg = cfg["PreProcess"]["transform_ops"]; - processors_.push_back(std::make_shared()); + processors_.push_back(std::make_shared()); for (const auto& op : preprocess_cfg) { FDASSERT(op.IsMap(), "Require the transform information in yaml be Map type."); From 2c1d022e2d1f20a5f04f833996cc77a179a9aab4 Mon Sep 17 00:00:00 2001 From: DefTruth <31974251+DefTruth@users.noreply.github.com> Date: Tue, 12 Jul 2022 15:01:15 +0800 Subject: [PATCH 6/6] Update CMakeLists.txt --- CMakeLists.txt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ff2b85f01..3b3a508f55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,15 +172,13 @@ install( TARGETS fastdeploy LIBRARY DESTINATION lib ) -if (DEFINED CMAKE_INSTALL_INCLUDEDIR) - install( - DIRECTORY ${PROJECT_SOURCE_DIR}/fastdeploy - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - FILES_MATCHING - PATTERN "*.h" - PATTERN "${PROJECT_SOURCE_DIR}/fastdeploy/backends/*/*.h" - ) -endif() +install( + DIRECTORY ${PROJECT_SOURCE_DIR}/fastdeploy + DESTINATION ${CMAKE_INSTALL_PREFIX}/include + FILES_MATCHING + PATTERN "*.h" + PATTERN "${PROJECT_SOURCE_DIR}/fastdeploy/backends/*/*.h" +) install( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install DESTINATION ${CMAKE_INSTALL_PREFIX}/third_libs