From 256f7c226987a66c4127e81775c6c9964cab2005 Mon Sep 17 00:00:00 2001 From: DefTruth <31974251+DefTruth@users.noreply.github.com> Date: Thu, 24 Nov 2022 18:56:38 +0800 Subject: [PATCH] [Bug Fix] fixed ppdet postprocess empty result error (#691) * [Android] Add CxxBuffer to native PaddleSegModel * [Android] Add PaddleSeg android app example * [Android] Add SCRFD android app example * [Doc] fix typos * [Android] revert camera setting changes * [Bug Fix] fixed ppdet postprocess empty result error --- CMakeLists.txt | 6 ++++++ fastdeploy/utils/utils.cc | 7 +++++++ fastdeploy/utils/utils.h | 9 +++++++++ fastdeploy/vision/detection/ppdet/postprocessor.cc | 12 ++++++------ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5754c7ffb..3aee32349 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -488,6 +488,12 @@ if(MSVC) # disable warnings for dll export target_compile_options(${LIBRARY_NAME} PRIVATE "$<$>:/wd4251>$<$>:-Xcompiler=/wd4251>") endif() + +if (ANDROID) + find_library(log-lib log) + list(APPEND DEPEND_LIBS ${log-lib}) +endif() + target_link_libraries(${LIBRARY_NAME} ${DEPEND_LIBS}) if(WIN32) diff --git a/fastdeploy/utils/utils.cc b/fastdeploy/utils/utils.cc index d89b1d555..3d85a619b 100644 --- a/fastdeploy/utils/utils.cc +++ b/fastdeploy/utils/utils.cc @@ -20,7 +20,11 @@ namespace fastdeploy { FDLogger::FDLogger(bool verbose, const std::string& prefix) { verbose_ = verbose; line_ = ""; +#ifdef __ANDROID__ + prefix_ = std::string("[FastDeploy]") + prefix; +#else prefix_ = prefix; +#endif } FDLogger& FDLogger::operator<<(std::ostream& (*os)(std::ostream&)) { @@ -28,6 +32,9 @@ FDLogger& FDLogger::operator<<(std::ostream& (*os)(std::ostream&)) { return *this; } std::cout << prefix_ << " " << line_ << std::endl; +#ifdef __ANDROID__ + __android_log_print(ANDROID_LOG_INFO, prefix_.c_str(), "%s", line_.c_str()); +#endif line_ = ""; return *this; } diff --git a/fastdeploy/utils/utils.h b/fastdeploy/utils/utils.h index 45b0f57cd..a8ac96e3d 100644 --- a/fastdeploy/utils/utils.h +++ b/fastdeploy/utils/utils.h @@ -24,6 +24,10 @@ #include #include +#ifdef __ANDROID__ +#include // NOLINT +#endif + #if defined(_WIN32) #ifdef FASTDEPLOY_LIB #define FASTDEPLOY_DECL __declspec(dllexport) @@ -54,10 +58,15 @@ class FASTDEPLOY_DECL FDLogger { line_ += ss.str(); return *this; } + FDLogger& operator<<(std::ostream& (*os)(std::ostream&)); + ~FDLogger() { if (!verbose_ && line_ != "") { std::cout << line_ << std::endl; +#ifdef __ANDROID__ + __android_log_print(ANDROID_LOG_INFO, prefix_.c_str(), "%s", line_.c_str()); +#endif } } diff --git a/fastdeploy/vision/detection/ppdet/postprocessor.cc b/fastdeploy/vision/detection/ppdet/postprocessor.cc index 8228a61d7..7b72e24ba 100644 --- a/fastdeploy/vision/detection/ppdet/postprocessor.cc +++ b/fastdeploy/vision/detection/ppdet/postprocessor.cc @@ -75,12 +75,6 @@ bool PaddleDetPostprocessor::Run(const std::vector& tensors, tensors[0].shape.size()); return ProcessUnDecodeResults(tensors, results); } - - if (tensors[0].shape[0] == 0) { - // No detected boxes - return true; - } - // Get number of boxes for each input image std::vector num_boxes(tensors[1].shape[0]); int total_num_boxes = 0; @@ -114,6 +108,12 @@ bool PaddleDetPostprocessor::Run(const std::vector& tensors, // Get boxes for each input image results->resize(num_boxes.size()); + + if (tensors[0].shape[0] == 0) { + // No detected boxes + return true; + } + const auto* box_data = static_cast(tensors[0].CpuData()); int offset = 0; for (size_t i = 0; i < num_boxes.size(); ++i) {