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/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