Merge pull request #19552 from WeiChungChang:partialSort

apply partial sort to save computations

* apply partial sort

* fix typo

* fix accroding to CR
pull/19601/head
WeiChungChang 4 years ago committed by GitHub
parent 98c2ccfaa3
commit f6bc4fd4c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      modules/dnn/src/layers/detection_output_layer.cpp

@ -611,8 +611,13 @@ public:
}
}
// Keep outputs k results per image.
std::sort(scoreIndexPairs.begin(), scoreIndexPairs.end(),
util::SortScorePairDescend<std::pair<int, int> >);
if ((_keepTopK * 8) > scoreIndexPairs.size()) {
std::sort(scoreIndexPairs.begin(), scoreIndexPairs.end(),
util::SortScorePairDescend<std::pair<int, int> >);
} else {
std::partial_sort(scoreIndexPairs.begin(), scoreIndexPairs.begin() + _keepTopK, scoreIndexPairs.end(),
util::SortScorePairDescend<std::pair<int, int> >);
}
scoreIndexPairs.resize(_keepTopK);
std::map<int, std::vector<int> > newIndices;

Loading…
Cancel
Save