diff --git a/src/frontends/tensorflow_common/src/op/arg_min_max.cpp b/src/frontends/tensorflow_common/src/op/arg_min_max.cpp index c9d72018e1e..831df7c2f7b 100644 --- a/src/frontends/tensorflow_common/src/op/arg_min_max.cpp +++ b/src/frontends/tensorflow_common/src/op/arg_min_max.cpp @@ -34,8 +34,9 @@ OutputVector translate_arg_min_max(const NodeContext& node, std::string mode) { // compute indices of max/min values using TopK auto k = make_shared(element::i64, Shape{}, 1); - // TODO: define sort attribute for TensorFlow case - auto top_k = std::make_shared(input, k, axis, mode, "none", output_type); + auto top_k_mode = (mode == "max" ? v11::TopK::Mode::MAX : v11::TopK::Mode::MIN); + auto sort_type = v11::TopK::SortType::SORT_VALUES; + auto top_k = make_shared(input, k, axis, top_k_mode, sort_type, output_type, true); auto axis_to_remove = make_shared(element::i64, Shape{1}, vector({axis})); auto res = make_shared(top_k->output(1), axis_to_remove); diff --git a/tests/layer_tests/tensorflow_tests/test_tf_ArgMinMax.py b/tests/layer_tests/tensorflow_tests/test_tf_ArgMinMax.py index 4a82d51b689..ca4f7f051e1 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_ArgMinMax.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_ArgMinMax.py @@ -3,44 +3,33 @@ import numpy as np import pytest - +import tensorflow as tf from common.tf_layer_test_class import CommonTFLayerTest + # Testing operation ArgMin, ArgMax (Initial Implementation) # Documentation: https://www.tensorflow.org/api_docs/python/tf/raw_ops/ArgMin # https://www.tensorflow.org/api_docs/python/tf/raw_ops/ArgMax class TestArgMinMax(CommonTFLayerTest): - # input_shape - should be an array - # dimension - dimension to be used, for vector should be 0 - # op_type - type of testing operation - # ir_version - common parameter - # use_new_frontend - common parameter - def create_argminmax_placeholder_const_net(self, input_shape, dimension, op_type, ir_version, use_new_frontend): - """ - Tensorflow net IR net - - Placeholder->op_type => Placeholder->TopK->Squeeze - / / / - Const-------/ Const-------/-----/ - - """ - - import tensorflow as tf + def _prepare_input(self, inputs_info): + assert 'input' in inputs_info + input_shape = inputs_info['input'] + inputs_data = {} + rng = np.random.default_rng() + inputs_data['input'] = rng.integers(-8, 8, input_shape).astype(self.input_type) + return inputs_data + def create_argmin_max_net(self, input_shape, dimension, input_type, output_type, op_type): + self.input_type = input_type tf.compat.v1.reset_default_graph() # Create the graph and model with tf.compat.v1.Session() as sess: - op_type_to_tf = { - 'ArgMax': tf.raw_ops.ArgMax, - 'ArgMin': tf.raw_ops.ArgMin, - } - tf_input_shape = input_shape.copy() - tf_input = tf.compat.v1.placeholder(tf.float32, tf_input_shape, 'Input') + tf_input = tf.compat.v1.placeholder(input_type, input_shape, 'input') tf_dimension = tf.constant(dimension) - op_type_to_tf[op_type](input = tf_input, dimension = tf_dimension) + op_type(input=tf_input, dimension=tf_dimension, output_type=output_type) tf.compat.v1.global_variables_initializer() tf_net = sess.graph_def @@ -50,21 +39,20 @@ class TestArgMinMax(CommonTFLayerTest): return tf_net, ref_net test_data = [ - dict(input_shape=[5], dimension=0), #Simple test of vector - pytest.param( - dict(input_shape=[2, 3], dimension=1), #Simple test - marks=pytest.mark.precommit_tf_fe), - dict(input_shape=[2, 3, 3, 4], dimension=2), #Simple test with possible nchw/nhcw + dict(input_shape=[20], dimension=0), + dict(input_shape=[20, 30], dimension=1), + dict(input_shape=[2, 30, 3, 4], dimension=2), ] @pytest.mark.parametrize("params", test_data) - @pytest.mark.parametrize("op_type", ['ArgMin', 'ArgMax']) - @pytest.mark.precommit + @pytest.mark.parametrize("input_type", [np.float32, np.int32]) + @pytest.mark.parametrize("output_type", [tf.int32, tf.int64]) + @pytest.mark.parametrize("op_type", [tf.raw_ops.ArgMax, tf.raw_ops.ArgMin]) + @pytest.mark.precommit_tf_fe @pytest.mark.nightly - def test_argminmax_placeholder_const(self, params, op_type, ie_device, precision, ir_version, temp_dir, - use_new_frontend, use_old_api): - self._test(*self.create_argminmax_placeholder_const_net(**params, op_type=op_type, - ir_version=ir_version, - use_new_frontend=use_new_frontend), + def test_argmin_max_net(self, params, input_type, output_type, op_type, ie_device, precision, ir_version, temp_dir, + use_new_frontend, use_old_api): + self._test(*self.create_argmin_max_net(**params, input_type=input_type, + output_type=output_type, op_type=op_type), ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend, use_old_api=use_old_api)