Skip to content

Commit bd41392

Browse files
hyeygittensorflower-gardener
authored andcommitted
Change NMS threshold criteria in GPU implementation to match CPU's (which was recently updated to fix regression). Also add a test for validating iou_threshold set to 0.0.
PiperOrigin-RevId: 342012687 Change-Id: I9614724ab371ec3083a3d8506d2a4437d25cbd90
1 parent 6c7b8ae commit bd41392

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tensorflow/core/kernels/image/non_max_suppression_op.cu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ __device__ EIGEN_STRONG_INLINE bool OverThreshold(const Box* a, const Box* b,
8989
const float aa = intersection;
9090
const float bb = a_area + b_area - intersection;
9191
const float bt = bb * iou_threshold;
92-
return aa >= bt;
92+
return aa > bt;
9393
}
9494

9595
template <bool flip_box>

tensorflow/python/ops/image_ops_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,6 +4944,21 @@ def testDataTypes(self):
49444944
selected_indices = self.evaluate(selected_indices)
49454945
self.assertAllClose(selected_indices, [3, 0, 5])
49464946

4947+
def testZeroIOUThreshold(self):
4948+
boxes_np = [[0, 0, 1, 1], [0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9],
4949+
[0, 10, 1, 11], [0, 10.1, 1, 11.1], [0, 100, 1, 101]]
4950+
scores_np = [1., 1., 1., 1., 1., 1.]
4951+
max_output_size_np = 3
4952+
iou_threshold_np = 0.0
4953+
with self.cached_session():
4954+
boxes = constant_op.constant(boxes_np)
4955+
scores = constant_op.constant(scores_np)
4956+
max_output_size = constant_op.constant(max_output_size_np)
4957+
iou_threshold = constant_op.constant(iou_threshold_np)
4958+
selected_indices = image_ops.non_max_suppression(
4959+
boxes, scores, max_output_size, iou_threshold)
4960+
self.assertAllClose(selected_indices, [0, 3, 5])
4961+
49474962

49484963
class NonMaxSuppressionWithScoresTest(test_util.TensorFlowTestCase):
49494964

0 commit comments

Comments
 (0)