Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions tfjs-core/src/backends/non_max_suppression_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ function nonMaxSuppressionImpl_(
returnScoresTensor = false, padToMaxOutputSize = false): NamedTensorMap {
// The list is sorted in ascending order, so that we can always pop the
// candidate with the largest score in O(1) time.
const candidates =
Array.from(scores)
.map((score, boxIndex) => ({score, boxIndex, suppressBeginIndex: 0}))
.filter(c => c.score > scoreThreshold)
.sort(ascendingComparator);
const candidates = [];

for (let i = 0; i < scores.length; i++) {
if (scores[i] > scoreThreshold) {
candidates.push({ score: scores[i], boxIndex: i, suppressBeginIndex: 0 });
}
}

candidates.sort(ascendingComparator);

// If softNmsSigma is 0, the outcome of this algorithm is exactly same as
// before.
Expand Down