mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-27 18:41:02 +08:00
Add YOLOv5Face model support (#38)
* update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * Add YOLOv5Face Model support * fixed examples/vision typos * fixed runtime_option print func bugs
This commit is contained in:
@@ -66,6 +66,62 @@ void NMS(DetectionResult* result, float iou_threshold) {
|
||||
}
|
||||
}
|
||||
|
||||
void NMS(FaceDetectionResult* result, float iou_threshold) {
|
||||
utils::SortDetectionResult(result);
|
||||
|
||||
std::vector<float> area_of_boxes(result->boxes.size());
|
||||
std::vector<int> suppressed(result->boxes.size(), 0);
|
||||
for (size_t i = 0; i < result->boxes.size(); ++i) {
|
||||
area_of_boxes[i] = (result->boxes[i][2] - result->boxes[i][0]) *
|
||||
(result->boxes[i][3] - result->boxes[i][1]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < result->boxes.size(); ++i) {
|
||||
if (suppressed[i] == 1) {
|
||||
continue;
|
||||
}
|
||||
for (size_t j = i + 1; j < result->boxes.size(); ++j) {
|
||||
if (suppressed[j] == 1) {
|
||||
continue;
|
||||
}
|
||||
float xmin = std::max(result->boxes[i][0], result->boxes[j][0]);
|
||||
float ymin = std::max(result->boxes[i][1], result->boxes[j][1]);
|
||||
float xmax = std::min(result->boxes[i][2], result->boxes[j][2]);
|
||||
float ymax = std::min(result->boxes[i][3], result->boxes[j][3]);
|
||||
float overlap_w = std::max(0.0f, xmax - xmin);
|
||||
float overlap_h = std::max(0.0f, ymax - ymin);
|
||||
float overlap_area = overlap_w * overlap_h;
|
||||
float overlap_ratio =
|
||||
overlap_area / (area_of_boxes[i] + area_of_boxes[j] - overlap_area);
|
||||
if (overlap_ratio > iou_threshold) {
|
||||
suppressed[j] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
FaceDetectionResult backup(*result);
|
||||
int landmarks_per_face = result->landmarks_per_face;
|
||||
|
||||
result->Clear();
|
||||
// don't forget to reset the landmarks_per_face
|
||||
// before apply Reserve method.
|
||||
result->landmarks_per_face = landmarks_per_face;
|
||||
result->Reserve(suppressed.size());
|
||||
for (size_t i = 0; i < suppressed.size(); ++i) {
|
||||
if (suppressed[i] == 1) {
|
||||
continue;
|
||||
}
|
||||
result->boxes.emplace_back(backup.boxes[i]);
|
||||
result->scores.push_back(backup.scores[i]);
|
||||
// landmarks (if have)
|
||||
if (result->landmarks_per_face > 0) {
|
||||
for (size_t j = 0; j < result->landmarks_per_face; ++j) {
|
||||
result->landmarks.emplace_back(
|
||||
backup.landmarks[i * result->landmarks_per_face + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
|
||||
Reference in New Issue
Block a user