From c25d1cc1bce44ef56fc7c86ae9bd7f3f931b9b65 Mon Sep 17 00:00:00 2001 From: WJJ1995 Date: Tue, 14 Feb 2023 17:51:39 +0800 Subject: [PATCH 1/2] [Backend]Fixed enable_paddle_to_trt() bug (#1320) * add GPL lisence * add GPL-3.0 lisence * add GPL-3.0 lisence * add GPL-3.0 lisence * support yolov8 * add pybind for yolov8 * add yolov8 readme * add cpp benchmark * add cpu and gpu mem * public part split * add runtime mode * fixed bugs * add cpu_thread_nums * deal with comments * deal with comments * deal with comments * rm useless code * add FASTDEPLOY_DECL * add FASTDEPLOY_DECL * fixed for windows * mv rss to pss * mv rss to pss * Update utils.cc * use thread to collect mem * Add ResourceUsageMonitor * rm useless code * fixed bug * fixed typo * update ResourceUsageMonitor * fixed bug * fixed bug * add note for ResourceUsageMonitor * deal with comments * add macros * deal with comments * deal with comments * deal with comments * re-lint * rm pmap and use mem api * rm pmap and use mem api * add mem api * Add PrintBenchmarkInfo func * Add PrintBenchmarkInfo func * Add PrintBenchmarkInfo func * deal with comments * fixed enable_paddle_to_trt * add log for paddle_trt --------- Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> --- fastdeploy/runtime/backends/paddle/paddle_backend.cc | 4 ++++ python/fastdeploy/runtime.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) mode change 100644 => 100755 fastdeploy/runtime/backends/paddle/paddle_backend.cc mode change 100644 => 100755 python/fastdeploy/runtime.py diff --git a/fastdeploy/runtime/backends/paddle/paddle_backend.cc b/fastdeploy/runtime/backends/paddle/paddle_backend.cc old mode 100644 new mode 100755 index 09dbe812a..dc804e926 --- a/fastdeploy/runtime/backends/paddle/paddle_backend.cc +++ b/fastdeploy/runtime/backends/paddle/paddle_backend.cc @@ -29,6 +29,10 @@ void PaddleBackend::BuildOption(const PaddleBackendOption& option) { config_.SetExecStream(option_.external_stream_); } if (option.enable_trt) { + if (!option.trt_option.enable_fp16) { + FDINFO << "Will try to use tensorrt inference with Paddle Backend." + << std::endl; + } config_.Exp_DisableTensorRtOPs(option.trt_disabled_ops_); auto precision = paddle_infer::PrecisionType::kFloat32; if (option.trt_option.enable_fp16) { diff --git a/python/fastdeploy/runtime.py b/python/fastdeploy/runtime.py old mode 100644 new mode 100755 index 6be764ea3..4980db52e --- a/python/fastdeploy/runtime.py +++ b/python/fastdeploy/runtime.py @@ -532,9 +532,10 @@ class RuntimeOption: logging.warning(" option = fd.RuntimeOption()") logging.warning(" option.use_gpu(0)") logging.warning(" option.use_paddle_infer_backend()") - logging.warning(" option.paddle_infer_option.enabel_trt = True") + logging.warning(" option.paddle_infer_option.enable_trt = True") logging.warning(" ==============================================") - return self._option.enable_paddle_to_trt() + self._option.use_paddle_backend() + self._option.paddle_infer_option.enable_trt = True def set_trt_max_workspace_size(self, trt_max_workspace_size): """Set max workspace size while using TensorRT backend. From a5d23c57d0cb6bd52fd2bc3daa4a9d3c2274c403 Mon Sep 17 00:00:00 2001 From: CoolCola <49013063+CoolKbh@users.noreply.github.com> Date: Tue, 14 Feb 2023 18:36:28 +0800 Subject: [PATCH 2/2] [Bug fix]add yolov7face landmarks (#1297) * add yolov7face benchmark * fix review problem * fix review problems --- .../contrib/yolov7face/postprocessor.cc | 27 ++++++++++++++++--- .../contrib/yolov7face/postprocessor.h | 12 +++++++-- .../contrib/yolov7face/yolov7face_pybind.cc | 3 ++- .../vision/facedet/contrib/yolov7face.py | 12 +++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/fastdeploy/vision/facedet/contrib/yolov7face/postprocessor.cc b/fastdeploy/vision/facedet/contrib/yolov7face/postprocessor.cc index 30bb523cc..624aa3403 100644 --- a/fastdeploy/vision/facedet/contrib/yolov7face/postprocessor.cc +++ b/fastdeploy/vision/facedet/contrib/yolov7face/postprocessor.cc @@ -24,7 +24,7 @@ namespace facedet { Yolov7FacePostprocessor::Yolov7FacePostprocessor() { conf_threshold_ = 0.5; nms_threshold_ = 0.45; - max_wh_ = 7680.0; + landmarks_per_face_ = 5; } bool Yolov7FacePostprocessor::Run(const std::vector& infer_result, @@ -36,6 +36,8 @@ bool Yolov7FacePostprocessor::Run(const std::vector& infer_result, for (size_t bs = 0; bs < batch; ++bs) { (*results)[bs].Clear(); + // must be setup landmarks_per_face before reserve + (*results)[bs].landmarks_per_face = landmarks_per_face_; (*results)[bs].Reserve(infer_result[0].shape[1]); if (infer_result[0].dtype != FDDataType::FP32) { FDERROR << "Only support post process with float32 data." << std::endl; @@ -61,6 +63,15 @@ bool Yolov7FacePostprocessor::Run(const std::vector& infer_result, (*results)[bs].boxes.emplace_back(std::array{ (x - w / 2.f), (y - h / 2.f), (x + w / 2.f), (y + h / 2.f)}); (*results)[bs].scores.push_back(confidence); + + // decode landmarks (default 5 landmarks) + if (landmarks_per_face_ > 0) { + float* landmarks_ptr = const_cast(reg_cls_ptr + 6); + for (size_t j = 0; j < landmarks_per_face_ * 3; j += 3) { + (*results)[bs].landmarks.emplace_back( + std::array{landmarks_ptr[j], landmarks_ptr[j + 1]}); + } + } } if ((*results)[bs].boxes.size() == 0) { @@ -79,9 +90,9 @@ bool Yolov7FacePostprocessor::Run(const std::vector& infer_result, float ipt_h = iter_ipt->second[0]; float ipt_w = iter_ipt->second[1]; float scale = std::min(out_h / ipt_h, out_w / ipt_w); + float pad_h = (out_h - ipt_h * scale) / 2; + float pad_w = (out_w - ipt_w * scale) / 2; for (size_t i = 0; i < (*results)[bs].boxes.size(); ++i) { - float pad_h = (out_h - ipt_h * scale) / 2; - float pad_w = (out_w - ipt_w * scale) / 2; // clip box (*results)[bs].boxes[i][0] = std::max(((*results)[bs].boxes[i][0] - pad_w) / scale, 0.0f); (*results)[bs].boxes[i][1] = std::max(((*results)[bs].boxes[i][1] - pad_h) / scale, 0.0f); @@ -92,6 +103,16 @@ bool Yolov7FacePostprocessor::Run(const std::vector& infer_result, (*results)[bs].boxes[i][2] = std::min((*results)[bs].boxes[i][2], ipt_w - 1.0f); (*results)[bs].boxes[i][3] = std::min((*results)[bs].boxes[i][3], ipt_h - 1.0f); } + + // scale and clip landmarks + for (size_t i = 0; i < (*results)[bs].landmarks.size(); ++i) { + (*results)[bs].landmarks[i][0] = + std::max(((*results)[bs].landmarks[i][0] - pad_w) / scale, 0.0f); + (*results)[bs].landmarks[i][1] = + std::max(((*results)[bs].landmarks[i][1] - pad_h) / scale, 0.0f); + (*results)[bs].landmarks[i][0] = std::min((*results)[bs].landmarks[i][0], ipt_w - 1.0f); + (*results)[bs].landmarks[i][1] = std::min((*results)[bs].landmarks[i][1], ipt_h - 1.0f); + } } return true; } diff --git a/fastdeploy/vision/facedet/contrib/yolov7face/postprocessor.h b/fastdeploy/vision/facedet/contrib/yolov7face/postprocessor.h index 4a1b0d852..f6a6bb23c 100644 --- a/fastdeploy/vision/facedet/contrib/yolov7face/postprocessor.h +++ b/fastdeploy/vision/facedet/contrib/yolov7face/postprocessor.h @@ -56,11 +56,19 @@ class FASTDEPLOY_DECL Yolov7FacePostprocessor{ /// Get nms_threshold, default 0.45 float GetNMSThreshold() const { return nms_threshold_; } + /// Set landmarks_per_face, default 5 + void SetLandmarksPerFace(const int& landmarks_per_face) { + landmarks_per_face_ = landmarks_per_face; + } + + /// Get landmarks_per_face, default 5 + int GetLandmarksPerFace() const { return landmarks_per_face_; } + + protected: float conf_threshold_; float nms_threshold_; - bool multi_label_; - float max_wh_; + int landmarks_per_face_; }; } // namespace facedet diff --git a/fastdeploy/vision/facedet/contrib/yolov7face/yolov7face_pybind.cc b/fastdeploy/vision/facedet/contrib/yolov7face/yolov7face_pybind.cc index c0c99d425..07f5feece 100644 --- a/fastdeploy/vision/facedet/contrib/yolov7face/yolov7face_pybind.cc +++ b/fastdeploy/vision/facedet/contrib/yolov7face/yolov7face_pybind.cc @@ -60,7 +60,8 @@ void BindYOLOv7Face(pybind11::module& m) { return results; }) .def_property("conf_threshold", &vision::facedet::Yolov7FacePostprocessor::GetConfThreshold, &vision::facedet::Yolov7FacePostprocessor::SetConfThreshold) - .def_property("nms_threshold", &vision::facedet::Yolov7FacePostprocessor::GetNMSThreshold, &vision::facedet::Yolov7FacePostprocessor::SetNMSThreshold); + .def_property("nms_threshold", &vision::facedet::Yolov7FacePostprocessor::GetNMSThreshold, &vision::facedet::Yolov7FacePostprocessor::SetNMSThreshold) + .def_property("landmarks_per_face", &vision::facedet::Yolov7FacePostprocessor::GetLandmarksPerFace, &vision::facedet::Yolov7FacePostprocessor::SetLandmarksPerFace); pybind11::class_(m, "YOLOv7Face") .def(pybind11::init