aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yong Tang <yong.tang.github@outlook.com>2018-08-14 16:45:21 +0000
committerGravatar Yong Tang <yong.tang.github@outlook.com>2018-09-04 06:56:03 +0000
commit141d5d666694a37cda65c440315c135d9a6a48a7 (patch)
tree804c4ccfeb8881f4d49e37b28692cbca40a68940
parentbf64fc285e88d36bb82f80757c4a1afd722347e0 (diff)
Add test cases for float16 support for non_max_suppression
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
-rw-r--r--tensorflow/python/ops/image_ops_test.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tensorflow/python/ops/image_ops_test.py b/tensorflow/python/ops/image_ops_test.py
index f7502c4018..ee76d3d1dc 100644
--- a/tensorflow/python/ops/image_ops_test.py
+++ b/tensorflow/python/ops/image_ops_test.py
@@ -3657,6 +3657,47 @@ class NonMaxSuppressionTest(test_util.TensorFlowTestCase):
scores = constant_op.constant([0.9])
image_ops.non_max_suppression(boxes, scores, 3, [[0.5]])
+ def testDataTypes(self):
+ # Test case for GitHub issue 20199.
+ boxes_np = [[0, 0, 1, 1], [0, 0.1, 1, 1.1], [0, -0.1, 1, 0.9],
+ [0, 10, 1, 11], [0, 10.1, 1, 11.1], [0, 100, 1, 101]]
+ scores_np = [0.9, 0.75, 0.6, 0.95, 0.5, 0.3]
+ max_output_size_np = 3
+ iou_threshold_np = 0.5
+ # Note: There are multiple versions of non_max_suppression v2, v3, v4.
+ # gen_image_ops.non_max_suppression_v2:
+ for dtype in [np.float16, np.float32]:
+ with self.test_session():
+ boxes = constant_op.constant(boxes_np, dtype=dtype)
+ scores = constant_op.constant(scores_np, dtype=dtype)
+ max_output_size = constant_op.constant(max_output_size_np)
+ iou_threshold = constant_op.constant(iou_threshold_np)
+ selected_indices = gen_image_ops.non_max_suppression_v2(
+ boxes, scores, max_output_size, iou_threshold).eval()
+ self.assertAllClose(selected_indices, [3, 0, 5])
+ # image_ops.non_max_suppression = gen_image_ops.non_max_suppression_v3.
+ for dtype in [np.float16, np.float32]:
+ with self.test_session():
+ boxes = constant_op.constant(boxes_np, dtype=dtype)
+ scores = constant_op.constant(scores_np, dtype=dtype)
+ max_output_size = constant_op.constant(max_output_size_np)
+ iou_threshold = constant_op.constant(iou_threshold_np)
+ selected_indices = image_ops.non_max_suppression(
+ boxes, scores, max_output_size, iou_threshold).eval()
+ self.assertAllClose(selected_indices, [3, 0, 5])
+ # gen_image_ops.non_max_suppression_v4.
+ score_threshold=float('-inf')
+ for dtype in [np.float16, np.float32]:
+ with self.test_session():
+ boxes = constant_op.constant(boxes_np, dtype=dtype)
+ scores = constant_op.constant(scores_np, dtype=dtype)
+ max_output_size = constant_op.constant(max_output_size_np)
+ iou_threshold = constant_op.constant(iou_threshold_np)
+ selected_indices, _ = gen_image_ops.non_max_suppression_v4(
+ boxes, scores, max_output_size, iou_threshold, score_threshold)
+ selected_indices = selected_indices.eval()
+ self.assertAllClose(selected_indices, [3, 0, 5])
+
class NonMaxSuppressionPaddedTest(test_util.TensorFlowTestCase):