Skip to content

Commit 62139e6

Browse files
committed
Better edge case handling
1 parent 1742aac commit 62139e6

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
Version 0.3.1
5+
------------
6+
- Edge case where all box scores are zero (or all below threshold) is now handled (threw uggly error before)
7+
8+
49
Version 0.3.0
510
------------
611
- Added multiclass support for NMS

lsnms/nms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def _nms(
2222
# Discard boxes below score threshold right now to avoid building the tree on useless boxes
2323
boxes = boxes[scores > score_threshold]
2424

25+
if len(boxes) == 0:
26+
return np.zeros(0, dtype=np.int64)
27+
2528
# Build the BallTree
2629
rtree = RNode(boxes, tree_leaf_size, max_spread_axis(boxes), None)
2730
rtree.build()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "lsnms"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Large Scale Non Maximum Suppression"
55
authors = ["Rémy Dubois <remydubois14@gmail.com>"]
66
license = "MIT"

tests/test_nms.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def test_rtree_nms():
2929
assert np.allclose(k1, k2)
3030

3131

32+
def test_empty_nms():
33+
boxes, scores = datagen()
34+
# Put all the scores to zero artificially
35+
keep = nms(boxes, scores * 0.)
36+
37+
assert keep.size == 0
38+
39+
3240
def test_rtree_multiclass_nms():
3341

3442
boxes, scores = datagen()

0 commit comments

Comments
 (0)