Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Fix iou_threshold not passed for NonMaxSuppressionV2 (#33836)

Evgeny Kotov2a8e2ed7fca0
diff --git a/src/frontends/tensorflow_common/src/op/non_max_suppression.cpp b/src/frontends/tensorflow_common/src/op/non_max_suppression.cpp
index ff3c3813cc1..20fdab3cb53 100644
--- a/src/frontends/tensorflow_common/src/op/non_max_suppression.cpp
+++ b/src/frontends/tensorflow_common/src/op/non_max_suppression.cpp
@@ -91,7 +91,7 @@ NamedOutputVector translate_non_max_suppression_op(const NodeContext& node) {
// NonMaxSuppressionV2 has four inputs and one output, selected indices
// iou_threshold comes as input
default_op_checks(node, 4, {"NonMaxSuppressionV2"});
- auto iou_threshold = node.get_input(3);
+ iou_threshold = node.get_input(3);
} else if (op_type == "NonMaxSuppressionV3") {
// NonMaxSuppressionV3 has five inputs and one output, selected indices
// score_threshold is a new input
diff --git a/tests/layer_tests/tensorflow_tests/test_tf_NonMaxSupression.py b/tests/layer_tests/tensorflow_tests/test_tf_NonMaxSupression.py
index 8e5ab9b36ec..98acc725e9b 100644
--- a/tests/layer_tests/tensorflow_tests/test_tf_NonMaxSupression.py
+++ b/tests/layer_tests/tensorflow_tests/test_tf_NonMaxSupression.py
@@ -101,3 +101,57 @@ class TestNonMaxSuppression(CommonTFLayerTest):
pytest.skip("Skip TF NonMaxSuppresionWithScores test on GPU")
self._test(*self.create_nms_net(test_params, with_scores=True), ie_device, precision,
ir_version, temp_dir=temp_dir)
+
+
+class TestNonMaxSuppressionV2(CommonTFLayerTest):
+ """Tests for NonMaxSuppressionV2 op which takes iou_threshold as input (not attribute).
+
+ Regression test for CVS-155709: variable shadowing bug caused iou_threshold
+ to be ignored (always 0.0) for NonMaxSuppressionV2.
+ """
+
+ def _prepare_input(self, inputs_dict):
+ np.random.seed(0)
+ input_data = {}
+ for input in inputs_dict.keys():
+ input_data[input] = np.random.uniform(low=0, high=1,
+ size=inputs_dict[input]).astype(np.float32)
+ return input_data
+
+ def create_nms_v2_net(self, test_params: dict):
+ tf.compat.v1.reset_default_graph()
+ with tf.compat.v1.Session() as sess:
+ number_of_boxes = test_params["number_of_boxes"]
+
+ boxes = tf.compat.v1.placeholder(tf.float32, [number_of_boxes, 4], "Input")
+
+ np.random.seed(42)
+ scores = np.random.uniform(low=0.2, high=1.0, size=[number_of_boxes]).astype(np.float32)
+
+ max_output_size = tf.constant(test_params["max_output_size"], dtype=tf.int32)
+ iou_threshold = tf.constant(test_params["iou_threshold"], dtype=tf.float32)
+
+ # tf.raw_ops.NonMaxSuppressionV2 directly creates the V2 op
+ selected_indices = tf.raw_ops.NonMaxSuppressionV2(
+ boxes=boxes, scores=scores,
+ max_output_size=max_output_size,
+ iou_threshold=iou_threshold)
+ tf.identity(selected_indices, name="NMS_V2")
+ tf_net = sess.graph_def
+
+ return tf_net, None
+
+ test_params = [
+ {"number_of_boxes": 50, "max_output_size": 5, "iou_threshold": 0.5},
+ {"number_of_boxes": 50, "max_output_size": 10, "iou_threshold": 0.7},
+ {"number_of_boxes": 50, "max_output_size": 3, "iou_threshold": 0.3},
+ ]
+
+ @pytest.mark.parametrize("test_params", test_params)
+ @pytest.mark.nightly
+ @pytest.mark.precommit
+ def test_NonMaxSuppressionV2(self, test_params, ie_device, precision, ir_version, temp_dir):
+ if ie_device == 'GPU':
+ pytest.skip("Skip TF NonMaxSuppressionV2 test on GPU")
+ self._test(*self.create_nms_v2_net(test_params), ie_device, precision,
+ ir_version, temp_dir=temp_dir)