improve pose
This commit is contained in:
@@ -6,6 +6,43 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// ── IoU dedup for end-to-end YOLO person detector output ──────────────
|
||||||
|
//
|
||||||
|
// Ultralytics E2E ONNX exports bake NMS into the graph, but its IoU
|
||||||
|
// threshold is set at export time (default ≈ 0.7) and we can't override
|
||||||
|
// it from outside. For a top-down pose pipeline that's too lax — pairs
|
||||||
|
// of overlapping bboxes survive and we end up running RTMPose twice on
|
||||||
|
// the same person.
|
||||||
|
//
|
||||||
|
// This filter walks the detector's output (already sorted by confidence
|
||||||
|
// in the E2E format), keeping each box only if its IoU with every
|
||||||
|
// already-kept box is below kPersonDedupIoU. O(N²) is fine because N is
|
||||||
|
// capped at 300 and typically <10 in practice.
|
||||||
|
constexpr float kPersonDedupIoU = 0.45f;
|
||||||
|
|
||||||
|
inline float boxIoU(const cv::Rect& a, const cv::Rect& b) {
|
||||||
|
const cv::Rect inter = a & b;
|
||||||
|
if (inter.area() <= 0) return 0.f;
|
||||||
|
const int uni = a.area() + b.area() - inter.area();
|
||||||
|
return uni > 0 ? static_cast<float>(inter.area()) / static_cast<float>(uni) : 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ANSCENTER::Object> dedupByIoU(
|
||||||
|
const std::vector<ANSCENTER::Object>& persons, float iouThr) {
|
||||||
|
std::vector<ANSCENTER::Object> kept;
|
||||||
|
kept.reserve(persons.size());
|
||||||
|
for (const auto& p : persons) {
|
||||||
|
bool isDup = false;
|
||||||
|
for (const auto& k : kept) {
|
||||||
|
if (boxIoU(p.box, k.box) > iouThr) { isDup = true; break; }
|
||||||
|
}
|
||||||
|
if (!isDup) kept.push_back(p);
|
||||||
|
}
|
||||||
|
return kept;
|
||||||
|
}
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
namespace ANSCENTER {
|
namespace ANSCENTER {
|
||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
@@ -690,6 +727,17 @@ namespace ANSCENTER {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IoU dedup — Ultralytics E2E NMS in person.onnx is too lax
|
||||||
|
// (training-time IoU≈0.7 default), letting near-duplicate
|
||||||
|
// boxes through. Drop duplicates BEFORE running pose so we
|
||||||
|
// don't pay for two RTMPose inferences on the same subject.
|
||||||
|
const size_t beforeDedup = persons.size();
|
||||||
|
persons = dedupByIoU(persons, kPersonDedupIoU);
|
||||||
|
if (persons.size() != beforeDedup) {
|
||||||
|
ANS_DBG("ANSONNXRTMPOSE", "DetectObjects: dedup %zu -> %zu (IoU>%g) cam='%s'",
|
||||||
|
beforeDedup, persons.size(), kPersonDedupIoU, camera_id.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Object> out;
|
std::vector<Object> out;
|
||||||
out.reserve(persons.size());
|
out.reserve(persons.size());
|
||||||
for (const auto& person : persons) {
|
for (const auto& person : persons) {
|
||||||
|
|||||||
@@ -6,6 +6,43 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// ── IoU dedup for end-to-end YOLO person detector output ──────────────
|
||||||
|
//
|
||||||
|
// Ultralytics E2E ONNX exports bake NMS into the graph, but its IoU
|
||||||
|
// threshold is set at export time (default ≈ 0.7) and we can't override
|
||||||
|
// it from outside. For a top-down pose pipeline that's too lax — pairs
|
||||||
|
// of overlapping bboxes survive and we end up running RTMPose twice on
|
||||||
|
// the same person.
|
||||||
|
//
|
||||||
|
// This filter walks the detector's output (already sorted by confidence
|
||||||
|
// in the E2E format), keeping each box only if its IoU with every
|
||||||
|
// already-kept box is below kPersonDedupIoU. O(N²) is fine because N is
|
||||||
|
// capped at 300 and typically <10 in practice.
|
||||||
|
constexpr float kPersonDedupIoU = 0.45f;
|
||||||
|
|
||||||
|
inline float boxIoU(const cv::Rect& a, const cv::Rect& b) {
|
||||||
|
const cv::Rect inter = a & b;
|
||||||
|
if (inter.area() <= 0) return 0.f;
|
||||||
|
const int uni = a.area() + b.area() - inter.area();
|
||||||
|
return uni > 0 ? static_cast<float>(inter.area()) / static_cast<float>(uni) : 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ANSCENTER::Object> dedupByIoU(
|
||||||
|
const std::vector<ANSCENTER::Object>& persons, float iouThr) {
|
||||||
|
std::vector<ANSCENTER::Object> kept;
|
||||||
|
kept.reserve(persons.size());
|
||||||
|
for (const auto& p : persons) {
|
||||||
|
bool isDup = false;
|
||||||
|
for (const auto& k : kept) {
|
||||||
|
if (boxIoU(p.box, k.box) > iouThr) { isDup = true; break; }
|
||||||
|
}
|
||||||
|
if (!isDup) kept.push_back(p);
|
||||||
|
}
|
||||||
|
return kept;
|
||||||
|
}
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
namespace ANSCENTER {
|
namespace ANSCENTER {
|
||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
@@ -411,6 +448,17 @@ namespace ANSCENTER {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IoU dedup — Ultralytics E2E NMS in person.onnx is too lax
|
||||||
|
// (training-time IoU≈0.7 default), letting near-duplicate
|
||||||
|
// boxes through. Drop duplicates BEFORE running pose so we
|
||||||
|
// don't pay for two RTMPose inferences on the same subject.
|
||||||
|
const size_t beforeDedup = persons.size();
|
||||||
|
persons = dedupByIoU(persons, kPersonDedupIoU);
|
||||||
|
if (persons.size() != beforeDedup) {
|
||||||
|
ANS_DBG("ANSRTRTMPOSE", "RunInference: dedup %zu -> %zu (IoU>%g) cam='%s'",
|
||||||
|
beforeDedup, persons.size(), kPersonDedupIoU, camera_id.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Object> results;
|
std::vector<Object> results;
|
||||||
results.reserve(persons.size());
|
results.reserve(persons.size());
|
||||||
for (const auto& person : persons) {
|
for (const auto& person : persons) {
|
||||||
|
|||||||
@@ -1997,9 +1997,9 @@ int FallDetectorTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int RTMPOSETest() {
|
int RTMPOSETest() {
|
||||||
int modelType = 33; // ONNX YOLO (30) RT YOLO (31)
|
int modelType = 32; // ONNX YOLO (30) RT YOLO (31)
|
||||||
std::string onnxclmodelFilePath = "E:\\Programs\\DemoAssets\\ANSAIModels\\PoseEstimationModels\\ANSRTMPOSE.zip";
|
std::string onnxclmodelFilePath = "E:\\Programs\\DemoAssets\\ANSAIModels\\PoseEstimationModels\\ANSRTMPOSE.zip";
|
||||||
std::string videoFile = "E:\\Programs\\DemoAssets\\Videos\\train.mp4";
|
std::string videoFile = "E:\\Programs\\DemoAssets\\Videos\\rtmpose.mp4";//"E:\\Programs\\DemoAssets\\Videos\\train.mp4";
|
||||||
VideoDetectorEngine(onnxclmodelFilePath, videoFile, modelType);// 22 is RT, 21 is onnx
|
VideoDetectorEngine(onnxclmodelFilePath, videoFile, modelType);// 22 is RT, 21 is onnx
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user