Skip to content

Commit f6bc4fd

Browse files
author
WeiChungChang
authored
Merge pull request opencv#19552 from WeiChungChang:partialSort
apply partial sort to save computations * apply partial sort * fix typo * fix accroding to CR
1 parent 98c2ccf commit f6bc4fd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

modules/dnn/src/layers/detection_output_layer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,13 @@ class DetectionOutputLayerImpl CV_FINAL : public DetectionOutputLayer
611611
}
612612
}
613613
// Keep outputs k results per image.
614-
std::sort(scoreIndexPairs.begin(), scoreIndexPairs.end(),
615-
util::SortScorePairDescend<std::pair<int, int> >);
614+
if ((_keepTopK * 8) > scoreIndexPairs.size()) {
615+
std::sort(scoreIndexPairs.begin(), scoreIndexPairs.end(),
616+
util::SortScorePairDescend<std::pair<int, int> >);
617+
} else {
618+
std::partial_sort(scoreIndexPairs.begin(), scoreIndexPairs.begin() + _keepTopK, scoreIndexPairs.end(),
619+
util::SortScorePairDescend<std::pair<int, int> >);
620+
}
616621
scoreIndexPairs.resize(_keepTopK);
617622

618623
std::map<int, std::vector<int> > newIndices;

0 commit comments

Comments
 (0)