32 std::vector<std::pair<float, int>> *score_index_vec) {
33 ACHECK(score_index_vec !=
nullptr);
35 for (
size_t i = 0; i < scores.size(); ++i) {
36 if (scores[i] > threshold) {
37 score_index_vec->emplace_back(scores[i], i);
41 std::sort(score_index_vec->begin(), score_index_vec->end(),
42 [](
const std::pair<float, int> &a,
const std::pair<float, int> &b) {
43 return a.first > b.first;
46 if (top_k > 0 && top_k <
static_cast<int>(score_index_vec->size())) {
47 score_index_vec->resize(top_k);
52void Nms(
const std::vector<BoxType> &bboxes,
const std::vector<float> &scores,
53 const float score_threshold,
const float nms_threshold,
54 const float eta,
const int top_k, std::vector<int> *indices,
55 float (*ComputeOverlap)(
const BoxType &,
const BoxType &),
56 int limit = std::numeric_limits<int>::max) {
57 ACHECK(bboxes.size() == scores.size());
58 ACHECK(indices !=
nullptr);
60 std::vector<std::pair<float, int>> score_index_vec;
63 float adaptive_threshold = nms_threshold;
65 for (
const std::pair<float, int> &score_index : score_index_vec) {
66 const int idx = score_index.second;
68 for (
const int &kept_idx : *indices) {
69 float overlap = ComputeOverlap(bboxes[idx], bboxes[kept_idx]);
70 if (overlap > adaptive_threshold) {
77 indices->push_back(idx);
78 if (
static_cast<int>(indices->size()) >= limit) {
83 if (keep && eta < 1 && adaptive_threshold > 0.5) {
84 adaptive_threshold *= eta;
void Nms(const std::vector< BoxType > &bboxes, const std::vector< float > &scores, const float score_threshold, const float nms_threshold, const float eta, const int top_k, std::vector< int > *indices, float(*ComputeOverlap)(const BoxType &, const BoxType &), int limit=std::numeric_limits< int >::max)