Skip to content

Commit b79fba3

Browse files
fix: nms perf (#3351)
Co-authored-by: hhstuhacker <hhstuhacker@gmail.com>
1 parent 8719988 commit b79fba3

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tfjs-core/src/backends/non_max_suppression_impl.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ function nonMaxSuppressionImpl_(
7171
returnScoresTensor = false, padToMaxOutputSize = false): NamedTensorMap {
7272
// The list is sorted in ascending order, so that we can always pop the
7373
// candidate with the largest score in O(1) time.
74-
const candidates =
75-
Array.from(scores)
76-
.map((score, boxIndex) => ({score, boxIndex, suppressBeginIndex: 0}))
77-
.filter(c => c.score > scoreThreshold)
78-
.sort(ascendingComparator);
74+
const candidates = [];
75+
76+
for (let i = 0; i < scores.length; i++) {
77+
if (scores[i] > scoreThreshold) {
78+
candidates.push({ score: scores[i], boxIndex: i, suppressBeginIndex: 0 });
79+
}
80+
}
81+
82+
candidates.sort(ascendingComparator);
7983

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

0 commit comments

Comments
 (0)